From c5370857b3075bd5719b59d8e493dda8bea15e24 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 11 Jul 2021 07:06:26 -0400 Subject: [PATCH] [BravoTV] Improve metadata extraction (#483) Authored by: kevinoconnor7 --- yt_dlp/extractor/bravotv.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/yt_dlp/extractor/bravotv.py b/yt_dlp/extractor/bravotv.py index bae2aedce..e4758baca 100644 --- a/yt_dlp/extractor/bravotv.py +++ b/yt_dlp/extractor/bravotv.py @@ -8,6 +8,9 @@ smuggle_url, update_url_query, int_or_none, + float_or_none, + try_get, + dict_get, ) @@ -24,6 +27,11 @@ class BravoTVIE(AdobePassIE): 'uploader': 'NBCU-BRAV', 'upload_date': '20190314', 'timestamp': 1552591860, + 'season_number': 16, + 'episode_number': 15, + 'series': 'Top Chef', + 'episode': 'The Top Chef Season 16 Winner Is...', + 'duration': 190.0, } }, { 'url': 'http://www.bravotv.com/below-deck/season-3/ep-14-reunion-part-1', @@ -79,12 +87,34 @@ def _real_extract(self, url): 'episode_number': int_or_none(metadata.get('episode_num')), }) query['switch'] = 'progressive' + + tp_url = 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path) + + tp_metadata = self._download_json( + update_url_query(tp_url, {'format': 'preview'}), + display_id, fatal=False) + if tp_metadata: + info.update({ + 'title': tp_metadata.get('title'), + 'description': tp_metadata.get('description'), + 'duration': float_or_none(tp_metadata.get('duration'), 1000), + 'season_number': int_or_none( + dict_get(tp_metadata, ('pl1$seasonNumber', 'nbcu$seasonNumber'))), + 'episode_number': int_or_none( + dict_get(tp_metadata, ('pl1$episodeNumber', 'nbcu$episodeNumber'))), + # For some reason the series is sometimes wrapped into a single element array. + 'series': try_get( + dict_get(tp_metadata, ('pl1$show', 'nbcu$show')), + lambda x: x[0] if isinstance(x, list) else x, + expected_type=str), + 'episode': dict_get( + tp_metadata, ('pl1$episodeName', 'nbcu$episodeName', 'title')), + }) + info.update({ '_type': 'url_transparent', 'id': release_pid, - 'url': smuggle_url(update_url_query( - 'http://link.theplatform.com/s/%s/%s' % (account_pid, tp_path), - query), {'force_smil_url': True}), + 'url': smuggle_url(update_url_query(tp_url, query), {'force_smil_url': True}), 'ie_key': 'ThePlatform', }) return info