mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-14 17:22:56 -07:00
Initial collections and playlists table to library page
This commit is contained in:
parent
b568af0a90
commit
84207effab
5 changed files with 514 additions and 1 deletions
|
@ -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={}§ionID={}'.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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue