Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plexapi/audio.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
from plexapi import library, media, utils
from plexapi.base import Playable, PlexPartialObject
from plexapi.exceptions import BadRequest
from plexapi.mixins import CollectionMixin, CountryMixin, GenreMixin, LabelMixin, MoodMixin, SimilarArtistMixin, StyleMixin


class Audio(PlexPartialObject):
Expand DownExpand Up@@ -123,7 +124,7 @@ def sync(self, bitrate, client=None, clientId=None, limit=None, title=None):


@utils.registerPlexObject
class Artist(Audio):
class Artist(Audio, CollectionMixin, CountryMixin, GenreMixin, MoodMixin, SimilarArtistMixin, StyleMixin):
""" Represents a single Artist.

Attributes:
Expand DownExpand Up@@ -226,7 +227,7 @@ def download(self, savepath=None, keep_original_name=False, **kwargs):


@utils.registerPlexObject
class Album(Audio):
class Album(Audio, CollectionMixin, GenreMixin, LabelMixin, MoodMixin, StyleMixin):
""" Represents a single Album.

Attributes:
Expand DownExpand Up@@ -332,7 +333,7 @@ def _defaultSyncTitle(self):


@utils.registerPlexObject
class Track(Audio, Playable):
class Track(Audio, Playable, MoodMixin):
""" Represents a single Track.

Attributes:
Expand Down
32 changes: 2 additions & 30 deletions plexapi/base.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@

from plexapi import log, utils
from plexapi.exceptions import BadRequest, NotFound, UnknownType, Unsupported
from plexapi.utils import tag_helper
from plexapi.utils import tag_plural, tag_helper

DONT_RELOAD_FOR_KEYS = ['key', 'session']
OPERATORS = {
Expand DownExpand Up@@ -462,40 +462,12 @@ def _edit_tags(self, tag, items, locked=True, remove=False):
"""
if not isinstance(items, list):
items = [items]
value = getattr(self, tag + 's')
value = getattr(self, tag_plural(tag))
existing_cols = [t.tag for t in value if t and remove is False]
d = tag_helper(tag, existing_cols + items, locked, remove)
self.edit(**d)
self.refresh()

def addCollection(self, collections):
""" Add a collection(s).

Parameters:
collections (list): list of strings
"""
self._edit_tags('collection', collections)

def removeCollection(self, collections):
""" Remove a collection(s). """
self._edit_tags('collection', collections, remove=True)

def addLabel(self, labels):
""" Add a label(s). """
self._edit_tags('label', labels)

def removeLabel(self, labels):
""" Remove a label(s). """
self._edit_tags('label', labels, remove=True)

def addGenre(self, genres):
""" Add a genre(s). """
self._edit_tags('genre', genres)

def removeGenre(self, genres):
""" Remove a genre(s). """
self._edit_tags('genre', genres, remove=True)

def refresh(self):
""" Refreshing a Library or individual item causes the metadata for the item to be
refreshed, even if it already has metadata. You can think of refreshing as
Expand Down
3 changes: 2 additions & 1 deletion plexapi/library.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
from plexapi import X_PLEX_CONTAINER_SIZE, log, media, utils
from plexapi.base import OPERATORS, PlexObject, PlexPartialObject
from plexapi.exceptions import BadRequest, NotFound
from plexapi.mixins import LabelMixin
from plexapi.settings import Setting
from plexapi.utils import deprecated

Expand DownExpand Up@@ -1526,7 +1527,7 @@ def _loadData(self, data):


@utils.registerPlexObject
class Collections(PlexPartialObject):
class Collections(PlexPartialObject, LabelMixin):
""" Represents a single Collection.

Attributes:
Expand Down
221 changes: 221 additions & 0 deletions plexapi/mixins.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
# -*- coding: utf-8 -*-


class CollectionMixin(object):
""" Mixin for Plex objects that can have collections. """

def addCollection(self, collections):
""" Add a collection tag(s).

Parameters:
collections (list): List of strings.
"""
self._edit_tags('collection', collections)

def removeCollection(self, collections):
""" Remove a collection tag(s).

Parameters:
collections (list): List of strings.
"""
self._edit_tags('collection', collections, remove=True)


class CountryMixin(object):
""" Mixin for Plex objects that can have countries. """

def addCountry(self, countries):
""" Add a country tag(s).

Parameters:
countries (list): List of strings.
"""
self._edit_tags('country', countries)

def removeCountry(self, countries):
""" Remove a country tag(s).

Parameters:
countries (list): List of strings.
"""
self._edit_tags('country', countries, remove=True)


class DirectorMixin(object):
""" Mixin for Plex objects that can have directors. """

def addDirector(self, directors):
""" Add a director tag(s).

Parameters:
directors (list): List of strings.
"""
self._edit_tags('director', directors)

def removeDirector(self, directors):
""" Remove a director tag(s).

Parameters:
directors (list): List of strings.
"""
self._edit_tags('director', directors, remove=True)


class GenreMixin(object):
""" Mixin for Plex objects that can have genres. """

