mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 07:46:07 -07:00
API2
This commit is contained in:
parent
9359567a8a
commit
2fcd55eb60
10 changed files with 1671 additions and 156 deletions
|
@ -14,7 +14,7 @@
|
|||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, notifiers, plextv, pmsconnect, common, log_reader, datafactory, graphs, users, libraries
|
||||
from plexpy.helpers import checked, radio, get_ip
|
||||
from plexpy.helpers import checked, addtoapi, get_ip
|
||||
|
||||
from mako.lookup import TemplateLookup
|
||||
from mako import exceptions
|
||||
|
@ -26,6 +26,7 @@ import hashlib
|
|||
import random
|
||||
import json
|
||||
import os
|
||||
from api2 import API2
|
||||
|
||||
try:
|
||||
# pylint:disable=E0611
|
||||
|
@ -101,10 +102,29 @@ class WebInterface(object):
|
|||
return serve_template(templatename="welcome.html", title="Welcome", config=config)
|
||||
|
||||
@cherrypy.expose
|
||||
def discover(self, token=''):
|
||||
"""
|
||||
Returns the servers that you own as a
|
||||
list of dicts (formatted for selectize)
|
||||
@addtoapi()
|
||||
def discover(self, token):
|
||||
""" Gets all your servers that are published to plextv
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
[{"httpsRequired": "0",
|
||||
"ip": "10.0.0.97",
|
||||
"value": "10.0.0.97",
|
||||
"label": "dude-PC",
|
||||
"clientIdentifier": "1234",
|
||||
"local": "1", "port": "32400"},
|
||||
{"httpsRequired": "0",
|
||||
"ip": "85.167.100.100",
|
||||
"value": "85.167.100.100",
|
||||
"label": "dude-PC",
|
||||
"clientIdentifier": "1234",
|
||||
"local": "0",
|
||||
"port": "10294"}
|
||||
]
|
||||
```
|
||||
|
||||
"""
|
||||
# Need to set token so result doesn't return http 401
|
||||
plexpy.CONFIG.__setattr__('PMS_TOKEN', token)
|
||||
|
@ -132,7 +152,10 @@ class WebInterface(object):
|
|||
return serve_template(templatename="index.html", title="Home", config=config)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_date_formats(self):
|
||||
""" Get the date and time formats used by plexpy """
|
||||
|
||||
if plexpy.CONFIG.DATE_FORMAT:
|
||||
date_format = plexpy.CONFIG.DATE_FORMAT
|
||||
else:
|
||||
|
@ -212,7 +235,7 @@ class WebInterface(object):
|
|||
library_cards = plexpy.CONFIG.HOME_LIBRARY_CARDS
|
||||
|
||||
stats_data = data_factory.get_library_stats(library_cards=library_cards)
|
||||
|
||||
|
||||
return serve_template(templatename="library_stats.html", title="Library Stats", data=stats_data)
|
||||
|
||||
@cherrypy.expose
|
||||
|
@ -242,6 +265,7 @@ class WebInterface(object):
|
|||
return serve_template(templatename="libraries.html", title="Libraries", config=config)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_library_list(self, **kwargs):
|
||||
|
||||
library_data = libraries.Libraries()
|
||||
|
@ -251,10 +275,37 @@ class WebInterface(object):
|
|||
return json.dumps(library_list)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_library_sections(self, **kwargs):
|
||||
""" Get the library sections from pms
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
[{"section_id": 1, "section_name": "Movies"},
|
||||
{"section_id": 7, "section_name": "Music"},
|
||||
{"section_id": 2, "section_name": "TV Shows"}
|
||||
]
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
library_data = libraries.Libraries()
|
||||
result = library_data.get_sections()
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
else:
|
||||
logger.warn(u"Unable to retrieve data for get_library_sections.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi() # should be added manually
|
||||
def refresh_libraries_list(self, **kwargs):
|
||||
threading.Thread(target=pmsconnect.refresh_libraries).start()
|
||||
logger.info(u"Manual libraries list refresh requested.")
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
def library(self, section_id=None):
|
||||
config = {
|
||||
|
@ -284,10 +335,11 @@ class WebInterface(object):
|
|||
else:
|
||||
result = None
|
||||
status_message = 'An error occured.'
|
||||
|
||||
|
||||
return serve_template(templatename="edit_library.html", title="Edit Library", data=result, status_message=status_message)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def edit_library(self, section_id=None, **kwargs):
|
||||
custom_thumb = kwargs.get('custom_thumb', '')
|
||||
do_notify = kwargs.get('do_notify', 0)
|
||||
|
@ -323,10 +375,10 @@ class WebInterface(object):
|
|||
|
||||
@cherrypy.expose
|
||||
def get_library_user_stats(self, section_id=None, **kwargs):
|
||||
|
||||
|
||||
library_data = libraries.Libraries()
|
||||
result = library_data.get_user_stats(section_id=section_id)
|
||||
|
||||
|
||||
if result:
|
||||
return serve_template(templatename="library_user_stats.html", data=result, title="Player Stats")
|
||||
else:
|
||||
|
@ -358,12 +410,13 @@ class WebInterface(object):
|
|||
return serve_template(templatename="library_recently_added.html", data=None, title="Recently Added")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_library_media_info(self, section_id=None, section_type=None, rating_key=None, refresh='', **kwargs):
|
||||
|
||||
|
||||
if refresh == 'true':
|
||||
refresh = True
|
||||
refresh = True
|
||||
else:
|
||||
refresh = False
|
||||
refresh = False
|
||||
|
||||
library_data = libraries.Libraries()
|
||||
result = library_data.get_datatables_media_info(section_id=section_id,
|
||||
|
@ -371,16 +424,17 @@ class WebInterface(object):
|
|||
rating_key=rating_key,
|
||||
refresh=refresh,
|
||||
kwargs=kwargs)
|
||||
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_media_info_file_sizes(self, section_id=None, rating_key=None):
|
||||
get_file_sizes_hold = plexpy.CONFIG.GET_FILE_SIZES_HOLD
|
||||
section_ids = set(get_file_sizes_hold['section_ids'])
|
||||
rating_keys = set(get_file_sizes_hold['rating_keys'])
|
||||
|
||||
|
||||
if (section_id and section_id not in section_ids) or (rating_key and rating_key not in rating_keys):
|
||||
if section_id:
|
||||
section_ids.add(section_id)
|
||||
|
@ -399,23 +453,25 @@ class WebInterface(object):
|
|||
plexpy.CONFIG.GET_FILE_SIZES_HOLD = {'section_ids': list(section_ids), 'rating_keys': list(rating_keys)}
|
||||
else:
|
||||
result = False
|
||||
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'success': result})
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_library_unwatched(self, section_id=None, section_type=None, **kwargs):
|
||||
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_library_children_details(section_id=section_id,
|
||||
section_type=section_type,
|
||||
get_media_info=True,
|
||||
kwargs=kwargs)
|
||||
section_type=section_type,
|
||||
get_media_info=True)
|
||||
# fixed a bug in this one, is this even used?
|
||||
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def delete_all_library_history(self, section_id, **kwargs):
|
||||
library_data = libraries.Libraries()
|
||||
|
||||
|
@ -430,6 +486,7 @@ class WebInterface(object):
|
|||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def delete_library(self, section_id, **kwargs):
|
||||
library_data = libraries.Libraries()
|
||||
|
||||
|
@ -444,6 +501,7 @@ class WebInterface(object):
|
|||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def undelete_library(self, section_id=None, section_name=None, **kwargs):
|
||||
library_data = libraries.Libraries()
|
||||
|
||||
|
@ -464,6 +522,7 @@ class WebInterface(object):
|
|||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def update_section_ids(self, **kwargs):
|
||||
|
||||
logger.debug(u"Manual database section_id update called.")
|
||||
|
@ -476,6 +535,7 @@ class WebInterface(object):
|
|||
return "Unable to update section_id's in database. See logs for details."
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def delete_datatable_media_info_cache(self, section_id, **kwargs):
|
||||
get_file_sizes_hold = plexpy.CONFIG.GET_FILE_SIZES_HOLD
|
||||
section_ids = set(get_file_sizes_hold['section_ids'])
|
||||
|
@ -514,6 +574,7 @@ class WebInterface(object):
|
|||
return serve_template(templatename="users.html", title="Users")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_user_list(self, **kwargs):
|
||||
|
||||
user_data = users.Users()
|
||||
|
@ -523,7 +584,9 @@ class WebInterface(object):
|
|||
return json.dumps(user_list)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def refresh_users_list(self, **kwargs):
|
||||
""" Refresh a users list in a own thread """
|
||||
threading.Thread(target=plextv.refresh_users).start()
|
||||
logger.info(u"Manual users list refresh requested.")
|
||||
|
||||
|
@ -781,6 +844,7 @@ class WebInterface(object):
|
|||
return "Updated graphs config values."
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_date(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -793,6 +857,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_date.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_dayofweek(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -805,6 +870,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_dayofweek.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_hourofday(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -817,6 +883,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_hourofday.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_per_month(self, y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -829,6 +896,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_per_month.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_top_10_platforms(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -841,6 +909,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_top_10_platforms.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_top_10_users(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -853,6 +922,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_top_10_users.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_stream_type(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -865,6 +935,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_stream_type.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_source_resolution(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -877,6 +948,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_source_resolution.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plays_by_stream_resolution(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -889,6 +961,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_plays_by_stream_resolution.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_stream_type_by_top_10_users(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -901,6 +974,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_stream_type_by_top_10_users.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_stream_type_by_top_10_platforms(self, time_range='30', y_axis='plays', **kwargs):
|
||||
|
||||
graph = graphs.Graphs()
|
||||
|
@ -993,6 +1067,7 @@ class WebInterface(object):
|
|||
})
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plex_log(self, window=1000, **kwargs):
|
||||
log_lines = []
|
||||
try:
|
||||
|
@ -1129,7 +1204,7 @@ class WebInterface(object):
|
|||
"buffer_wait": plexpy.CONFIG.BUFFER_WAIT,
|
||||
"group_history_tables": checked(plexpy.CONFIG.GROUP_HISTORY_TABLES)
|
||||
}
|
||||
|
||||
|
||||
return serve_template(templatename="settings.html", title="Settings", config=config)
|
||||
|
||||
@cherrypy.expose
|
||||
|
@ -1137,15 +1212,15 @@ class WebInterface(object):
|
|||
# Handle the variable config options. Note - keys with False values aren't getting passed
|
||||
|
||||
checked_configs = [
|
||||
"launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github", "get_file_sizes",
|
||||
"launch_browser", "enable_https", "api_enabled", "freeze_db", "check_github", "get_file_sizes",
|
||||
"grouping_global_history", "grouping_user_history", "grouping_charts", "pms_use_bif", "pms_ssl",
|
||||
"movie_notify_enable", "tv_notify_enable", "music_notify_enable", "monitoring_use_websocket",
|
||||
"tv_notify_on_start", "movie_notify_on_start", "music_notify_on_start",
|
||||
"tv_notify_on_stop", "movie_notify_on_stop", "music_notify_on_stop",
|
||||
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause",
|
||||
"tv_notify_on_pause", "movie_notify_on_pause", "music_notify_on_pause",
|
||||
"refresh_libraries_on_startup", "refresh_users_on_startup",
|
||||
"ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
|
||||
"pms_is_remote", "home_stats_type", "group_history_tables", "notify_consecutive",
|
||||
"ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
|
||||
"pms_is_remote", "home_stats_type", "group_history_tables", "notify_consecutive",
|
||||
"notify_recently_added", "notify_recently_added_grandparent", "monitor_remote_access"
|
||||
]
|
||||
for checked_config in checked_configs:
|
||||
|
@ -1231,11 +1306,11 @@ class WebInterface(object):
|
|||
# Get new server URLs for SSL communications.
|
||||
if server_changed:
|
||||
plextv.get_real_pms_url()
|
||||
|
||||
|
||||
# Get new server friendly name.
|
||||
if server_changed:
|
||||
pmsconnect.get_server_friendly_name()
|
||||
|
||||
|
||||
# Reconfigure scheduler if intervals changed
|
||||
if reschedule:
|
||||
plexpy.initialize_scheduler()
|
||||
|
@ -1286,6 +1361,7 @@ class WebInterface(object):
|
|||
data=this_agent)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi('notify')
|
||||
def test_notifier(self, config_id=None, subject='PlexPy', body='Test notification', **kwargs):
|
||||
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
|
||||
|
||||
|
@ -1297,7 +1373,7 @@ class WebInterface(object):
|
|||
break
|
||||
else:
|
||||
this_agent = None
|
||||
|
||||
|
||||
if this_agent:
|
||||
logger.debug(u"Sending test %s notification." % this_agent['name'])
|
||||
notifiers.send_notification(this_agent['id'], subject, body, **kwargs)
|
||||
|
@ -1308,7 +1384,8 @@ class WebInterface(object):
|
|||
else:
|
||||
logger.debug(u"Unable to send test notification, no notification agent ID received.")
|
||||
return "No notification agent ID received."
|
||||
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
def twitterStep1(self):
|
||||
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
|
||||
|
@ -1373,6 +1450,7 @@ class WebInterface(object):
|
|||
cherrypy.response.status = 200
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_plexwatch_export_data(self, database_path=None, table_name=None, import_ignore_interval=0, **kwargs):
|
||||
from plexpy import plexwatch_import
|
||||
|
||||
|
@ -1404,6 +1482,7 @@ class WebInterface(object):
|
|||
return False
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_server_id(self, hostname=None, port=None, identifier=None, ssl=0, remote=0, **kwargs):
|
||||
from plexpy import http_handler
|
||||
|
||||
|
@ -1444,7 +1523,17 @@ class WebInterface(object):
|
|||
return None
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_server_pref(self, pref=None, **kwargs):
|
||||
""" Return a specified server preference.
|
||||
|
||||
Args:
|
||||
pref(string): 'name of preference'
|
||||
|
||||
Returns:
|
||||
String: ''
|
||||
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_server_pref(pref=pref)
|
||||
|
@ -1507,7 +1596,7 @@ class WebInterface(object):
|
|||
result = pms_connect.get_metadata_details(rating_key=rating_key, get_media_info=True)
|
||||
if result:
|
||||
metadata = result['metadata']
|
||||
|
||||
|
||||
if metadata:
|
||||
return serve_template(templatename="info.html", data=metadata, title="Info", config=config, source=source)
|
||||
else:
|
||||
|
@ -1553,15 +1642,8 @@ class WebInterface(object):
|
|||
|
||||
return None
|
||||
|
||||
|
||||
##### Search #####
|
||||
|
||||
@cherrypy.expose
|
||||
def search(self, query=''):
|
||||
|
||||
return serve_template(templatename="search.html", title="Search", query=query)
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi('search')
|
||||
def search_results(self, query, **kwargs):
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
@ -1573,6 +1655,10 @@ class WebInterface(object):
|
|||
else:
|
||||
logger.warn(u"Unable to retrieve data for search_results.")
|
||||
|
||||
@cherrypy.expose
|
||||
def search(self, query=''):
|
||||
return serve_template(templatename="search.html", title="Search", query=query)
|
||||
|
||||
@cherrypy.expose
|
||||
def get_search_results_children(self, query, media_type=None, season_index=None, **kwargs):
|
||||
|
||||
|
@ -1582,7 +1668,7 @@ class WebInterface(object):
|
|||
if media_type:
|
||||
result['results_list'] = {media_type: result['results_list'][media_type]}
|
||||
if media_type == 'season' and season_index:
|
||||
result['results_list']['season'] = [season for season in result['results_list']['season']
|
||||
result['results_list']['season'] = [season for season in result['results_list']['season']
|
||||
if season['media_index'] == season_index]
|
||||
|
||||
if result:
|
||||
|
@ -1591,10 +1677,6 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_search_results_children.")
|
||||
return serve_template(templatename="info_search_results_list.html", data=None, title="Search Result List")
|
||||
|
||||
|
||||
|
||||
##### Update Metadata #####
|
||||
|
||||
@cherrypy.expose
|
||||
def update_metadata(self, rating_key=None, query=None, update=False, **kwargs):
|
||||
query_string = query
|
||||
|
@ -1612,6 +1694,7 @@ class WebInterface(object):
|
|||
return serve_template(templatename="update_metadata.html", query=query, update=update, title="Info")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def update_metadata_details(self, old_rating_key, new_rating_key, media_type, **kwargs):
|
||||
data_factory = datafactory.DataFactory()
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
@ -1631,11 +1714,21 @@ class WebInterface(object):
|
|||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
|
||||
|
||||
# test code
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_new_rating_keys(self, rating_key='', media_type='', **kwargs):
|
||||
"""
|
||||
Grap the new rating keys
|
||||
|
||||
Args:
|
||||
rating_key(string): '',
|
||||
media_type(string): ''
|
||||
|
||||
Returns:
|
||||
json: ''
|
||||
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_rating_keys_list(rating_key=rating_key, media_type=media_type)
|
||||
|
@ -1647,7 +1740,17 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_new_rating_keys.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_old_rating_keys(self, rating_key='', media_type='', **kwargs):
|
||||
"""
|
||||
Grap the old rating keys
|
||||
Args:
|
||||
rating_key(string): '',
|
||||
media_type(string): ''
|
||||
Returns:
|
||||
json: ''
|
||||
|
||||
"""
|
||||
|
||||
data_factory = datafactory.DataFactory()
|
||||
result = data_factory.get_rating_keys_list(rating_key=rating_key, media_type=media_type)
|
||||
|
@ -1659,18 +1762,8 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_old_rating_keys.")
|
||||
|
||||
|
||||
##### API #####
|
||||
|
||||
@cherrypy.expose
|
||||
def api(self, *args, **kwargs):
|
||||
from plexpy.api import Api
|
||||
|
||||
a = Api()
|
||||
a.checkParams(*args, **kwargs)
|
||||
|
||||
return a.fetchData()
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_pms_sessions_json(self, **kwargs):
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
@ -1696,6 +1789,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_metadata_json.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi('get_metadata')
|
||||
def get_metadata_xml(self, rating_key='', **kwargs):
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
@ -1708,7 +1802,17 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_metadata_xml.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi('get_recently_added')
|
||||
def get_recently_added_json(self, count='0', **kwargs):
|
||||
""" Get all items that where recelty added to plex
|
||||
|
||||
Args:
|
||||
count(string): Number of items
|
||||
|
||||
Returns:
|
||||
dict: of all added items
|
||||
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_recently_added(count, 'json')
|
||||
|
@ -1720,19 +1824,9 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_recently_added_json.")
|
||||
|
||||
@cherrypy.expose
|
||||
def get_episode_list_json(self, rating_key='', **kwargs):
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_episode_list(rating_key, 'json')
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return result
|
||||
else:
|
||||
logger.warn(u"Unable to retrieve data for get_episode_list_json.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_friends_list(self, **kwargs):
|
||||
""" Gets the friends list of the server owner for plex.tv """
|
||||
|
||||
plex_tv = plextv.PlexTV()
|
||||
result = plex_tv.get_plextv_friends('json')
|
||||
|
@ -1744,7 +1838,9 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_friends_list.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_user_details(self, **kwargs):
|
||||
""" Get all details about a user from plextv """
|
||||
|
||||
plex_tv = plextv.PlexTV()
|
||||
result = plex_tv.get_plextv_user_details('json')
|
||||
|
@ -1756,7 +1852,9 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_user_details.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_server_list(self, **kwargs):
|
||||
""" Find all servers published on plextv"""
|
||||
|
||||
plex_tv = plextv.PlexTV()
|
||||
result = plex_tv.get_plextv_server_list('json')
|
||||
|
@ -1768,6 +1866,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_server_list.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_sync_lists(self, machine_id='', **kwargs):
|
||||
|
||||
plex_tv = plextv.PlexTV()
|
||||
|
@ -1780,7 +1879,22 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_sync_lists.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_servers(self, **kwargs):
|
||||
""" All servers
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
{"MediaContainer": {"@size": "1", "Server":
|
||||
{"@name": "dude-PC",
|
||||
"@host": "10.0.0.97",
|
||||
"@address": "10.0.0.97",
|
||||
"@port": "32400",
|
||||
"@machineIdentifier": "1234",
|
||||
"@version": "0.9.15.2.1663-7efd046"}}}
|
||||
```
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_server_list(output_format='json')
|
||||
|
@ -1792,7 +1906,24 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_servers.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_servers_info(self, **kwargs):
|
||||
""" Graps info about the server
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
[{"port": "32400",
|
||||
"host": "10.0.0.97",
|
||||
"version": "0.9.15.2.1663-7efd046",
|
||||
"name": "dude-PC",
|
||||
"machine_identifier": "1234"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_servers_info()
|
||||
|
@ -1804,6 +1935,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_servers_info.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_server_friendly_name(self, **kwargs):
|
||||
|
||||
result = pmsconnect.get_server_friendly_name()
|
||||
|
@ -1815,6 +1947,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_server_friendly_name.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_server_prefs(self, pref=None, **kwargs):
|
||||
|
||||
if pref:
|
||||
|
@ -1830,19 +1963,18 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_server_prefs.")
|
||||
|
||||
@cherrypy.expose
|
||||
def get_library_sections(self, **kwargs):
|
||||
|
||||
library_data = libraries.Libraries()
|
||||
result = library_data.get_sections()
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
else:
|
||||
logger.warn(u"Unable to retrieve data for get_library_sections.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_activity(self, **kwargs):
|
||||
""" Return processed and validated session list.
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
{stream_count: 1,
|
||||
session: [{dict}]
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_current_activity()
|
||||
|
@ -1854,7 +1986,22 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_activity.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_full_users_list(self, **kwargs):
|
||||
""" Get a list all users that has access to your server
|
||||
|
||||
Returns:
|
||||
json:
|
||||
```
|
||||
[{"username": "Hellowlol", "user_id": "1345",
|
||||
"thumb": "https://plex.tv/users/123aa/avatar",
|
||||
"is_allow_sync": null,
|
||||
"is_restricted": "0",
|
||||
"is_home_user": "0",
|
||||
"email": "John.Doe@email.com"}]
|
||||
```
|
||||
|
||||
"""
|
||||
|
||||
plex_tv = plextv.PlexTV()
|
||||
result = plex_tv.get_full_users_list()
|
||||
|
@ -1866,7 +2013,43 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_full_users_list.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_sync_item(self, sync_id, **kwargs):
|
||||
""" Return sync item details.
|
||||
|
||||
Args:
|
||||
sync_id(string): unique sync id for item
|
||||
output_format(string, optional): 'xml/json'
|
||||
|
||||
Returns:
|
||||
List:
|
||||
```
|
||||
{"data": [
|
||||
{"username": "username",
|
||||
"item_downloaded_percent_complete": 100,
|
||||
"user_id": "134",
|
||||
"failure": "",
|
||||
"title": "Some Movie",
|
||||
"total_size": "747195119",
|
||||
"root_title": "Movies",
|
||||
"music_bitrate": "128",
|
||||
"photo_quality": "49",
|
||||
"friendly_name": "username",
|
||||
"device_name": "Username iPad",
|
||||
"platform": "iOS",
|
||||
"state": "complete",
|
||||
"item_downloaded_count": "1",
|
||||
"content_type": "video",
|
||||
"metadata_type": "movie",
|
||||
"video_quality": "49",
|
||||
"item_count": "1",
|
||||
"rating_key": "59207",
|
||||
"item_complete_count": "1",
|
||||
"sync_id": "1234"}
|
||||
]
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_sync_item(sync_id, output_format='json')
|
||||
|
@ -1878,6 +2061,7 @@ class WebInterface(object):
|
|||
logger.warn(u"Unable to retrieve data for get_sync_item.")
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def get_sync_transcode_queue(self, **kwargs):
|
||||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
|
@ -1889,10 +2073,8 @@ class WebInterface(object):
|
|||
else:
|
||||
logger.warn(u"Unable to retrieve data for get_sync_transcode_queue.")
|
||||
|
||||
|
||||
|
||||
|
||||
@cherrypy.expose
|
||||
@addtoapi()
|
||||
def random_arnold_quotes(self, **kwargs):
|
||||
from random import randint
|
||||
quote_list = ['To crush your enemies, see them driven before you, and to hear the lamentation of their women!',
|
||||
|
@ -1921,4 +2103,16 @@ class WebInterface(object):
|
|||
]
|
||||
|
||||
random_number = randint(0, len(quote_list) - 1)
|
||||
return quote_list[int(random_number)]
|
||||
return quote_list[int(random_number)]
|
||||
|
||||
### API ###
|
||||
|
||||
@cherrypy.expose
|
||||
def api(self, *args, **kwargs):
|
||||
if args and 'v2' in args[0]:
|
||||
return API2()._api_run(**kwargs)
|
||||
else:
|
||||
from plexpy.api import Api
|
||||
a = Api()
|
||||
a.checkParams(*args, **kwargs)
|
||||
return a.fetchData()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue