mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Get additional Live TV metadata from metadata.provider.plex.tv
This commit is contained in:
parent
5d1bc3cf9b
commit
df851e67f9
5 changed files with 44 additions and 41 deletions
|
@ -223,10 +223,6 @@ class DataFactory(object):
|
|||
else:
|
||||
watched_status = 0
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if item['live'] and not item['originally_available_at']:
|
||||
item['originally_available_at'] = helpers.timestamp_to_iso_date(item['added_at'])
|
||||
|
||||
# Rename Mystery platform names
|
||||
platform = common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])
|
||||
|
||||
|
@ -1060,10 +1056,6 @@ class DataFactory(object):
|
|||
else:
|
||||
section_name = ''
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if item['live'] and not item['originally_available_at']:
|
||||
item['originally_available_at'] = helpers.timestamp_to_iso_date(item['added_at'])
|
||||
|
||||
directors = item['directors'].split(';') if item['directors'] else []
|
||||
writers = item['writers'].split(';') if item['writers'] else []
|
||||
actors = item['actors'].split(';') if item['actors'] else []
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Tautulli. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import arrow
|
||||
import base64
|
||||
import certifi
|
||||
import cloudinary
|
||||
|
@ -221,8 +222,20 @@ def utc_now_iso():
|
|||
return utcnow.isoformat()
|
||||
|
||||
|
||||
def timestamp_to_iso_date(timestamp):
|
||||
return datetime.datetime.fromtimestamp(cast_to_int(timestamp)).strftime("%Y-%m-%d")
|
||||
def timestamp_to_YMD(timestamp):
|
||||
return timestamp_to_datetime(timestamp).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def timestamp_to_datetime(timestamp):
|
||||
return datetime.datetime.fromtimestamp(cast_to_int(str(timestamp)))
|
||||
|
||||
|
||||
def iso_to_YMD(iso):
|
||||
return iso_to_datetime(iso).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def iso_to_datetime(iso):
|
||||
return arrow.get(iso).datetime
|
||||
|
||||
|
||||
def human_duration(s, sig='dhms'):
|
||||
|
|
|
@ -329,10 +329,6 @@ class Libraries(object):
|
|||
else:
|
||||
library_thumb = common.DEFAULT_COVER_THUMB
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if item['live'] and not item['originally_available_at']:
|
||||
item['originally_available_at'] = helpers.timestamp_to_iso_date(item['added_at'])
|
||||
|
||||
row = {'section_id': item['section_id'],
|
||||
'section_name': item['section_name'],
|
||||
'section_type': item['section_type'],
|
||||
|
@ -913,10 +909,6 @@ class Libraries(object):
|
|||
else:
|
||||
thumb = row['thumb']
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if row['live'] and not row['originally_available_at']:
|
||||
row['originally_available_at'] = helpers.timestamp_to_iso_date(row['added_at'])
|
||||
|
||||
recent_output = {'row_id': row['id'],
|
||||
'media_type': row['media_type'],
|
||||
'rating_key': row['rating_key'],
|
||||
|
|
|
@ -571,7 +571,8 @@ class PmsConnect(object):
|
|||
|
||||
return output
|
||||
|
||||
def get_metadata_details(self, rating_key='', sync_id='', cache_key=None, skip_cache_time=False, media_info=True):
|
||||
def get_metadata_details(self, rating_key='', sync_id='', plex_guid='',
|
||||
cache_key=None, skip_cache_time=False, media_info=True):
|
||||
"""
|
||||
Return processed and validated metadata list for requested item.
|
||||
|
||||
|
@ -604,6 +605,11 @@ class PmsConnect(object):
|
|||
metadata_xml = self.get_metadata(str(rating_key), output_format='xml')
|
||||
elif sync_id:
|
||||
metadata_xml = self.get_sync_item(str(sync_id), output_format='xml')
|
||||
elif plex_guid:
|
||||
rating_key = plex_guid.rsplit('/', 1)[-1]
|
||||
plextv_metadata = PmsConnect(token=plexpy.CONFIG.PMS_TOKEN)
|
||||
plextv_metadata.url = 'https://metadata.provider.plex.tv'
|
||||
metadata_xml = plextv_metadata.get_metadata(rating_key, output_format='xml')
|
||||
else:
|
||||
return metadata
|
||||
|
||||
|
@ -778,7 +784,13 @@ class PmsConnect(object):
|
|||
|
||||
elif metadata_type == 'season':
|
||||
parent_rating_key = helpers.get_xml_attr(metadata_main, 'parentRatingKey')
|
||||
show_details = self.get_metadata_details(parent_rating_key) if parent_rating_key else {}
|
||||
parent_guid = helpers.get_xml_attr(metadata_main, 'parentGuid')
|
||||
show_details = {}
|
||||
if plex_guid and parent_guid:
|
||||
show_details = self.get_metadata_details(plex_guid=parent_guid)
|
||||
elif not plex_guid and parent_rating_key:
|
||||
show_details = self.get_metadata_details(parent_rating_key)
|
||||
|
||||
metadata = {'media_type': metadata_type,
|
||||
'section_id': section_id,
|
||||
'library_name': library_name,
|
||||
|
@ -829,13 +841,18 @@ class PmsConnect(object):
|
|||
|
||||
elif metadata_type == 'episode':
|
||||
grandparent_rating_key = helpers.get_xml_attr(metadata_main, 'grandparentRatingKey')
|
||||
show_details = self.get_metadata_details(grandparent_rating_key) if grandparent_rating_key else {}
|
||||
grandparent_guid = helpers.get_xml_attr(metadata_main, 'grandparentGuid')
|
||||
show_details = {}
|
||||
if plex_guid and grandparent_guid:
|
||||
show_details = self.get_metadata_details(plex_guid=grandparent_guid)
|
||||
elif not plex_guid and grandparent_rating_key:
|
||||
show_details = self.get_metadata_details(grandparent_rating_key)
|
||||
|
||||
parent_rating_key = helpers.get_xml_attr(metadata_main, 'parentRatingKey')
|
||||
parent_media_index = helpers.get_xml_attr(metadata_main, 'parentIndex')
|
||||
parent_thumb = helpers.get_xml_attr(metadata_main, 'parentThumb')
|
||||
|
||||
if not parent_rating_key:
|
||||
if not plex_guid and not parent_rating_key:
|
||||
# Try getting the parent_rating_key from the parent_thumb
|
||||
if parent_thumb.startswith('/library/metadata/'):
|
||||
parent_rating_key = parent_thumb.split('/')[3]
|
||||
|
@ -1249,9 +1266,14 @@ class PmsConnect(object):
|
|||
else:
|
||||
return metadata
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if metadata['live'] and not metadata['originally_available_at']:
|
||||
metadata['originally_available_at'] = helpers.timestamp_to_iso_date(metadata['added_at'])
|
||||
# Get additional metadata from metadata.provider.plex.tv
|
||||
if not plex_guid and metadata['live']:
|
||||
plextv_metadata = self.get_metadata_details(plex_guid=metadata['guid'])
|
||||
keys_to_update = ['summary', 'rating', 'thumb', 'grandparent_thumb', 'duration',
|
||||
'guid', 'grandparent_guid', 'genres']
|
||||
for key in keys_to_update:
|
||||
metadata[key] = plextv_metadata[key]
|
||||
metadata['originally_available_at'] = helpers.iso_to_YMD(plextv_metadata['originally_available_at'])
|
||||
|
||||
if metadata and media_info:
|
||||
medias = []
|
||||
|
@ -1973,10 +1995,6 @@ class PmsConnect(object):
|
|||
source_subtitle_details = next((p for p in source_media_part_streams if p['id'] == subtitle_id),
|
||||
next((p for p in source_media_part_streams if p['type'] == '3'), source_subtitle_details))
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if stream_details['live'] and not metadata_details['originally_available_at']:
|
||||
metadata_details['originally_available_at'] = helpers.timestamp_to_iso_date(metadata_details['added_at'])
|
||||
|
||||
# Overrides for live sessions
|
||||
if stream_details['live'] and transcode_session:
|
||||
stream_details['stream_container_decision'] = 'transcode'
|
||||
|
|
|
@ -161,10 +161,6 @@ class Users(object):
|
|||
else:
|
||||
user_thumb = common.DEFAULT_USER_THUMB
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if item['live'] and not item['originally_available_at']:
|
||||
item['originally_available_at'] = helpers.timestamp_to_iso_date(item['added_at'])
|
||||
|
||||
# Rename Mystery platform names
|
||||
platform = common.PLATFORM_NAME_OVERRIDES.get(item['platform'], item['platform'])
|
||||
|
||||
|
@ -274,10 +270,6 @@ class Users(object):
|
|||
else:
|
||||
thumb = item["thumb"]
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if item['live'] and not item['originally_available_at']:
|
||||
item['originally_available_at'] = helpers.timestamp_to_iso_date(item['added_at'])
|
||||
|
||||
# Rename Mystery platform names
|
||||
platform = common.PLATFORM_NAME_OVERRIDES.get(item["platform"], item["platform"])
|
||||
|
||||
|
@ -578,10 +570,6 @@ class Users(object):
|
|||
else:
|
||||
thumb = row['thumb']
|
||||
|
||||
# Fake Live TV air date using added_at timestamp
|
||||
if row['live'] and not row['originally_available_at']:
|
||||
row['originally_available_at'] = helpers.timestamp_to_iso_date(row['added_at'])
|
||||
|
||||
recent_output = {'row_id': row['id'],
|
||||
'media_type': row['media_type'],
|
||||
'rating_key': row['rating_key'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue