diff --git a/data/interfaces/default/history_new.html b/data/interfaces/default/history_new.html index d425d053..5650ca92 100644 --- a/data/interfaces/default/history_new.html +++ b/data/interfaces/default/history_new.html @@ -38,11 +38,12 @@ from plexpy import helpers Paused Stopped Duration - Completed + grandparentRatingKey RatingKey + diff --git a/data/interfaces/default/js/tables/history_table_new.js b/data/interfaces/default/js/tables/history_table_new.js index f5d9dd2b..be82ae88 100644 --- a/data/interfaces/default/js/tables/history_table_new.js +++ b/data/interfaces/default/js/tables/history_table_new.js @@ -90,7 +90,11 @@ history_table_options = { "createdCell": function (td, cellData, rowData, row, col) { if (cellData !== '') { if (rowData['media_type'] === 'movie' || rowData['media_type'] === 'episode') { - $(td).html('
' + cellData + '
'); + var transcode_dec = ''; + if (rowData['video_decision'] === 'transcode') { + transcode_dec = ' '; + } + $(td).html('
' + cellData + '
' + transcode_dec + '
'); } else if (rowData['media_type'] === 'track') { $(td).html('
' + cellData + '
'); } else { @@ -147,13 +151,18 @@ history_table_options = { "targets": [10], "data":"percent_complete", "render": function ( data, type, full ) { - if (data < 85) { - return ''+Math.round(data)+'%'; + if (data > 80) { + return '' + //return ''+Math.round(data)+'%'; + } else if (data > 40) { + return '' + //return '100%'; } else { - return '100%'; + return '' } }, "searchable": false, + "orderable": true, "className": "no-wrap" }, { @@ -179,8 +188,15 @@ history_table_options = { "data":"user", "searchable":false, "visible":false + }, + { + "targets": [15], + "data":"video_decision", + "searchable":false, + "visible":false } + ], "drawCallback": function (settings) { // Jump to top of page diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 7cf162d1..4fca223e 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -405,8 +405,8 @@ def dbcheck(): c_db.execute( 'CREATE TABLE IF NOT EXISTS session_history_metadata (id INTEGER PRIMARY KEY, ' 'rating_key INTEGER, parent_rating_key INTEGER, grandparent_rating_key INTEGER, ' - 'title TEXT, parent_title TEXT, grandparent_title TEXT, media_index INTEGER, parent_media_index INTEGER, ' - 'thumb TEXT, parent_thumb TEXT, grandparent_thumb TEXT, art TEXT, media_type TEXT, ' + 'title TEXT, parent_title TEXT, grandparent_title TEXT, full_title TEXT, media_index INTEGER, ' + 'parent_media_index INTEGER, thumb TEXT, parent_thumb TEXT, grandparent_thumb TEXT, art TEXT, media_type TEXT, ' 'year INTEGER, originally_available_at TEXT, added_at INTEGER, updated_at INTEGER, last_viewed_at INTEGER, ' 'content_rating TEXT, summary TEXT, rating TEXT, duration INTEGER, guid TEXT, ' 'directors TEXT, writers TEXT, actors TEXT, genres TEXT, studio TEXT)' @@ -547,6 +547,15 @@ def dbcheck(): 'ALTER TABLE sessions ADD COLUMN transcode_height INTEGER' ) + # Upgrade sessions table from earlier versions + try: + c_db.execute('SELECT full_title from session_history_metadata') + except sqlite3.OperationalError: + logger.debug(u"Altering database. Updating database table sessions.") + c_db.execute( + 'ALTER TABLE session_history_metadata ADD COLUMN full_title TEXT' + ) + conn_db.commit() c_db.close() diff --git a/plexpy/datafactory.py b/plexpy/datafactory.py index c5f9fbb2..0b1e3a8b 100644 --- a/plexpy/datafactory.py +++ b/plexpy/datafactory.py @@ -148,7 +148,7 @@ class DataFactory(object): '.user ELSE users.friendly_name END) as friendly_name', t1 + '.player', t1 + '.ip_address', - t2 + '.title', + t2 + '.full_title', t1 + '.started', t1 + '.paused_counter', t1 + '.stopped', @@ -160,7 +160,8 @@ class DataFactory(object): t1 + '.grandparent_rating_key as grandparent_rating_key', t1 + '.rating_key as rating_key', t1 + '.user', - t2 + '.media_type' + t2 + '.media_type', + t4 + '.video_decision' ] try: query = data_tables.ssp_query(table_name=t1, @@ -173,9 +174,11 @@ class DataFactory(object): search_regex=search_regex, custom_where=custom_where, group_by='', - join_type=['JOIN', 'JOIN'], - join_table=[t3, t2], - join_evals=[[t1 + '.user_id', t3 + '.user_id'], [t1 + '.id', t2 + '.id']], + join_type=['JOIN', 'JOIN', 'JOIN'], + join_table=[t3, t2, t4], + join_evals=[[t1 + '.user_id', t3 + '.user_id'], + [t1 + '.id', t2 + '.id'], + [t1 + '.id', t4 + '.id']], kwargs=kwargs) except: logger.warn("Unable to open PlexWatch database.") @@ -193,7 +196,7 @@ class DataFactory(object): "friendly_name": item['friendly_name'], "platform": item["player"], "ip_address": item["ip_address"], - "title": item["title"], + "title": item["full_title"], "started": item["started"], "paused_counter": item["paused_counter"], "stopped": item["stopped"], @@ -202,7 +205,8 @@ class DataFactory(object): "grandparent_rating_key": item["grandparent_rating_key"], "rating_key": item["rating_key"], "user": item["user"], - "media_type": item["media_type"] + "media_type": item["media_type"], + "video_decision": item["video_decision"], } if item['paused_counter'] > 0: diff --git a/plexpy/monitor.py b/plexpy/monitor.py index da22ccd0..c396d42e 100644 --- a/plexpy/monitor.py +++ b/plexpy/monitor.py @@ -130,6 +130,14 @@ def drop_session_db(): monitor_db = MonitorDatabase() monitor_db.action('DROP TABLE sessions') +def clear_history_tables(): + logger.debug(u"PlexPy Monitor :: Deleting all session_history records... No turning back now bub.") + monitor_db = MonitorDatabase() + monitor_db.action('DELETE FROM session_history') + monitor_db.action('DELETE FROM session_history_media_info') + monitor_db.action('DELETE FROM session_history_metadata') + monitor_db.action('VACUUM;') + def db_filename(filename="plexpy.db"): return os.path.join(plexpy.DATA_DIR, filename) @@ -365,17 +373,25 @@ class MonitorProcessing(object): actors = ";".join(metadata['actors']) genres = ";".join(metadata['genres']) + # Build media item title + if session['media_type'] == 'episode' or session['media_type'] == 'track': + full_title = '%s - %s' % (metadata['grandparent_title'], metadata['title']) + elif session['media_type'] == 'movie': + full_title = metadata['title'] + else: + full_title = metadata['title'] + logger.debug(u"PlexPy Monitor :: Attempting to write to session_history_metadata table...") query = 'INSERT INTO session_history_metadata (id, rating_key, parent_rating_key, ' \ - 'grandparent_rating_key, title, parent_title, grandparent_title, media_index, ' \ + 'grandparent_rating_key, title, parent_title, grandparent_title, full_title, media_index, ' \ 'parent_media_index, thumb, parent_thumb, grandparent_thumb, art, media_type, year, ' \ 'originally_available_at, added_at, updated_at, last_viewed_at, content_rating, summary, ' \ 'rating, duration, guid, directors, writers, actors, genres, studio) VALUES ' \ - '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' + '(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' args = [last_id, session['rating_key'], session['parent_rating_key'], session['grandparent_rating_key'], - session['title'], session['parent_title'], session['grandparent_title'], metadata['index'], - metadata['parent_index'], metadata['thumb'], metadata['parent_thumb'], + session['title'], session['parent_title'], session['grandparent_title'], full_title, + metadata['index'], metadata['parent_index'], metadata['thumb'], metadata['parent_thumb'], metadata['grandparent_thumb'], metadata['art'], session['media_type'], metadata['year'], metadata['originally_available_at'], metadata['added_at'], metadata['updated_at'], metadata['last_viewed_at'], metadata['content_rating'], metadata['summary'], metadata['rating'], diff --git a/plexpy/webserve.py b/plexpy/webserve.py index aa7713ca..8c9efa54 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, common, log_reader, datafactory +from plexpy import logger, notifiers, plextv, pmsconnect, plexwatch, db, common, log_reader, datafactory, monitor from plexpy.helpers import checked, radio from mako.lookup import TemplateLookup @@ -465,6 +465,12 @@ class WebInterface(object): cherrypy.response.headers['Content-type'] = 'application/json' return json.dumps(history) + @cherrypy.expose + def clear_all_history_new(self, **kwargs): + + monitor.clear_history_tables() + raise cherrypy.HTTPRedirect("history_new") + @cherrypy.expose def get_stream_details(self, rating_key=0, **kwargs):