Add temporary watched state for sessions

This commit is contained in:
JonnyWong16 2018-04-04 22:05:30 -07:00
parent 8465df5095
commit fcd7593764
3 changed files with 21 additions and 7 deletions

View file

@ -529,8 +529,8 @@ def dbcheck():
'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, '
'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title TEXT, '
'synced_version INTEGER, synced_version_profile TEXT, '
'buffer_count INTEGER DEFAULT 0, buffer_last_triggered INTEGER, last_paused INTEGER, write_attempts INTEGER DEFAULT 0, '
'raw_stream_info TEXT)'
'buffer_count INTEGER DEFAULT 0, buffer_last_triggered INTEGER, last_paused INTEGER, watched INTEGER DEFAULT 0, '
'write_attempts INTEGER DEFAULT 0, raw_stream_info TEXT)'
)
# session_history table :: This is a history table which logs essential stream details
@ -1038,6 +1038,15 @@ def dbcheck():
'ALTER TABLE sessions ADD COLUMN transcode_hw_encoding INTEGER'
)
# Upgrade sessions table from earlier versions
try:
c_db.execute('SELECT watched FROM sessions')
except sqlite3.OperationalError:
logger.debug(u"Altering database. Updating database table sessions.")
c_db.execute(
'ALTER TABLE sessions ADD COLUMN watched INTEGER DEFAULT 0'
)
# Upgrade session_history table from earlier versions
try:
c_db.execute('SELECT reference_id FROM session_history')

View file

@ -271,7 +271,7 @@ class ActivityHandler(object):
# Monitor if the stream has reached the watch percentage for notifications
# The only purpose of this is for notifications
if this_state != 'buffering':
if not db_session['watched'] and this_state != 'buffering':
progress_percent = helpers.get_percent(self.timeline['viewOffset'], db_session['duration'])
watched_percent = {'movie': plexpy.CONFIG.MOVIE_WATCHED_PERCENT,
'episode': plexpy.CONFIG.TV_WATCHED_PERCENT,
@ -280,12 +280,12 @@ class ActivityHandler(object):
}
if progress_percent >= watched_percent.get(db_session['media_type'], 101):
watched_notifiers = notification_handler.get_notify_state_enabled(
session=db_session, notify_action='on_watched', notified=False)
if watched_notifiers:
logger.debug(u"Tautulli ActivityHandler :: Session %s watched."
% str(self.get_session_key()))
ap.set_watched(session_key=self.get_session_key())
watched_notifiers = notification_handler.get_notify_state_enabled(
session=db_session, notify_action='on_watched', notified=False)
for d in watched_notifiers:
plexpy.NOTIFY_QUEUE.put({'stream_data': db_session.copy(),

View file

@ -540,3 +540,8 @@ class ActivityProcessor(object):
session = self.get_session_by_key(session_key=session_key)
self.db.action('UPDATE sessions SET write_attempts = ? WHERE session_key = ?',
[session['write_attempts'] + 1, session_key])
def set_watched(self, session_key=None):
self.db.action('UPDATE sessions SET watched = ?'
'WHERE session_key = ?',
[1, session_key])