diff --git a/data/interfaces/default/home_stats.html b/data/interfaces/default/home_stats.html index c71c47f42..ab0d33e51 100644 --- a/data/interfaces/default/home_stats.html +++ b/data/interfaces/default/home_stats.html @@ -46,9 +46,9 @@
  • - % if a['rows'][0]['grandparent_thumb'] != '': + % if a['rows'][0]['grandparent_thumb']: + src="pms_image_proxy?img=${a['rows'][0]['grandparent_thumb']}&width=162&height=240&fallback=poster"> % else: % endif @@ -75,7 +75,7 @@

    ${a['rows'][0]['total_plays']}

    % if a['rows'][0]['grandparent_thumb'] != '': + src="pms_image_proxy?img=${a['rows'][0]['grandparent_thumb']}&width=162&height=240&fallback=poster"> % else: % endif diff --git a/data/interfaces/default/js/tables/sync_table.js b/data/interfaces/default/js/tables/sync_table.js index c13a88cc4..9853c2fe0 100644 --- a/data/interfaces/default/js/tables/sync_table.js +++ b/data/interfaces/default/js/tables/sync_table.js @@ -9,12 +9,14 @@ sync_table_options = { "pageLength": 25, "stateSave": true, "language": { - "search":"Search: ", - "lengthMenu":"Show _MENU_ lines per page", - "emptyTable": "No synced items", - "info":"Showing _START_ to _END_ of _TOTAL_ lines", - "infoEmpty":"Showing 0 to 0 of 0 lines", - "infoFiltered":"(filtered from _MAX_ total lines)"}, + "search":"Search: ", + "lengthMenu":"Show _MENU_ lines per page", + "emptyTable": "No synced items", + "info":"Showing _START_ to _END_ of _TOTAL_ lines", + "infoEmpty":"Showing 0 to 0 of 0 lines", + "infoFiltered":"(filtered from _MAX_ total lines)", + "loadingRecords":' Loading items...' + }, "columnDefs": [ { "targets": [0], @@ -91,11 +93,10 @@ sync_table_options = { }, { "targets": [10], - "data": null, + "data": "item_downloaded_percent_complete", "createdCell": function (td, cellData, rowData, row, col) { if (rowData['item_count'] > 0 ) { - percent_complete = Math.round((rowData['item_downloaded_count']/rowData['item_count']*100),0); - $(td).html('' + percent_complete + '%'); + $(td).html('' + cellData + '%'); } else { $(td).html('0%'); } diff --git a/plexpy/common.py b/plexpy/common.py index ae8f41fe6..eb701edb0 100644 --- a/plexpy/common.py +++ b/plexpy/common.py @@ -25,10 +25,10 @@ from plexpy import version -#Identify Our Application +# Identify Our Application USER_AGENT = 'PlexPy/-' + version.PLEXPY_VERSION + ' (' + platform.system() + ' ' + platform.release() + ')' -### Notification Types +# Notification Types NOTIFY_SNATCH = 1 NOTIFY_DOWNLOAD = 2 @@ -36,13 +36,5 @@ notifyStrings[NOTIFY_SNATCH] = "Started Download" notifyStrings[NOTIFY_DOWNLOAD] = "Download Finished" -### Release statuses -UNKNOWN = -1 # should never happen -UNAIRED = 1 # releases that haven't dropped yet -SNATCHED = 2 # qualified with quality -WANTED = 3 # releases we don't have but want to get -DOWNLOADED = 4 # qualified with quality -SKIPPED = 5 # releases we don't want -ARCHIVED = 6 # releases that you don't have locally (counts toward download completion stats) -IGNORED = 7 # releases that you don't want included in your download stats -SNATCHED_PROPER = 9 # qualified with quality +DEFAULT_USER_THUMB = "interfaces/default/images/gravatar-default-80x80.png" +DEFAULT_POSTER_THUMB = "interfaces/default/images/poster.png" \ No newline at end of file diff --git a/plexpy/plextv.py b/plexpy/plextv.py index 07be4e51a..7967b3e63 100644 --- a/plexpy/plextv.py +++ b/plexpy/plextv.py @@ -17,17 +17,9 @@ from xml.dom import minidom from httplib import HTTPSConnection -from urlparse import parse_qsl -from urllib import urlencode import base64 -import cherrypy -import urllib -import urllib2 import plexpy -import os.path -import subprocess -import json class PlexTV(object): @@ -346,6 +338,8 @@ def get_synced_items(self, machine_id=None, user_id=None): status_item_ready_count = self.get_xml_attr(status, 'itemsReadyCount') status_item_successful_count = self.get_xml_attr(status, 'itemsSuccessfulCount') status_total_size = self.get_xml_attr(status, 'totalSize') + status_item_download_percent_complete = helpers.get_percent( + status_item_downloaded_count, status_item_count) for settings in item.getElementsByTagName('MediaSettings'): settings_audio_boost = self.get_xml_attr(settings, 'audioBoost') @@ -376,6 +370,7 @@ def get_synced_items(self, machine_id=None, user_id=None): "item_count": status_item_count, "item_complete_count": status_item_complete_count, "item_downloaded_count": status_item_downloaded_count, + "item_downloaded_percent_complete": status_item_download_percent_complete, "music_bitrate": settings_music_bitrate, "photo_quality": settings_photo_quality, "video_quality": settings_video_quality, diff --git a/plexpy/plexwatch.py b/plexpy/plexwatch.py index fbe475653..69659e31d 100644 --- a/plexpy/plexwatch.py +++ b/plexpy/plexwatch.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with PlexPy. If not, see . -from plexpy import logger, helpers, datatables, db +from plexpy import logger, helpers, datatables, db, common from xml.dom import minidom import sys if sys.version_info < (2, 7): @@ -100,8 +100,8 @@ def get_user_list(self, start='', length='', kwargs=None): rows = [] for item in users: - if not item['thumb']: - user_thumb = 'interfaces/default/images/gravatar-default-80x80.png' + if not item['thumb'] or item['thumb'] == '': + user_thumb = common.DEFAULT_USER_THUMB else: user_thumb = item['thumb'] @@ -710,8 +710,8 @@ def get_home_stats(self, time_range='30'): return None for item in result: - if not item['thumb']: - user_thumb = 'interfaces/default/images/gravatar-default-80x80.png' + if not item['thumb'] or item['thumb'] == '': + user_thumb = common.DEFAULT_USER_THUMB else: user_thumb = item[4] @@ -948,10 +948,20 @@ def get_user_friendly_name(self, user=None): def get_user_details(self, user=None, user_id=None): try: myDB = db.DBConnection() + t = self.get_history_table_name() + if user: - query = 'select user_id, username, friendly_name, email, thumb, ' \ - 'is_home_user, is_allow_sync, is_restricted FROM plexpy_users WHERE username = ? LIMIT 1' - result = myDB.select(query, args=[user]) + query = 'SELECT user_id, username, friendly_name, email, ' \ + 'thumb, is_home_user, is_allow_sync, is_restricted ' \ + 'FROM plexpy_users ' \ + 'WHERE username = ? ' \ + 'UNION ALL ' \ + 'SELECT null, user, null, null, null, null, null, null ' \ + 'FROM %s ' \ + 'WHERE user = ? ' \ + 'GROUP BY user ' \ + 'LIMIT 1' % t + result = myDB.select(query, args=[user, user]) elif user_id: query = 'select user_id, username, friendly_name, email, thumb, ' \ 'is_home_user, is_allow_sync, is_restricted FROM plexpy_users WHERE user_id = ? LIMIT 1' @@ -962,12 +972,16 @@ def get_user_details(self, user=None, user_id=None): friendly_name = item['username'] else: friendly_name = item['friendly_name'] + if not item['thumb'] or item['thumb'] == '': + user_thumb = common.DEFAULT_USER_THUMB + else: + user_thumb = item['thumb'] user_details = {"user_id": item['user_id'], "username": item['username'], "friendly_name": friendly_name, "email": item['email'], - "thumb": item['thumb'], + "thumb": user_thumb, "is_home_user": item['is_home_user'], "is_allow_sync": item['is_allow_sync'], "is_restricted": item['is_restricted'] diff --git a/plexpy/webserve.py b/plexpy/webserve.py index ae1cfa664..f56b8b341 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with PlexPy. If not, see . -from plexpy import logger, notifiers, plextv, pmsconnect, plexwatch, db +from plexpy import logger, notifiers, plextv, pmsconnect, plexwatch, db, common from plexpy.helpers import checked, radio from mako.lookup import TemplateLookup @@ -50,6 +50,10 @@ def serve_template(templatename, **kwargs): class WebInterface(object): + + def __init__(self): + self.interface_dir = os.path.join(str(plexpy.PROG_DIR), 'data/') + @cherrypy.expose def index(self): raise cherrypy.HTTPRedirect("home") @@ -108,7 +112,6 @@ def user(self, user=None): user_details = plex_watch.get_user_details(user) except: logger.warn("Unable to retrieve friendly name for user %s " % user) - friendly_name = user return serve_template(templatename="user.html", title="User", data=user_details) @@ -532,7 +535,7 @@ def get_recently_added(self, count='0', **kwargs): logger.warn('Unable to retrieve data.') @cherrypy.expose - def pms_image_proxy(self, img='', width='0', height='0', **kwargs): + def pms_image_proxy(self, img='', width='0', height='0', fallback=None, **kwargs): if img != '': try: pms_connect = pmsconnect.PmsConnect() @@ -541,10 +544,18 @@ def pms_image_proxy(self, img='', width='0', height='0', **kwargs): return result[1] except: logger.warn('Image proxy queried but errors occured.') - return 'No image' + if fallback == 'poster': + logger.info('Trying fallback image...') + try: + fallback_image = open(self.interface_dir + common.DEFAULT_POSTER_THUMB, 'rb') + cherrypy.response.headers['Content-type'] = 'image/png' + return fallback_image + except IOError, e: + logger.error('Unable to read fallback image. %s' % e) + return None else: logger.warn('Image proxy queried but no parameters received.') - return 'No image' + return None @cherrypy.expose def info(self, rating_key='', **kwargs):