diff --git a/data/interfaces/default/info.html b/data/interfaces/default/info.html index ef8fb57b..7187840e 100644 --- a/data/interfaces/default/info.html +++ b/data/interfaces/default/info.html @@ -782,6 +782,7 @@ DOCUMENTATION :: END % if metadata: <% data = defaultdict(None, **metadata) + history_user_id = '' if _session['user_group'] == 'admin' else _session['user_id'] %> @@ -795,7 +796,7 @@ DOCUMENTATION :: END return { json_data: JSON.stringify( d ), guid: "${data['guid']}", - user_id: "${_session['user_group']}" == "admin" ? null : "${_session['user_id']}" + user_id: "${history_user_id}" }; } } @@ -811,7 +812,7 @@ DOCUMENTATION :: END return { json_data: JSON.stringify( d ), grandparent_rating_key: "${data['rating_key']}", - user_id: "${_session['user_group']}" == "admin" ? null : "${_session['user_id']}" + user_id: "${history_user_id}" }; } } @@ -827,7 +828,7 @@ DOCUMENTATION :: END return { json_data: JSON.stringify( d ), parent_rating_key: "${data['rating_key']}", - user_id: "${_session['user_group']}" == "admin" ? null : "${_session['user_id']}" + user_id: "${history_user_id}" }; } } @@ -843,7 +844,7 @@ DOCUMENTATION :: END return { json_data: JSON.stringify( d ), rating_key: "${data['rating_key']}", - user_id: "${_session['user_group']}" == "admin" ? null : "${_session['user_id']}" + user_id: "${history_user_id}" }; } } @@ -868,6 +869,132 @@ DOCUMENTATION :: END $("#refresh-history-list").click(function () { history_table.draw(); }); + +% endif +% if data['media_type'] in ('show', 'season', 'artist', 'album', 'photo_album', 'collection', 'playlist'): + +% endif +% if data['media_type'] == 'collection': + +% endif + +% if _session['user_group'] == 'admin': + -% endif -% if data['media_type'] in ('show', 'season', 'artist', 'album', 'photo_album', 'collection', 'playlist'): - -% endif -% if data['media_type'] == 'collection': - -% endif - +% endif % if data.get('poster_url'): % if data: <% from plexpy.common import LIVE_TV_SECTION_ID %> +<% + history_user_id = '' if _session['user_group'] == 'admin' else _session['user_id'] +%> +% if _session['user_group'] == 'admin': + +% endif % endif \ No newline at end of file diff --git a/data/interfaces/default/user.html b/data/interfaces/default/user.html index 0a328b60..d9bdf58d 100644 --- a/data/interfaces/default/user.html +++ b/data/interfaces/default/user.html @@ -549,7 +549,101 @@ DOCUMENTATION :: END $(".inactive-user-tooltip").tooltip(); - % if _session['user_group'] == 'admin': + function recentlyWatched() { + // Populate recently watched + $.ajax({ + url: 'get_user_recently_watched', + async: true, + data: { + user_id: user_id, + limit: 50 + }, + complete: function(xhr, status) { + $("#user-recently-watched").html(xhr.responseText); + highlightWatchedScrollerButton(); + } + }); + } + + recentlyWatched(); + + function highlightWatchedScrollerButton() { + var scroller = $("#recently-watched-row-scroller"); + var numElems = scroller.find("li").length; + scroller.width(numElems * 175); + if (scroller.width() > $("#user-recently-watched").width()) { + $("#recently-watched-page-right").removeClass("disabled"); + } else { + $("#recently-watched-page-right").addClass("disabled"); + } + } + + $(window).resize(function() { + highlightWatchedScrollerButton(); + }); + + var leftTotal = 0; + $(".paginate").click(function (e) { + e.preventDefault(); + var scroller = $("#recently-watched-row-scroller"); + var containerWidth = $("#user-recently-watched").width(); + var scrollAmount = $(this).data("id") * parseInt(containerWidth / 175) * 175; + var leftMax = Math.min(-parseInt(scroller.width()) + Math.abs(scrollAmount), 0); + + leftTotal = Math.max(Math.min(leftTotal + scrollAmount, 0), leftMax); + scroller.animate({ left: leftTotal }, 250); + + if (leftTotal == 0) { + $("#recently-watched-page-left").addClass("disabled").blur(); + } else { + $("#recently-watched-page-left").removeClass("disabled"); + } + + if (leftTotal == leftMax) { + $("#recently-watched-page-right").addClass("disabled").blur(); + } else { + $("#recently-watched-page-right").removeClass("disabled"); + } + }); + + $(document).ready(function () { + + // Javascript to enable link to tab + var hash = document.location.hash; + var prefix = "tab_"; + if (hash) { + $('.nav-list a[href=' + hash.replace(prefix, "") + ']').tab('show').trigger('show.bs.tab'); + } + + // Change hash for page-reload + $('.nav-list a').on('shown.bs.tab', function (e) { + window.location.hash = e.target.hash.replace("#", "#" + prefix); + }); + + // Populate watch time stats + $.ajax({ + url: 'user_watch_time_stats', + async: true, + data: { user_id: user_id, user: username }, + complete: function(xhr, status) { + $("#user-time-stats").html(xhr.responseText); + } + }); + + // Populate platform stats + $.ajax({ + url: 'user_player_stats', + async: true, + data: { user_id: user_id, user: username }, + complete: function(xhr, status) { + $("#user-player-stats").html(xhr.responseText); + } + }); + + }); + +% if _session['user_group'] == 'admin': + % endif +% endif \ No newline at end of file diff --git a/plexpy/libraries.py b/plexpy/libraries.py index ac2b1919..27dff12b 100644 --- a/plexpy/libraries.py +++ b/plexpy/libraries.py @@ -143,7 +143,7 @@ def has_library_type(section_type): def get_collections(section_id): - plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN) + plex = Plex(plexpy.CONFIG.PMS_URL, session.get_session_user_token()) library = plex.get_library(section_id) if library.type not in ('movie', 'show', 'artist'): @@ -231,7 +231,7 @@ def get_collections_list(section_id=None, **kwargs): def get_playlists(section_id): - plex = Plex(plexpy.CONFIG.PMS_URL, plexpy.CONFIG.PMS_TOKEN) + plex = Plex(plexpy.CONFIG.PMS_URL, session.get_session_user_token()) library = Libraries().get_details(section_id=section_id) diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 0cb42e94..38e015d4 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -3020,8 +3020,7 @@ class SCRIPTS(Notifier): if user_id: user_tokens = users.Users().get_tokens(user_id=user_id) - if user_tokens and user_tokens['server_token']: - custom_env['PLEX_USER_TOKEN'] = str(user_tokens['server_token']) + custom_env['PLEX_USER_TOKEN'] = str(user_tokens['server_token']) if self.pythonpath and plexpy.INSTALL_TYPE not in ('windows', 'macos'): custom_env['PYTHONPATH'] = os.pathsep.join([p for p in sys.path if p]) diff --git a/plexpy/session.py b/plexpy/session.py index c4346ede..b3be5170 100644 --- a/plexpy/session.py +++ b/plexpy/session.py @@ -57,6 +57,22 @@ def get_session_user_id(): _session = get_session_info() return str(_session['user_id']) if _session['user_group'] == 'guest' and _session['user_id'] else None + +def get_session_user_token(): + """ + Returns the user's server_token for the current logged in session + """ + _session = get_session_info() + + if _session['user_group'] == 'guest' and _session['user_id']: + session_user_tokens = users.Users().get_tokens(_session['user_id']) + user_token = session_user_tokens['server_token'] + else: + user_token = plexpy.CONFIG.PMS_TOKEN + + return user_token + + def get_session_shared_libraries(): """ Returns a tuple of section_id for the current logged in session diff --git a/plexpy/users.py b/plexpy/users.py index 7d6d6ae3..0e4836b9 100644 --- a/plexpy/users.py +++ b/plexpy/users.py @@ -787,6 +787,12 @@ class Users(object): return session.friendly_name_to_username(result) def get_tokens(self, user_id=None): + tokens = { + 'allow_guest': 0, + 'user_token': '', + 'server_token': '' + } + if user_id: try: monitor_db = database.MonitorDatabase() @@ -800,11 +806,11 @@ class Users(object): } return tokens else: - return None + return tokens except: - return None + return tokens - return None + return tokens def get_filters(self, user_id=None): if not user_id: diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 3dee55d6..84e203c0 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -845,7 +845,7 @@ class WebInterface(object): @cherrypy.expose @cherrypy.tools.json_out() - @requireAuth(member_of("admin")) + @requireAuth() @addtoapi("get_collections_table") def get_collections_list(self, section_id=None, **kwargs): """ Get the data on the Tautulli collections tables. @@ -882,7 +882,7 @@ class WebInterface(object): @cherrypy.expose @cherrypy.tools.json_out() - @requireAuth(member_of("admin")) + @requireAuth() @addtoapi("get_playlists_table") def get_playlists_list(self, section_id=None, **kwargs): """ Get the data on the Tautulli playlists tables.