From e7be5ab89209d042b9243ea3fb8140111ab1cd42 Mon Sep 17 00:00:00 2001 From: mimvahedi <61986916+mimvahedi@users.noreply.github.com> Date: Sat, 11 Nov 2023 18:46:49 +0330 Subject: [PATCH 1/5] [telewebion] fix extraction --- youtube_dl/extractor/telewebion.py | 35 +++++++++++++----------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/youtube_dl/extractor/telewebion.py b/youtube_dl/extractor/telewebion.py index 1207b1a1b8c..18c91436a9d 100644 --- a/youtube_dl/extractor/telewebion.py +++ b/youtube_dl/extractor/telewebion.py @@ -5,15 +5,15 @@ class TelewebionIE(InfoExtractor): - _VALID_URL = r'https?://(?:www\.)?telewebion\.com/#!/episode/(?P\d+)' + _VALID_URL = r'https?://(?:www\.)?telewebion\.com/(episode|clip)/(?P[a-zA-Z0-9]+)' _TEST = { - 'url': 'http://www.telewebion.com/#!/episode/1263668/', + 'url': 'http://www.telewebion.com/episode/0x1b3139c/', 'info_dict': { - 'id': '1263668', + 'id': '0x1b3139c', 'ext': 'mp4', 'title': 'قرعه\u200cکشی لیگ قهرمانان اروپا', - 'thumbnail': r're:^https?://.*\.jpg', + 'thumbnail': r're:^https?://static.telewebion.com/episodeImages/.*/default', 'view_count': int, }, 'params': { @@ -25,31 +25,26 @@ class TelewebionIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - secure_token = self._download_webpage( - 'http://m.s2.telewebion.com/op/op?action=getSecurityToken', video_id) - episode_details = self._download_json( - 'http://m.s2.telewebion.com/op/op', video_id, - query={'action': 'getEpisodeDetails', 'episode_id': video_id}) + episode_details = self._download_json('https://gateway.telewebion.ir/kandoo/episode/getEpisodeDetail/?EpisodeId={}'.format(video_id), video_id) + episode_details = episode_details["body"]["queryEpisode"][0] - m3u8_url = 'http://m.s1.telewebion.com/smil/%s.m3u8?filepath=%s&m3u8=1&secure_token=%s' % ( - video_id, episode_details['file_path'], secure_token) + channel_id = episode_details["channel"]["descriptor"] + episode_image_id = episode_details.get("image") + episode_image = "https://static.telewebion.com/episodeImages/{}/default".format(episode_image_id) + + m3u8_url = 'https://cdna.telewebion.com/{channel_id}/episode/{video_id}/playlist.m3u8'.format(channel_id=channel_id, video_id=video_id) formats = self._extract_m3u8_formats( m3u8_url, video_id, ext='mp4', m3u8_id='hls') - picture_paths = [ - episode_details.get('picture_path'), - episode_details.get('large_picture_path'), - ] - thumbnails = [{ - 'url': picture_path, - 'preference': idx, - } for idx, picture_path in enumerate(picture_paths) if picture_path is not None] + 'url': episode_image, + }] return { 'id': video_id, - 'title': episode_details['title'], + 'title': episode_details.get('title'), 'formats': formats, 'thumbnails': thumbnails, 'view_count': episode_details.get('view_count'), + 'duration': episode_details.get('duration') } From 25afca63c47a0ed566c8695498971e6a9b50bfc1 Mon Sep 17 00:00:00 2001 From: mimvahedi <61986916+mimvahedi@users.noreply.github.com> Date: Mon, 27 Nov 2023 17:47:05 +0330 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: dirkf --- youtube_dl/extractor/telewebion.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/youtube_dl/extractor/telewebion.py b/youtube_dl/extractor/telewebion.py index 18c91436a9d..d64af08770b 100644 --- a/youtube_dl/extractor/telewebion.py +++ b/youtube_dl/extractor/telewebion.py @@ -13,7 +13,7 @@ class TelewebionIE(InfoExtractor): 'id': '0x1b3139c', 'ext': 'mp4', 'title': 'قرعه\u200cکشی لیگ قهرمانان اروپا', - 'thumbnail': r're:^https?://static.telewebion.com/episodeImages/.*/default', + 'thumbnail': r're:^https?://static\.telewebion\.com/episodeImages/.*/default', 'view_count': int, }, 'params': { @@ -25,14 +25,14 @@ class TelewebionIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - episode_details = self._download_json('https://gateway.telewebion.ir/kandoo/episode/getEpisodeDetail/?EpisodeId={}'.format(video_id), video_id) - episode_details = episode_details["body"]["queryEpisode"][0] + episode_details = self._download_json('https://gateway.telewebion.ir/kandoo/episode/getEpisodeDetail/?EpisodeId={0}'.format(video_id), video_id) + episode_details = episode_details['body']['queryEpisode'][0] - channel_id = episode_details["channel"]["descriptor"] - episode_image_id = episode_details.get("image") - episode_image = "https://static.telewebion.com/episodeImages/{}/default".format(episode_image_id) + channel_id = episode_details['channel']['descriptor'] + episode_image_id = episode_details.get('image') + episode_image = 'https://static.telewebion.com/episodeImages/{0}/default'.format(episode_image_id) if episode_image_id else None - m3u8_url = 'https://cdna.telewebion.com/{channel_id}/episode/{video_id}/playlist.m3u8'.format(channel_id=channel_id, video_id=video_id) + m3u8_url = 'https://cdna.telewebion.com/{0}/episode/{1}/playlist.m3u8'.format(channel_id, video_id) formats = self._extract_m3u8_formats( m3u8_url, video_id, ext='mp4', m3u8_id='hls') @@ -45,6 +45,6 @@ def _real_extract(self, url): 'title': episode_details.get('title'), 'formats': formats, 'thumbnails': thumbnails, - 'view_count': episode_details.get('view_count'), - 'duration': episode_details.get('duration') + 'view_count': int_or_none(episode_details.get('view_count')), + 'duration': float_or_none(episode_details.get('duration')), } From 9a039c174f678e5438f2f2f3080720cf772d1cde Mon Sep 17 00:00:00 2001 From: mimvahedi Date: Mon, 27 Nov 2023 18:40:28 +0330 Subject: [PATCH 3/5] Apply suggestions --- youtube_dl/extractor/telewebion.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/telewebion.py b/youtube_dl/extractor/telewebion.py index d64af08770b..1965973510d 100644 --- a/youtube_dl/extractor/telewebion.py +++ b/youtube_dl/extractor/telewebion.py @@ -3,6 +3,12 @@ from .common import InfoExtractor +from ..utils import ( + float_or_none, + int_or_none, + url_or_none, +) + class TelewebionIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?telewebion\.com/(episode|clip)/(?P[a-zA-Z0-9]+)' @@ -36,15 +42,11 @@ def _real_extract(self, url): formats = self._extract_m3u8_formats( m3u8_url, video_id, ext='mp4', m3u8_id='hls') - thumbnails = [{ - 'url': episode_image, - }] - return { 'id': video_id, - 'title': episode_details.get('title'), + 'title': episode_details['title'], 'formats': formats, - 'thumbnails': thumbnails, + 'thumbnail': url_or_none(episode_image), 'view_count': int_or_none(episode_details.get('view_count')), 'duration': float_or_none(episode_details.get('duration')), } From 11e1e1747da9ecdb482eb606ef6cf0730db51676 Mon Sep 17 00:00:00 2001 From: dirkf Date: Sat, 2 Dec 2023 13:04:49 +0000 Subject: [PATCH 4/5] Use native M3U8 downloader --- youtube_dl/extractor/telewebion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/telewebion.py b/youtube_dl/extractor/telewebion.py index 1965973510d..a7380db69e0 100644 --- a/youtube_dl/extractor/telewebion.py +++ b/youtube_dl/extractor/telewebion.py @@ -40,7 +40,8 @@ def _real_extract(self, url): m3u8_url = 'https://cdna.telewebion.com/{0}/episode/{1}/playlist.m3u8'.format(channel_id, video_id) formats = self._extract_m3u8_formats( - m3u8_url, video_id, ext='mp4', m3u8_id='hls') + m3u8_url, video_id, ext='mp4', m3u8_id='hls', + entry_protocol='m3u8_native') return { 'id': video_id, From 1fcdc82b922ed342fa70348bb3a5270bd88e4a14 Mon Sep 17 00:00:00 2001 From: dirkf Date: Sat, 2 Dec 2023 14:53:36 +0000 Subject: [PATCH 5/5] Sort formats! --- youtube_dl/extractor/telewebion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/youtube_dl/extractor/telewebion.py b/youtube_dl/extractor/telewebion.py index a7380db69e0..30192d74e17 100644 --- a/youtube_dl/extractor/telewebion.py +++ b/youtube_dl/extractor/telewebion.py @@ -42,6 +42,7 @@ def _real_extract(self, url): formats = self._extract_m3u8_formats( m3u8_url, video_id, ext='mp4', m3u8_id='hls', entry_protocol='m3u8_native') + self._sort_formats(formats) return { 'id': video_id,