Skip to content
Merged
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
59 changes: 59 additions & 0 deletions plexapi/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ def photo(self, title):
return photo
raise NotFound('Unable to find photo: %s' % title)

def iterParts(self):
""" Iterates over the parts of this media item. """
for album in self.albums():
for photo in album.photos():
for part in photo.iterParts():
yield part

def download(self, savepath=None, keep_original_name=False, showstatus=False):
""" Download photo files to specified directory.

Parameters:
savepath (str): Defaults to current working dir.
keep_original_name (bool): True to keep the original file name otherwise
a friendlier is generated.
showstatus(bool): Display a progressbar.
"""
filepaths = []
locations = [i for i in self.iterParts() if i]
for location in locations:
name = location.file
if not keep_original_name:
title = self.title.replace(' ', '.')
name = '%s.%s' % (title, location.container)
url = self._server.url('%s?download=1' % location.key)
filepath = utils.download(url, self._server._token, filename=name, showstatus=showstatus,
savepath=savepath, session=self._server._session)
if filepath:
filepaths.append(filepath)
return filepaths


@utils.registerPlexObject
class Photo(PlexPartialObject):
Expand Down Expand Up @@ -137,6 +167,12 @@ def section(self):
else:
raise BadRequest('Unable to get section for photo, can`t find librarySectionID')

def iterParts(self):
""" Iterates over the parts of this media item. """
for item in self.media:
for part in item.parts:
yield part

def sync(self, resolution, client=None, clientId=None, limit=None, title=None):
""" Add current photo as sync item for specified device.
See :func:`plexapi.myplex.MyPlexAccount.sync()` for possible exceptions.
Expand Down Expand Up @@ -172,3 +208,26 @@ def sync(self, resolution, client=None, clientId=None, limit=None, title=None):
sync_item.mediaSettings = MediaSettings.createPhoto(resolution)

return myplex.sync(sync_item, client=client, clientId=clientId)

def download(self, savepath=None, keep_original_name=False, showstatus=False):
""" Download photo files to specified directory.

Parameters:
savepath (str): Defaults to current working dir.
keep_original_name (bool): True to keep the original file name otherwise
a friendlier is generated.
showstatus(bool): Display a progressbar.
"""
filepaths = []
locations = [i for i in self.iterParts() if i]
for location in locations:
name = location.file
if not keep_original_name:
title = self.title.replace(' ', '.')
name = '%s.%s' % (title, location.container)
url = self._server.url('%s?download=1' % location.key)
filepath = utils.download(url, self._server._token, filename=name, showstatus=showstatus,
savepath=savepath, session=self._server._session)
if filepath:
filepaths.append(filepath)
return filepaths