diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 29695588..46b09776 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -1482,46 +1482,6 @@ {progress_percent} The last reported progress percent for the item. - - {container} - The media container of the original media. - - - {video_codec} - The video codec of the original media. - - - {video_bitrate} - The video bitrate of the original media. - - - {video_width} - The video width of the original media. - - - {video_height} - The video height of the original media. - - - {video_resolution} - The video resolution of the original media. - - - {video_framerate} - The video framerate of the original media. - - - {aspect_ratio} - The aspect ratio of the original media. - - - {audio_codec} - The audio codec of the original media. - - - {audio_channels} - The audio channels of the original media. - {transcode_decision} The stream transcode decisions for the media item. @@ -1589,13 +1549,53 @@ {media_type} The type of media. (movie, episode, track) + + {container} + The media container of the original media. + + + {video_codec} + The video codec of the original media. + + + {video_bitrate} + The video bitrate of the original media. + + + {video_width} + The video width of the original media. + + + {video_height} + The video height of the original media. + + + {video_resolution} + The video resolution of the original media. + + + {video_framerate} + The video framerate of the original media. + + + {aspect_ratio} + The aspect ratio of the original media. + + + {audio_codec} + The audio codec of the original media. + + + {audio_channels} + The audio channels of the original media. + {title} The full title of the item. {library_name} - The library title of the media item. + The library name of the item. {show_name} @@ -1752,6 +1752,14 @@ {trakt_url} The trakt.tv URL for the movie or TV show. + + {file} + The file path to the item. + + + {file_size} + The file size of the item. + {section_id} The unique identifier for the library. diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 2af4b255..324a5aa9 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -768,3 +768,26 @@ def build_datatables_json(kwargs, dt_columns, default_sort_col=None): "search": {"value": kwargs.pop("search", "")} } return json.dumps(json_data) + +def humanFileSize(bytes, si=False): + if str(bytes).isdigit(): + bytes = int(bytes) + else: + return bytes + + thresh = 1000 if si else 1024 + if bytes < thresh: + return str(bytes) + ' B' + + if si: + units = ('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB') + else: + units = ('KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB') + + u = -1 + + while bytes >= thresh and u < len(units): + bytes /= thresh + u += 1 + + return "{0:.1f} {1}".format(bytes, units[u]) diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index 7266f6b5..a86e1aa2 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -259,7 +259,7 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * rating_key = timeline['rating_key'] pms_connect = pmsconnect.PmsConnect() - metadata_list = pms_connect.get_metadata_details(rating_key=rating_key) + metadata_list = pms_connect.get_metadata_details(rating_key=rating_key, get_media_info=True) if metadata_list: metadata = metadata_list['metadata'] @@ -476,16 +476,6 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * 'progress_duration': view_offset, 'progress_time': arrow.get(view_offset * 60).format(duration_format), 'progress_percent': progress_percent, - 'container': session.get('container',''), - 'video_codec': session.get('video_codec',''), - 'video_bitrate': session.get('bitrate',''), - 'video_width': session.get('width',''), - 'video_height': session.get('height',''), - 'video_resolution': session.get('video_resolution',''), - 'video_framerate': session.get('video_framerate',''), - 'aspect_ratio': session.get('aspect_ratio',''), - 'audio_codec': session.get('audio_codec',''), - 'audio_channels': session.get('audio_channels',''), 'transcode_decision': transcode_decision, 'video_decision': session.get('video_decision','').title(), 'audio_decision': session.get('audio_decision','').title(), @@ -501,6 +491,16 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * 'machine_id': session.get('machine_id',''), # Metadata parameters 'media_type': metadata['media_type'], + 'container': session.get('container', metadata.get('container','')), + 'video_codec': session.get('video_codec', metadata.get('video_codec','')), + 'video_bitrate': session.get('bitrate', metadata.get('bitrate','')), + 'video_width': session.get('width', metadata.get('width','')), + 'video_height': session.get('height', metadata.get('height','')), + 'video_resolution': session.get('video_resolution', metadata.get('video_resolution','')), + 'video_framerate': session.get('video_framerate', metadata.get('video_framerate','')), + 'aspect_ratio': session.get('aspect_ratio', metadata.get('aspect_ratio','')), + 'audio_codec': session.get('audio_codec', metadata.get('audio_codec','')), + 'audio_channels': session.get('audio_channels', metadata.get('audio_channels','')), 'title': full_title, 'library_name': metadata['library_name'], 'show_name': show_name, @@ -545,6 +545,8 @@ def build_media_notify_params(notify_action=None, session=None, timeline=None, * 'themoviedb_url': metadata.get('themoviedb_url',''), 'lastfm_url': metadata.get('lastfm_url',''), 'trakt_url': metadata.get('trakt_url',''), + 'file': metadata.get('file',''), + 'file_size': helpers.humanFileSize(metadata.get('file_size','')), 'section_id': metadata['section_id'], 'rating_key': metadata['rating_key'], 'parent_rating_key': metadata['parent_rating_key'], diff --git a/plexpy/pmsconnect.py b/plexpy/pmsconnect.py index d1c37f19..e916c5f4 100644 --- a/plexpy/pmsconnect.py +++ b/plexpy/pmsconnect.py @@ -872,19 +872,21 @@ class PmsConnect(object): return None if get_media_info: - item_media = metadata_main.getElementsByTagName('Media') - for media in item_media: - media_info = {'container': helpers.get_xml_attr(media, 'container'), - 'bitrate': helpers.get_xml_attr(media, 'bitrate'), - 'video_codec': helpers.get_xml_attr(media, 'videoCodec'), - 'video_resolution': helpers.get_xml_attr(media, 'videoResolution'), - 'video_framerate': helpers.get_xml_attr(media, 'videoFrameRate'), - 'audio_codec': helpers.get_xml_attr(media, 'audioCodec'), - 'audio_channels': helpers.get_xml_attr(media, 'audioChannels'), - 'file': helpers.get_xml_attr(media.getElementsByTagName('Part')[0], 'file'), - 'file_size': helpers.get_xml_attr(media.getElementsByTagName('Part')[0], 'size'), - } - metadata.update(media_info) + item_media = metadata_main.getElementsByTagName('Media')[0] + media_info = {'container': helpers.get_xml_attr(item_media, 'container'), + 'bitrate': helpers.get_xml_attr(item_media, 'bitrate'), + 'height': helpers.get_xml_attr(item_media, 'height'), + 'width': helpers.get_xml_attr(item_media, 'width'), + 'aspect_ratio': helpers.get_xml_attr(item_media, 'aspectRatio'), + 'video_codec': helpers.get_xml_attr(item_media, 'videoCodec'), + 'video_resolution': helpers.get_xml_attr(item_media, 'videoResolution'), + 'video_framerate': helpers.get_xml_attr(item_media, 'videoFrameRate'), + 'audio_codec': helpers.get_xml_attr(item_media, 'audioCodec'), + 'audio_channels': helpers.get_xml_attr(item_media, 'audioChannels'), + 'file': helpers.get_xml_attr(item_media.getElementsByTagName('Part')[0], 'file'), + 'file_size': helpers.get_xml_attr(item_media.getElementsByTagName('Part')[0], 'size'), + } + metadata.update(media_info) return metadata_list