mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-20 05:13:21 -07:00
commit
2f2069e0ad
5 changed files with 600 additions and 54 deletions
|
@ -1,3 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of PlexPy.
|
||||
#
|
||||
# PlexPy is free software: you can redistribute it and/or modify
|
||||
|
@ -14,12 +17,14 @@
|
|||
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from plexpy import logger, helpers, users, http_handler, database
|
||||
|
||||
import xmltodict
|
||||
import json
|
||||
from xml.dom import minidom
|
||||
|
||||
import base64
|
||||
import plexpy
|
||||
|
||||
|
||||
def refresh_users():
|
||||
logger.info("Requesting users list refresh...")
|
||||
result = PlexTV().get_full_users_list()
|
||||
|
@ -54,6 +59,7 @@ def refresh_users():
|
|||
else:
|
||||
logger.warn("Unable to refresh users list.")
|
||||
|
||||
|
||||
def get_real_pms_url():
|
||||
logger.info("Requesting URLs for server...")
|
||||
|
||||
|
@ -91,6 +97,7 @@ def get_real_pms_url():
|
|||
plexpy.CONFIG.__setattr__('PMS_URL', fallback_url)
|
||||
plexpy.CONFIG.write()
|
||||
|
||||
|
||||
class PlexTV(object):
|
||||
"""
|
||||
Plex.tv authentication
|
||||
|
@ -133,7 +140,7 @@ class PlexTV(object):
|
|||
if plextv_response:
|
||||
xml_head = plextv_response.getElementsByTagName('user')
|
||||
if not xml_head:
|
||||
logger.warn("Error parsing XML for Plex.tv token: %s" % e)
|
||||
logger.warn("Error parsing XML for Plex.tv token")
|
||||
return []
|
||||
|
||||
auth_token = xml_head[0].getAttribute('authenticationToken')
|
||||
|
@ -401,4 +408,39 @@ class PlexTV(object):
|
|||
|
||||
server_urls.append(server_details)
|
||||
|
||||
return server_urls
|
||||
return server_urls
|
||||
|
||||
def discover(self):
|
||||
""" Query plex for all servers online. Returns the ones you own in a selectize format """
|
||||
result = self.get_plextv_resources(include_https=True, output_format='raw')
|
||||
servers = xmltodict.parse(result, process_namespaces=True, attr_prefix='')
|
||||
clean_servers = []
|
||||
|
||||
try:
|
||||
if servers:
|
||||
# Fix if its only one "device"
|
||||
if int(servers['MediaContainer']['size']) == 1:
|
||||
servers['MediaContainer']['Device'] = [servers['MediaContainer']['Device']]
|
||||
|
||||
for server in servers['MediaContainer']['Device']:
|
||||
# Only grab servers online and own
|
||||
if server.get('presence', None) == '1' and server.get('owned', None) == '1' and server.get('provides', None) == 'server':
|
||||
# If someone only has one connection..
|
||||
if isinstance(server['Connection'], dict):
|
||||
server['Connection'] = [server['Connection']]
|
||||
|
||||
for s in server['Connection']:
|
||||
# to avoid circular ref
|
||||
d = {}
|
||||
d.update(s)
|
||||
d.update(server)
|
||||
d['label'] = d['name']
|
||||
d['value'] = d['address']
|
||||
del d['Connection']
|
||||
clean_servers.append(d)
|
||||
|
||||
except Exception as e:
|
||||
logger.warn('Failed to get servers from plex %s' % e)
|
||||
return clean_servers
|
||||
|
||||
return json.dumps(clean_servers, indent=4)
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
# This file is part of PlexPy.
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# This file is part of PlexPy.
|
||||
#
|
||||
# PlexPy is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -97,8 +100,7 @@ class WebInterface(object):
|
|||
}
|
||||
|
||||
# The setup wizard just refreshes the page on submit so we must redirect to home if config set.
|
||||
# Also redirecting to home if a PMS token already exists - will remove this in future.
|
||||
if plexpy.CONFIG.FIRST_RUN_COMPLETE or plexpy.CONFIG.PMS_TOKEN:
|
||||
if plexpy.CONFIG.FIRST_RUN_COMPLETE:
|
||||
plexpy.initialize_scheduler()
|
||||
raise cherrypy.HTTPRedirect("home")
|
||||
else:
|
||||
|
@ -567,7 +569,7 @@ class WebInterface(object):
|
|||
|
||||
watched_percent = plexpy.CONFIG.NOTIFY_WATCHED_PERCENT
|
||||
|
||||
custom_where=[]
|
||||
custom_where = []
|
||||
if user_id:
|
||||
custom_where = [['session_history.user_id', user_id]]
|
||||
elif user:
|
||||
|
@ -897,7 +899,7 @@ class WebInterface(object):
|
|||
@cherrypy.expose
|
||||
def get_user_ips(self, user_id=None, user=None, **kwargs):
|
||||
|
||||
custom_where=[]
|
||||
custom_where = []
|
||||
if user_id:
|
||||
custom_where = [['user_id', user_id]]
|
||||
elif user:
|
||||
|
@ -1131,7 +1133,7 @@ class WebInterface(object):
|
|||
|
||||
pms_connect = pmsconnect.PmsConnect()
|
||||
result = pms_connect.get_server_children()
|
||||
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
|
@ -1396,8 +1398,8 @@ class WebInterface(object):
|
|||
new_key_list = pms_connect.get_rating_keys_list(rating_key=new_rating_key, media_type=media_type)
|
||||
|
||||
update_db = data_factory.update_rating_key(old_key_list=old_key_list,
|
||||
new_key_list=new_key_list,
|
||||
media_type=media_type)
|
||||
new_key_list=new_key_list,
|
||||
media_type=media_type)
|
||||
|
||||
if update_db:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
|
@ -1406,7 +1408,6 @@ class WebInterface(object):
|
|||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps({'message': 'no data received'})
|
||||
|
||||
|
||||
# test code
|
||||
@cherrypy.expose
|
||||
def get_new_rating_keys(self, rating_key='', media_type='', **kwargs):
|
||||
|
@ -1443,11 +1444,27 @@ class WebInterface(object):
|
|||
new_key_list = pms_connect.get_rating_keys_list(rating_key=new_rating_key, media_type=media_type)
|
||||
|
||||
result = data_factory.update_rating_key(old_key_list=old_key_list,
|
||||
new_key_list=new_key_list,
|
||||
media_type=media_type)
|
||||
new_key_list=new_key_list,
|
||||
media_type=media_type)
|
||||
|
||||
if result:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return json.dumps(result)
|
||||
else:
|
||||
logger.warn('Unable to retrieve data.')
|
||||
|
||||
@cherrypy.expose
|
||||
def discover(self, token=''):
|
||||
"""
|
||||
Returns the servers that you own as a
|
||||
list of dicts (formatted for selectize)
|
||||
"""
|
||||
# Need to set token so result dont return http 401
|
||||
plexpy.CONFIG.__setattr__('PMS_TOKEN', token)
|
||||
plexpy.CONFIG.write()
|
||||
|
||||
result = plextv.PlexTV()
|
||||
servers = result.discover()
|
||||
if servers:
|
||||
cherrypy.response.headers['Content-type'] = 'application/json'
|
||||
return servers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue