mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 14:10:52 -07:00
Set on_created notification in database
This commit is contained in:
parent
539cd60e92
commit
d6b31dc542
3 changed files with 63 additions and 24 deletions
|
@ -552,7 +552,7 @@ def dbcheck():
|
||||||
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
'CREATE TABLE IF NOT EXISTS notify_log (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||||
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
|
'session_key INTEGER, rating_key INTEGER, user_id INTEGER, user TEXT, '
|
||||||
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
|
'agent_id INTEGER, agent_name TEXT, on_play INTEGER, on_stop INTEGER, on_watched INTEGER, '
|
||||||
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER)'
|
'on_pause INTEGER, on_resume INTEGER, on_buffer INTEGER, on_created INTEGER)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Upgrade users table from earlier versions
|
# Upgrade users table from earlier versions
|
||||||
|
@ -588,6 +588,15 @@ def dbcheck():
|
||||||
'ALTER TABLE notify_log ADD COLUMN on_buffer INTEGER'
|
'ALTER TABLE notify_log ADD COLUMN on_buffer INTEGER'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade notify_log table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT on_created from notify_log')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table notify_log.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE notify_log ADD COLUMN on_created INTEGER'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade sessions table from earlier versions
|
# Upgrade sessions table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT buffer_count from sessions')
|
c_db.execute('SELECT buffer_count from sessions')
|
||||||
|
|
|
@ -221,7 +221,7 @@ class TimelineHandler(object):
|
||||||
# print timeline
|
# print timeline
|
||||||
|
|
||||||
def is_item(self):
|
def is_item(self):
|
||||||
if 'itemID' in self.timeline and 'metadataState' in self.timeline:
|
if 'itemID' in self.timeline:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -254,7 +254,13 @@ class TimelineHandler(object):
|
||||||
if self.is_item():
|
if self.is_item():
|
||||||
|
|
||||||
this_state = self.timeline['state']
|
this_state = self.timeline['state']
|
||||||
this_metadataState = self.timeline['metadataState']
|
this_type = self.timeline['type']
|
||||||
|
this_metadataState = self.timeline.get('metadataState', None)
|
||||||
|
this_section_id = self.timeline['sectionID']
|
||||||
|
this_rating_key = self.timeline['itemID']
|
||||||
|
|
||||||
if this_state == 0 and this_metadataState == 'created':
|
# state: 5: done processing metadata
|
||||||
|
# type: 1: movie, 2: tv show, 4: episode, 8: artist, 10: track
|
||||||
|
types = [1, 2, 4, 8, 10]
|
||||||
|
if this_state == 5 and this_type in types and not this_metadataState:
|
||||||
self.on_created()
|
self.on_created()
|
|
@ -43,7 +43,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='play', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_stop'] and notify_action == 'stop' \
|
elif agent['on_stop'] and notify_action == 'stop' \
|
||||||
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT):
|
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < plexpy.CONFIG.NOTIFY_WATCHED_PERCENT):
|
||||||
|
@ -53,7 +53,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state='stop', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_pause'] and notify_action == 'pause' \
|
elif agent['on_pause'] and notify_action == 'pause' \
|
||||||
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
|
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
|
||||||
|
@ -63,7 +63,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state='pause', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_resume'] and notify_action == 'resume' \
|
elif agent['on_resume'] and notify_action == 'resume' \
|
||||||
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
|
and (plexpy.CONFIG.NOTIFY_CONSECUTIVE or progress_percent < 99):
|
||||||
|
@ -73,7 +73,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state='resume', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_buffer'] and notify_action == 'buffer':
|
elif agent['on_buffer'] and notify_action == 'buffer':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -82,7 +82,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
|
|
||||||
set_notify_state(session=stream_data, state='buffer', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_watched'] and notify_action == 'watched':
|
elif agent['on_watched'] and notify_action == 'watched':
|
||||||
# Get the current states for notifications from our db
|
# Get the current states for notifications from our db
|
||||||
|
@ -96,7 +96,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='watched', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Check in our notify log if the notification has already been sent
|
# Check in our notify log if the notification has already been sent
|
||||||
|
@ -108,7 +108,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='watched', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif stream_data['media_type'] == 'track':
|
elif stream_data['media_type'] == 'track':
|
||||||
if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:
|
if plexpy.CONFIG.MUSIC_NOTIFY_ENABLE:
|
||||||
|
@ -121,7 +121,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='play', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_stop'] and notify_action == 'stop':
|
elif agent['on_stop'] and notify_action == 'stop':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -130,7 +130,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='stop', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_pause'] and notify_action == 'pause':
|
elif agent['on_pause'] and notify_action == 'pause':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -139,7 +139,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='pause', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_resume'] and notify_action == 'resume':
|
elif agent['on_resume'] and notify_action == 'resume':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -148,7 +148,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='resume', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif agent['on_buffer'] and notify_action == 'buffer':
|
elif agent['on_buffer'] and notify_action == 'buffer':
|
||||||
# Build and send notification
|
# Build and send notification
|
||||||
|
@ -157,7 +157,7 @@ def notify(stream_data=None, notify_action=None):
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
# Set the notification state in the db
|
# Set the notification state in the db
|
||||||
set_notify_state(session=stream_data, state='buffer', agent_info=agent)
|
set_notify_state(session=stream_data, state=notify_action, agent_info=agent)
|
||||||
|
|
||||||
elif stream_data['media_type'] == 'clip':
|
elif stream_data['media_type'] == 'clip':
|
||||||
pass
|
pass
|
||||||
|
@ -177,6 +177,8 @@ def notify_timeline(timeline_data=None, notify_action=None):
|
||||||
notifiers.send_notification(config_id=agent['id'],
|
notifiers.send_notification(config_id=agent['id'],
|
||||||
subject=notify_strings[0],
|
subject=notify_strings[0],
|
||||||
body=notify_strings[1])
|
body=notify_strings[1])
|
||||||
|
# Set the notification state in the db
|
||||||
|
set_notify_state(session=timeline_data, state=notify_action, agent_info=agent)
|
||||||
else:
|
else:
|
||||||
logger.debug(u"PlexPy Notifier :: Notify timeline called but incomplete data received.")
|
logger.debug(u"PlexPy Notifier :: Notify timeline called but incomplete data received.")
|
||||||
|
|
||||||
|
@ -203,6 +205,21 @@ def get_notify_state(session):
|
||||||
|
|
||||||
return notify_states
|
return notify_states
|
||||||
|
|
||||||
|
def get_notify_state_timeline(timeline):
|
||||||
|
monitor_db = database.MonitorDatabase()
|
||||||
|
result = monitor_db.select('SELECT on_created, agent_id '
|
||||||
|
'FROM notify_log '
|
||||||
|
'WHERE rating_key = ? '
|
||||||
|
'ORDER BY id DESC',
|
||||||
|
args=[timeline['rating_key']])
|
||||||
|
notify_states = []
|
||||||
|
for item in result:
|
||||||
|
notify_state = {'on_created': item[0],
|
||||||
|
'agent_id': item[1]}
|
||||||
|
notify_states.append(notify_state)
|
||||||
|
|
||||||
|
return notify_states
|
||||||
|
|
||||||
|
|
||||||
def set_notify_state(session, state, agent_info):
|
def set_notify_state(session, state, agent_info):
|
||||||
|
|
||||||
|
@ -221,15 +238,22 @@ def set_notify_state(session, state, agent_info):
|
||||||
values = {'on_buffer': int(time.time())}
|
values = {'on_buffer': int(time.time())}
|
||||||
elif state == 'watched':
|
elif state == 'watched':
|
||||||
values = {'on_watched': int(time.time())}
|
values = {'on_watched': int(time.time())}
|
||||||
|
elif state == 'created':
|
||||||
|
values = {'on_created': int(time.time())}
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
keys = {'session_key': session['session_key'],
|
if state == 'created':
|
||||||
'rating_key': session['rating_key'],
|
keys = {'rating_key': session['rating_key'],
|
||||||
'user_id': session['user_id'],
|
'agent_id': agent_info['id'],
|
||||||
'user': session['user'],
|
'agent_name': agent_info['name']}
|
||||||
'agent_id': agent_info['id'],
|
else:
|
||||||
'agent_name': agent_info['name']}
|
keys = {'session_key': session['session_key'],
|
||||||
|
'rating_key': session['rating_key'],
|
||||||
|
'user_id': session['user_id'],
|
||||||
|
'user': session['user'],
|
||||||
|
'agent_id': agent_info['id'],
|
||||||
|
'agent_name': agent_info['name']}
|
||||||
|
|
||||||
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
monitor_db.upsert(table_name='notify_log', key_dict=keys, value_dict=values)
|
||||||
else:
|
else:
|
||||||
|
@ -326,7 +350,7 @@ def build_notify_text(session, state):
|
||||||
|
|
||||||
duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
|
duration = helpers.convert_milliseconds_to_minutes(metadata['duration'])
|
||||||
|
|
||||||
view_offset = ''
|
view_offset = 0
|
||||||
if 'view_offset' in session:
|
if 'view_offset' in session:
|
||||||
view_offset = helpers.convert_milliseconds_to_minutes(session['view_offset'])
|
view_offset = helpers.convert_milliseconds_to_minutes(session['view_offset'])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue