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
61 changes: 61 additions & 0 deletions plexapi/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@ 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, 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):
""" Add an Actor from item. """
JonnyWong16 marked this conversation as resolved.
Show resolved Hide resolved
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 +559,36 @@ 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):
""" Add an Actor from item. """
JonnyWong16 marked this conversation as resolved.
Show resolved Hide resolved
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