mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Save Live TV sessions to the database
This commit is contained in:
parent
13a45facf9
commit
66c1fd6593
4 changed files with 61 additions and 9 deletions
|
@ -604,7 +604,8 @@ def dbcheck():
|
||||||
'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, '
|
'transcode_hw_decoding INTEGER, transcode_hw_encoding INTEGER, '
|
||||||
'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title TEXT, '
|
'optimized_version INTEGER, optimized_version_profile TEXT, optimized_version_title TEXT, '
|
||||||
'synced_version INTEGER, synced_version_profile TEXT, '
|
'synced_version INTEGER, synced_version_profile TEXT, '
|
||||||
'live INTEGER, live_uuid TEXT, secure INTEGER, relayed INTEGER, '
|
'live INTEGER, live_uuid TEXT, channel_call_sign TEXT, channel_identifier TEXT, channel_thumb TEXT, '
|
||||||
|
'secure INTEGER, relayed INTEGER, '
|
||||||
'buffer_count INTEGER DEFAULT 0, buffer_last_triggered INTEGER, last_paused INTEGER, watched INTEGER DEFAULT 0, '
|
'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)'
|
'write_attempts INTEGER DEFAULT 0, raw_stream_info TEXT)'
|
||||||
)
|
)
|
||||||
|
@ -652,7 +653,7 @@ def dbcheck():
|
||||||
'art TEXT, media_type TEXT, year INTEGER, originally_available_at TEXT, added_at INTEGER, updated_at INTEGER, '
|
'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, tagline TEXT, rating TEXT, '
|
'last_viewed_at INTEGER, content_rating TEXT, summary TEXT, tagline TEXT, rating TEXT, '
|
||||||
'duration INTEGER DEFAULT 0, guid TEXT, directors TEXT, writers TEXT, actors TEXT, genres TEXT, studio TEXT, '
|
'duration INTEGER DEFAULT 0, guid TEXT, directors TEXT, writers TEXT, actors TEXT, genres TEXT, studio TEXT, '
|
||||||
'labels TEXT)'
|
'labels TEXT, live INTEGER DEFAULT 0, channel_call_sign TEXT, channel_identifier TEXT, channel_thumb TEXT)'
|
||||||
)
|
)
|
||||||
|
|
||||||
# users table :: This table keeps record of the friends list
|
# users table :: This table keeps record of the friends list
|
||||||
|
@ -1220,6 +1221,21 @@ def dbcheck():
|
||||||
'ALTER TABLE sessions ADD COLUMN stream_video_dynamic_range TEXT'
|
'ALTER TABLE sessions ADD COLUMN stream_video_dynamic_range TEXT'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade sessions table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT channel_identifier FROM sessions')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table sessions.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE sessions ADD COLUMN channel_call_sign TEXT'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE sessions ADD COLUMN channel_identifier TEXT'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE sessions ADD COLUMN channel_thumb TEXT'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade session_history table from earlier versions
|
# Upgrade session_history table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT reference_id FROM session_history')
|
c_db.execute('SELECT reference_id FROM session_history')
|
||||||
|
@ -1327,6 +1343,24 @@ def dbcheck():
|
||||||
'ALTER TABLE session_history_metadata ADD COLUMN original_title TEXT'
|
'ALTER TABLE session_history_metadata ADD COLUMN original_title TEXT'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Upgrade session_history_metadata table from earlier versions
|
||||||
|
try:
|
||||||
|
c_db.execute('SELECT live FROM session_history_metadata')
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
logger.debug(u"Altering database. Updating database table session_history_metadata.")
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE session_history_metadata ADD COLUMN live INTEGER DEFAULT 0'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE session_history_metadata ADD COLUMN channel_call_sign TEXT'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE session_history_metadata ADD COLUMN channel_identifier TEXT'
|
||||||
|
)
|
||||||
|
c_db.execute(
|
||||||
|
'ALTER TABLE session_history_metadata ADD COLUMN channel_thumb TEXT'
|
||||||
|
)
|
||||||
|
|
||||||
# Upgrade session_history_media_info table from earlier versions
|
# Upgrade session_history_media_info table from earlier versions
|
||||||
try:
|
try:
|
||||||
c_db.execute('SELECT transcode_decision FROM session_history_media_info')
|
c_db.execute('SELECT transcode_decision FROM session_history_media_info')
|
||||||
|
|
|
@ -235,6 +235,11 @@ class ActivityProcessor(object):
|
||||||
if not is_import:
|
if not is_import:
|
||||||
logger.debug(u"Tautulli ActivityProcessor :: Fetching metadata for item ratingKey %s" % session['rating_key'])
|
logger.debug(u"Tautulli ActivityProcessor :: Fetching metadata for item ratingKey %s" % session['rating_key'])
|
||||||
pms_connect = pmsconnect.PmsConnect()
|
pms_connect = pmsconnect.PmsConnect()
|
||||||
|
if session['live']:
|
||||||
|
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']),
|
||||||
|
cache_key=session['session_key'],
|
||||||
|
skip_cache_time=True)
|
||||||
|
else:
|
||||||
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']))
|
metadata = pms_connect.get_metadata_details(rating_key=str(session['rating_key']))
|
||||||
if not metadata:
|
if not metadata:
|
||||||
return False
|
return False
|
||||||
|
@ -453,7 +458,11 @@ class ActivityProcessor(object):
|
||||||
'actors': actors,
|
'actors': actors,
|
||||||
'genres': genres,
|
'genres': genres,
|
||||||
'studio': metadata['studio'],
|
'studio': metadata['studio'],
|
||||||
'labels': labels
|
'labels': labels,
|
||||||
|
'live': session['live'],
|
||||||
|
'channel_call_sign': metadata['channel_call_sign'],
|
||||||
|
'channel_identifier': metadata['channel_identifier'],
|
||||||
|
'channel_thumb': metadata['channel_thumb']
|
||||||
}
|
}
|
||||||
|
|
||||||
# logger.debug(u"Tautulli ActivityProcessor :: Writing sessionKey %s session_history_metadata transaction..."
|
# logger.debug(u"Tautulli ActivityProcessor :: Writing sessionKey %s session_history_metadata transaction..."
|
||||||
|
|
|
@ -94,6 +94,7 @@ class DataFactory(object):
|
||||||
'session_history_metadata.thumb',
|
'session_history_metadata.thumb',
|
||||||
'session_history_metadata.parent_thumb',
|
'session_history_metadata.parent_thumb',
|
||||||
'session_history_metadata.grandparent_thumb',
|
'session_history_metadata.grandparent_thumb',
|
||||||
|
'session_history_metadata.live',
|
||||||
'MAX((CASE WHEN (view_offset IS NULL OR view_offset = "") THEN 0.1 ELSE view_offset * 1.0 END) / \
|
'MAX((CASE WHEN (view_offset IS NULL OR view_offset = "") THEN 0.1 ELSE view_offset * 1.0 END) / \
|
||||||
(CASE WHEN (session_history_metadata.duration IS NULL OR session_history_metadata.duration = "") \
|
(CASE WHEN (session_history_metadata.duration IS NULL OR session_history_metadata.duration = "") \
|
||||||
THEN 1.0 ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete',
|
THEN 1.0 ELSE session_history_metadata.duration * 1.0 END) * 100) AS percent_complete',
|
||||||
|
@ -142,6 +143,7 @@ class DataFactory(object):
|
||||||
'thumb',
|
'thumb',
|
||||||
'parent_thumb',
|
'parent_thumb',
|
||||||
'grandparent_thumb',
|
'grandparent_thumb',
|
||||||
|
'live',
|
||||||
'MAX((CASE WHEN (view_offset IS NULL OR view_offset = "") THEN 0.1 ELSE view_offset * 1.0 END) / \
|
'MAX((CASE WHEN (view_offset IS NULL OR view_offset = "") THEN 0.1 ELSE view_offset * 1.0 END) / \
|
||||||
(CASE WHEN (duration IS NULL OR duration = "") \
|
(CASE WHEN (duration IS NULL OR duration = "") \
|
||||||
THEN 1.0 ELSE duration * 1.0 END) * 100) AS percent_complete',
|
THEN 1.0 ELSE duration * 1.0 END) * 100) AS percent_complete',
|
||||||
|
@ -206,6 +208,9 @@ class DataFactory(object):
|
||||||
else:
|
else:
|
||||||
thumb = item['thumb']
|
thumb = item['thumb']
|
||||||
|
|
||||||
|
if item['live']:
|
||||||
|
item['percent_complete'] = 100
|
||||||
|
|
||||||
if item['percent_complete'] >= watched_percent[item['media_type']]:
|
if item['percent_complete'] >= watched_percent[item['media_type']]:
|
||||||
watched_status = 1
|
watched_status = 1
|
||||||
elif item['percent_complete'] >= watched_percent[item['media_type']]/2:
|
elif item['percent_complete'] >= watched_percent[item['media_type']]/2:
|
||||||
|
@ -230,6 +235,7 @@ class DataFactory(object):
|
||||||
'product': item['product'],
|
'product': item['product'],
|
||||||
'player': item['player'],
|
'player': item['player'],
|
||||||
'ip_address': item['ip_address'],
|
'ip_address': item['ip_address'],
|
||||||
|
'live': item['live'],
|
||||||
'media_type': item['media_type'],
|
'media_type': item['media_type'],
|
||||||
'rating_key': item['rating_key'],
|
'rating_key': item['rating_key'],
|
||||||
'parent_rating_key': item['parent_rating_key'],
|
'parent_rating_key': item['parent_rating_key'],
|
||||||
|
@ -1016,7 +1022,9 @@ class DataFactory(object):
|
||||||
'session_history_media_info.container, session_history_media_info.bitrate, ' \
|
'session_history_media_info.container, session_history_media_info.bitrate, ' \
|
||||||
'session_history_media_info.video_codec, session_history_media_info.video_resolution, ' \
|
'session_history_media_info.video_codec, session_history_media_info.video_resolution, ' \
|
||||||
'session_history_media_info.video_framerate, session_history_media_info.audio_codec, ' \
|
'session_history_media_info.video_framerate, session_history_media_info.audio_codec, ' \
|
||||||
'session_history_media_info.audio_channels ' \
|
'session_history_media_info.audio_channels, session_history_metadata.live, ' \
|
||||||
|
'session_history_metadata.channel_call_sign, session_history_metadata.channel_identifier, ' \
|
||||||
|
'session_history_metadata.channel_thumb ' \
|
||||||
'FROM session_history_metadata ' \
|
'FROM session_history_metadata ' \
|
||||||
'JOIN library_sections ON session_history_metadata.section_id = library_sections.section_id ' \
|
'JOIN library_sections ON session_history_metadata.section_id = library_sections.section_id ' \
|
||||||
'JOIN session_history_media_info ON session_history_metadata.id = session_history_media_info.id ' \
|
'JOIN session_history_media_info ON session_history_metadata.id = session_history_media_info.id ' \
|
||||||
|
|
|
@ -571,7 +571,7 @@ class PmsConnect(object):
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def get_metadata_details(self, rating_key='', sync_id='', cache_key=None, media_info=True):
|
def get_metadata_details(self, rating_key='', sync_id='', cache_key=None, skip_cache_time=False, media_info=True):
|
||||||
"""
|
"""
|
||||||
Return processed and validated metadata list for requested item.
|
Return processed and validated metadata list for requested item.
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ class PmsConnect(object):
|
||||||
if metadata:
|
if metadata:
|
||||||
_cache_time = metadata.pop('_cache_time', 0)
|
_cache_time = metadata.pop('_cache_time', 0)
|
||||||
# Return cached metadata if less than METADATA_CACHE_SECONDS ago
|
# Return cached metadata if less than METADATA_CACHE_SECONDS ago
|
||||||
if int(time.time()) - _cache_time <= plexpy.CONFIG.METADATA_CACHE_SECONDS:
|
if skip_cache_time or int(time.time()) - _cache_time <= plexpy.CONFIG.METADATA_CACHE_SECONDS:
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
if rating_key:
|
if rating_key:
|
||||||
|
@ -641,8 +641,6 @@ class PmsConnect(object):
|
||||||
if metadata_main.nodeName == 'Directory' and metadata_type == 'photo':
|
if metadata_main.nodeName == 'Directory' and metadata_type == 'photo':
|
||||||
metadata_type = 'photo_album'
|
metadata_type = 'photo_album'
|
||||||
|
|
||||||
live = int(helpers.get_xml_attr(metadata_main, 'live') == '1')
|
|
||||||
|
|
||||||
section_id = helpers.get_xml_attr(a, 'librarySectionID')
|
section_id = helpers.get_xml_attr(a, 'librarySectionID')
|
||||||
library_name = helpers.get_xml_attr(a, 'librarySectionTitle')
|
library_name = helpers.get_xml_attr(a, 'librarySectionTitle')
|
||||||
|
|
||||||
|
@ -1344,7 +1342,10 @@ class PmsConnect(object):
|
||||||
'parts': parts
|
'parts': parts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
live = int(helpers.get_xml_attr(metadata_main, 'live') == '1')
|
||||||
|
|
||||||
if live:
|
if live:
|
||||||
|
media_info['live'] = live
|
||||||
media_info['channel_call_sign'] = helpers.get_xml_attr(media, 'channelCallSign')
|
media_info['channel_call_sign'] = helpers.get_xml_attr(media, 'channelCallSign')
|
||||||
media_info['channel_identifier'] = helpers.get_xml_attr(media, 'channelIdentifier')
|
media_info['channel_identifier'] = helpers.get_xml_attr(media, 'channelIdentifier')
|
||||||
media_info['channel_thumb'] = helpers.get_xml_attr(media, 'channelThumb')
|
media_info['channel_thumb'] = helpers.get_xml_attr(media, 'channelThumb')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue