Log a full_title field into the metadata table.

Create a clear_all_history_new endpoint to delete all old PlexPy session history IMMEDIATELY.
Add icon in history_new to indicate if video was transcoded or not.
Replace relatively inaccurate percent_completed with icons in history_new.
This commit is contained in:
Tim 2015-07-13 12:41:03 +02:00
parent 65b3930baa
commit 2b317f6fd4
6 changed files with 71 additions and 19 deletions

View file

@ -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()

View file

@ -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:

View file

@ -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'],

View file

@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with PlexPy. If not, see <http://www.gnu.org/licenses/>.
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):