Initial collections and playlists table to library page

This commit is contained in:
JonnyWong16 2020-09-30 15:44:23 -07:00
commit 84207effab
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 514 additions and 1 deletions

View file

@ -33,6 +33,7 @@ if plexpy.PYTHON2:
import plextv
import pmsconnect
import session
from plex import Plex
else:
from plexpy import common
from plexpy import database
@ -42,6 +43,7 @@ else:
from plexpy import plextv
from plexpy import pmsconnect
from plexpy import session
from plexpy.plex import Plex
def refresh_libraries():
@ -140,6 +142,117 @@ def has_library_type(section_type):
return bool(result)
def get_collections(section_id):
plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN)
library = plex.get_library(section_id)
if library.type not in ('movie', 'show', 'artist'):
return []
collections = library.collection()
collections_list = []
for collection in collections:
collection_dict = {
'addedAt': helpers.datetime_to_iso(collection.addedAt),
'art': collection.art,
'childCount': collection.childCount,
'collectionMode': collection.collectionMode,
'collectionSort': collection.collectionSort,
'contentRating': collection.contentRating,
'guid': collection.guid,
'librarySectionID': collection.librarySectionID,
'librarySectionTitle': collection.librarySectionTitle,
'maxYear': collection.maxYear,
'minYear': collection.minYear,
'ratingKey': collection.ratingKey,
'subtype': collection.subtype,
'summary': collection.summary,
'thumb': collection.thumb,
'title': collection.title,
'titleSort': collection.titleSort,
'type': collection.type,
'updatedAt': helpers.datetime_to_iso(collection.updatedAt)
}
collections_list.append(collection_dict)
return collections_list
def get_collections_list(section_id=None, **kwargs):
if not section_id:
default_return = {'recordsTotal': 0,
'draw': 0,
'data': 'null',
'error': 'Unable to execute database query.'}
return default_return
collections = get_collections(section_id)
data = {'recordsTotal': len(collections),
'data': collections,
'draw': kwargs.get('draw', 0)
}
return data
def get_playlists(section_id):
plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN)
library = Libraries().get_details(section_id=section_id)
if library['section_type'] == 'artist':
playlist_type = 'audio'
elif library['section_type'] == 'photo':
playlist_type = 'photo'
else:
playlist_type = 'video'
playlists = plex.plex.fetchItems(
'/playlists?type=15&playlistType={}&sectionID={}'.format(playlist_type, section_id))
playlists_list = []
for playlist in playlists:
playlist_dict = {
'addedAt': helpers.datetime_to_iso(playlist.addedAt),
'composite': playlist.composite,
'duration': playlist.duration,
'guid': playlist.guid,
'leafCount': playlist.leafCount,
'librarySectionID': section_id,
'librarySectionTitle': library['section_name'],
'playlistType': playlist.playlistType,
'ratingKey': playlist.ratingKey,
'smart': playlist.smart,
'summary': playlist.summary,
'title': playlist.title,
'type': playlist.type,
'updatedAt': helpers.datetime_to_iso(playlist.updatedAt)
}
playlists_list.append(playlist_dict)
return playlists_list
def get_playlists_list(section_id=None, **kwargs):
if not section_id:
default_return = {'recordsTotal': 0,
'draw': 0,
'data': 'null',
'error': 'Unable to execute database query.'}
return default_return
playlists = get_playlists(section_id)
data = {'recordsTotal': len(playlists),
'data': playlists,
'draw': kwargs.get('draw', 0)
}
return data
class Libraries(object):
def __init__(self):

View file

@ -843,6 +843,106 @@ class WebInterface(object):
return result
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def get_collections_list(self, section_id=None, **kwargs):
""" Get the data on the Tautulli media info tables.
```
Required parameters:
section_id (str): The id of the Plex library section, OR
Optional parameters:
None
Returns:
json:
{"draw": 1,
"recordsTotal": 5,
"data":
[...]
}
```
"""
# Check if datatables json_data was received.
# If not, then build the minimal amount of json data for a query
if not kwargs.get('json_data'):
# Alias 'title' to 'sort_title'
if kwargs.get('order_column') == 'title':
kwargs['order_column'] = 'sort_title'
# TODO: Find some one way to automatically get the columns
dt_columns = [("added_at", True, False),
("sort_title", True, True),
("container", True, True),
("bitrate", True, True),
("video_codec", True, True),
("video_resolution", True, True),
("video_framerate", True, True),
("audio_codec", True, True),
("audio_channels", True, True),
("file_size", True, False),
("last_played", True, False),
("play_count", True, False)]
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "sort_title")
result = libraries.get_collections_list(section_id=section_id,
kwargs=kwargs)
return result
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
@addtoapi()
def get_playlists_list(self, section_id=None, **kwargs):
""" Get the data on the Tautulli media info tables.
```
Required parameters:
section_id (str): The id of the Plex library section, OR
Optional parameters:
None
Returns:
json:
{"draw": 1,
"recordsTotal": 5,
"data":
[...]
}
```
"""
# Check if datatables json_data was received.
# If not, then build the minimal amount of json data for a query
if not kwargs.get('json_data'):
# Alias 'title' to 'sort_title'
if kwargs.get('order_column') == 'title':
kwargs['order_column'] = 'sort_title'
# TODO: Find some one way to automatically get the columns
dt_columns = [("added_at", True, False),
("sort_title", True, True),
("container", True, True),
("bitrate", True, True),
("video_codec", True, True),
("video_resolution", True, True),
("video_framerate", True, True),
("audio_codec", True, True),
("audio_channels", True, True),
("file_size", True, False),
("last_played", True, False),
("play_count", True, False)]
kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, "sort_title")
result = libraries.get_playlists_list(section_id=section_id,
kwargs=kwargs)
return result
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))