Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor editing #510

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
8 changes: 8 additions & 0 deletions plexapi/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ class Role(MediaTag):
TAG = 'Role'
FILTER = 'role'

def _loadData(self, data):
self._data = data
self.id = data.attrib.get('id')
self.filter = data.attrib.get('filter')
self.role = data.attrib.get('role')
self.tag = data.attrib.get('tag')
self.thumb = data.attrib.get('thumb')


@utils.registerPlexObject
class Similar(MediaTag):
Expand Down
67 changes: 67 additions & 0 deletions plexapi/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,42 @@ def download(self, savepath=None, keep_original_name=False, **kwargs):
filepaths.append(filepath)
return filepaths

def addActor(self, index=0, name=None, role=None, thumb=None):
""" Add an Actor.

Parameters:
index (int): Positional index
name (str): Name of Actor.
role (str): Role actor plays in video.
thumb (str): URL to image file.
"""
edits = {}
actors = {actor.tag: actor for actor in self.actors}
actor = 'actor[%s]' % index
if name:
edits['%s.tag.tag' % actor] = name
else:
raise BadRequest('name keyword is required.')
if role or type(role) == str:
edits['%s.tagging.text' % actor] = role
else:
previousRole = actors.get(name)
if previousRole:
edits['%s.tagging.text' % actor] = previousRole.role
if thumb:
edits['%s.tag.thumb' % actor] = thumb

self.edit(**edits)

def removeActor(self, name):
""" Remove an Actor from item. """
actors = [actor.tag for actor in self.actors]
if name in actors:
edits = {'actor[].tag.tag-': name}
self.edit(**edits)
else:
raise NotFound('%s not found in items list of actors %s' % (name, actors))


@utils.registerPlexObject
class Show(Video):
Expand Down Expand Up @@ -528,6 +564,37 @@ def download(self, savepath=None, keep_original_name=False, **kwargs):
filepaths += episode.download(savepath, keep_original_name, **kwargs)
return filepaths

def addActor(self, index=0, name=None, role=None, thumb=None, locked=True):
""" Add an Actor.

Parameters:
index (int): Positional index
name (str): Name of Actor.
role (str): Role actor plays in video.
thumb (str): URL to image file.
locked (bool): True = 1, False = 0
"""
edits = {}
actor = 'actor[%s]' % index
if name:
edits['%s.tag.tag' % actor] = name
if role:
edits['%s.tagging.text' % actor] = role
if thumb:
edits['%s.tag.thumb' % actor] = thumb
if locked:
edits['%s.locked' % actor] = int(locked)
self.edit(**edits)

def removeActor(self, name):
""" Remove an Actor from item. """
actors = [actor.tag for actor in self.actors]
if name in actors:
edits = {'actor[].tag.tag-': name}
self.edit(**edits)
else:
raise NotFound('%s not found in items list of actors %s' % (name, actors))


@utils.registerPlexObject
class Season(Video):
Expand Down