def addGenre(self, genres):
""" Add a genre tag(s).

Parameters:
genres (list): List of strings.
"""
self._edit_tags('genre', genres)

def removeGenre(self, genres):
""" Remove a genre tag(s).

Parameters:
genres (list): List of strings.
"""
self._edit_tags('genre', genres, remove=True)


class LabelMixin(object):
""" Mixin for Plex objects that can have labels. """

def addLabel(self, labels):
""" Add a label tag(s).

Parameters:
labels (list): List of strings.
"""
self._edit_tags('label', labels)

def removeLabel(self, labels):
""" Remove a label tag(s).

Parameters:
labels (list): List of strings.
"""
self._edit_tags('label', labels, remove=True)


class MoodMixin(object):
""" Mixin for Plex objects that can have moods. """

def addMood(self, moods):
""" Add a mood tag(s).

Parameters:
moods (list): List of strings.
"""
self._edit_tags('mood', moods)

def removeMood(self, moods):
""" Remove a mood tag(s).

Parameters:
moods (list): List of strings.
"""
self._edit_tags('mood', moods, remove=True)


class ProducerMixin(object):
""" Mixin for Plex objects that can have producers. """

def addProducer(self, producers):
""" Add a producer tag(s).

Parameters:
producers (list): List of strings.
"""
self._edit_tags('producer', producers)

def removeProducer(self, producers):
""" Remove a producer tag(s).

Parameters:
producers (list): List of strings.
"""
self._edit_tags('producer', producers, remove=True)


class SimilarArtistMixin(object):
""" Mixin for Plex objects that can have similar artists. """

def addSimilarArtist(self, artists):
""" Add a similar artist tag(s).

Parameters:
artists (list): List of strings.
"""
self._edit_tags('similar', artists)

def removeSimilarArtist(self, artists):
""" Remove a similar artist tag(s).

Parameters:
artists (list): List of strings.
"""
self._edit_tags('similar', artists, remove=True)


class StyleMixin(object):
""" Mixin for Plex objects that can have styles. """

def addStyle(self, styles):
""" Add a style tag(s).

Parameters:
styles (list): List of strings.
"""
self._edit_tags('style', styles)

def removeStyle(self, styles):
""" Remove a style tag(s).

Parameters:
styles (list): List of strings.
"""
self._edit_tags('style', styles, remove=True)


class TagMixin(object):
""" Mixin for Plex objects that can have tags. """

def addTag(self, tags):
""" Add a tag(s).

Parameters:
tags (list): List of strings.
"""
self._edit_tags('tag', tags)

def removeTag(self, tags):
""" Remove a tag(s).

Parameters:
tags (list): List of strings.
"""
self._edit_tags('tag', tags, remove=True)


class EditWriter(object):
""" Mixin for Plex objects that can have writers. """

def addWriter(self, writers):
""" Add a writer tag(s).

Parameters:
writers (list): List of strings.
"""
self._edit_tags('writer', writers)

def removeWriter(self, writers):
""" Remove a writer tag(s).

Parameters:
writers (list): List of strings.
"""
self._edit_tags('writer', writers, remove=True)
7 changes: 4 additions & 3 deletions plexapi/photo.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@
from plexapi import media, utils, video
from plexapi.base import Playable, PlexPartialObject
from plexapi.exceptions import BadRequest
from plexapi.mixins import TagMixin


@utils.registerPlexObject
Expand DownExpand Up@@ -136,7 +137,7 @@ def download(self, savepath=None, keep_original_name=False, showstatus=False):


@utils.registerPlexObject
class Photo(PlexPartialObject, Playable):
class Photo(PlexPartialObject, Playable, TagMixin):
""" Represents a single Photo.

Attributes:
Expand All@@ -163,7 +164,7 @@ class Photo(PlexPartialObject, Playable):
parentTitle (str): Name of the photo album for the photo.
ratingKey (int): Unique key identifying the photo.
summary (str): Summary of the photo.
tag (List<:class:`~plexapi.media.Tag`>): List of tag objects.
tags (List<:class:`~plexapi.media.Tag`>): List of tag objects.
thumb (str): URL to thumbnail image (/library/metadata/<ratingKey>/thumb/<thumbid>).
title (str): Name of the photo.
titleSort (str): Title to use when sorting (defaults to title).
Expand DownExpand Up@@ -199,7 +200,7 @@ def _loadData(self, data):
self.parentTitle = data.attrib.get('parentTitle')
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey'))
self.summary = data.attrib.get('summary')
self.tag = self.findItems(data, media.Tag)
self.tags = self.findItems(data, media.Tag)
self.thumb = data.attrib.get('thumb')
self.title = data.attrib.get('title')
self.titleSort = data.attrib.get('titleSort', self.title)
Expand Down
9 changes: 9 additions & 0 deletions plexapi/utils.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -335,6 +335,15 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
return fullpath


def tag_plural(tag):
if tag == 'country':
return 'countries'
elif tag == 'similar':
return 'similar'
else:
return tag + 's'


def tag_helper(tag, items, locked=True, remove=False):
""" Simple tag helper for editing a object. """
if not isinstance(items, list):
Expand Down
Loading