mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Use edit mixins for Playlists (#1284)
* Use mixins to edit playlists * Add titleSort attribute to Playlists * Update Playlists edit tests * Fix deprecation warning stacklevel * Fix edit title for m3u playlist
This commit is contained in:
parent
47f11f04eb
commit
556b4b3da4
3 changed files with 26 additions and 5 deletions
|
@ -1223,3 +1223,10 @@ class CollectionEditMixins(
|
|||
LabelMixin
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
class PlaylistEditMixins(
|
||||
ArtLockMixin, PosterLockMixin,
|
||||
SortTitleMixin, SummaryMixin, TitleMixin
|
||||
):
|
||||
pass
|
||||
|
|
|
@ -7,7 +7,7 @@ from plexapi import media, utils
|
|||
from plexapi.base import Playable, PlexPartialObject
|
||||
from plexapi.exceptions import BadRequest, NotFound, Unsupported
|
||||
from plexapi.library import LibrarySection, MusicSection
|
||||
from plexapi.mixins import SmartFilterMixin, ArtMixin, PosterMixin
|
||||
from plexapi.mixins import SmartFilterMixin, ArtMixin, PosterMixin, PlaylistEditMixins
|
||||
from plexapi.utils import deprecated
|
||||
|
||||
|
||||
|
@ -15,7 +15,8 @@ from plexapi.utils import deprecated
|
|||
class Playlist(
|
||||
PlexPartialObject, Playable,
|
||||
SmartFilterMixin,
|
||||
ArtMixin, PosterMixin
|
||||
ArtMixin, PosterMixin,
|
||||
PlaylistEditMixins
|
||||
):
|
||||
""" Represents a single Playlist.
|
||||
|
||||
|
@ -42,6 +43,7 @@ class Playlist(
|
|||
smart (bool): True if the playlist is a smart playlist.
|
||||
summary (str): Summary of the playlist.
|
||||
title (str): Name of the playlist.
|
||||
titleSort (str): Title to use when sorting (defaults to title).
|
||||
type (str): 'playlist'
|
||||
updatedAt (datetime): Datetime the playlist was updated.
|
||||
"""
|
||||
|
@ -71,6 +73,7 @@ class Playlist(
|
|||
self.smart = utils.cast(bool, data.attrib.get('smart'))
|
||||
self.summary = data.attrib.get('summary')
|
||||
self.title = data.attrib.get('title')
|
||||
self.titleSort = data.attrib.get('titleSort', self.title)
|
||||
self.type = data.attrib.get('type')
|
||||
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))
|
||||
self._items = None # cache for self.items
|
||||
|
@ -224,7 +227,7 @@ class Playlist(
|
|||
self._server.query(key, method=self._server._session.put)
|
||||
return self
|
||||
|
||||
@deprecated('use "removeItems" instead', stacklevel=3)
|
||||
@deprecated('use "removeItems" instead')
|
||||
def removeItem(self, item):
|
||||
self.removeItems(item)
|
||||
|
||||
|
@ -308,10 +311,15 @@ class Playlist(
|
|||
|
||||
def _edit(self, **kwargs):
|
||||
""" Actually edit the playlist. """
|
||||
if isinstance(self._edits, dict):
|
||||
self._edits.update(kwargs)
|
||||
return self
|
||||
|
||||
key = f'{self.key}{utils.joinArgs(kwargs)}'
|
||||
self._server.query(key, method=self._server._session.put)
|
||||
return self
|
||||
|
||||
@deprecated('use "editTitle" and "editSummary" instead')
|
||||
def edit(self, title=None, summary=None):
|
||||
""" Edit the playlist.
|
||||
|
||||
|
@ -384,7 +392,7 @@ class Playlist(
|
|||
key = f"/playlists/upload{utils.joinArgs(args)}"
|
||||
server.query(key, method=server._session.post)
|
||||
try:
|
||||
return server.playlists(sectionId=section.key, guid__endswith=m3ufilepath)[0].edit(title=title).reload()
|
||||
return server.playlists(sectionId=section.key, guid__endswith=m3ufilepath)[0].editTitle(title).reload()
|
||||
except IndexError:
|
||||
raise BadRequest('Failed to create playlist from m3u file.') from None
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ def test_Playlist_edit(plex, movie):
|
|||
playlist = plex.createPlaylist(title, items=movie)
|
||||
assert playlist.title == title
|
||||
assert playlist.summary == ''
|
||||
playlist.edit(title=new_title, summary=new_summary)
|
||||
playlist.editTitle(new_title).editSummary(new_summary)
|
||||
playlist.reload()
|
||||
assert playlist.title == new_title
|
||||
assert playlist.summary == new_summary
|
||||
|
@ -330,3 +330,9 @@ def test_Playlist_mixins_images(playlist):
|
|||
test_mixins.lock_poster(playlist)
|
||||
test_mixins.edit_art(playlist)
|
||||
test_mixins.edit_poster(playlist)
|
||||
|
||||
|
||||
def test_Playlist_mixins_fields(playlist):
|
||||
test_mixins.edit_sort_title(playlist)
|
||||
test_mixins.edit_summary(playlist)
|
||||
test_mixins.edit_title(playlist)
|
||||
|
|
Loading…
Reference in a new issue