From 2559d457d722c50efdad81b8168086bb18b4d749 Mon Sep 17 00:00:00 2001 From: zenerdi0de Date: Sat, 1 Oct 2022 01:11:25 +0530 Subject: [PATCH 1/2] [Fancode] fix video extraction, regex --- yt_dlp/extractor/fancode.py | 41 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/yt_dlp/extractor/fancode.py b/yt_dlp/extractor/fancode.py index 9716e581a..d1c3e0c4e 100644 --- a/yt_dlp/extractor/fancode.py +++ b/yt_dlp/extractor/fancode.py @@ -12,7 +12,7 @@ from ..utils import ( class FancodeVodIE(InfoExtractor): IE_NAME = 'fancode:vod' - _VALID_URL = r'https?://(?:www\.)?fancode\.com/video/(?P[0-9]+)\b' + _VALID_URL = r'https?://(?:www\.)?fancode\.com(?:/[a-zA-Z0-9].*)?/videos?/(?:(?:[^/])*?/)?(?P[0-9]+)\b' _TESTS = [{ 'url': 'https://fancode.com/video/15043/match-preview-pbks-vs-mi', @@ -33,6 +33,21 @@ class FancodeVodIE(InfoExtractor): }, { 'url': 'https://fancode.com/video/15043', 'only_matching': True, + }, { + 'url': 'https://www.fancode.com/cricket/videos/thriller-india-fightback-to-clinch-2wicket-win/35441', + 'params': { + 'skip_download': True, + }, + 'info_dict': { + 'id': '35441', + 'ext': 'mp4', + 'title': 'Thriller! India fightback to clinch 2-wicket win', + 'thumbnail': r're:^https?://.*\.jpg$', + "timestamp": 1619081590, + 'view_count': int, + 'like_count': int, + 'release_timestamp': 1658702382 + } }] _ACCESS_TOKEN = None @@ -89,7 +104,7 @@ class FancodeVodIE(InfoExtractor): brightcove_user_id = '6008340455001' data = '''{ - "query":"query Video($id: Int\\u0021, $filter: SegmentFilter) { media(id: $id, filter: $filter) { id contentId title contentId publishedTime totalViews totalUpvotes provider thumbnail { src } mediaSource {brightcove } duration isPremium isUserEntitled tags duration }}", + "query":"query Video($id: Int\\u0021, $filter: SegmentFilter) { media(id: $id, filter: $filter) { id contentId title contentId publishedTime totalViews totalUpvotes provider thumbnail { src } mediaSource {brightcove } duration isPremium source {url} isUserEntitled tags duration }}", "variables":{ "id":%s, "filter":{ @@ -102,19 +117,17 @@ class FancodeVodIE(InfoExtractor): metadata_json = self.download_gql(video_id, data, note='Downloading metadata') media = try_get(metadata_json, lambda x: x['data']['media'], dict) or {} + source_url = try_get(media, lambda x: x['source']['url']) brightcove_video_id = try_get(media, lambda x: x['mediaSource']['brightcove'], compat_str) - if brightcove_video_id is None: - raise ExtractorError('Unable to extract brightcove Video ID') + if not brightcove_video_id and not source_url: + raise ExtractorError('Unable to extract Video URL') is_premium = media.get('isPremium') self._check_login_required(media.get('isUserEntitled'), is_premium) - return { - '_type': 'url_transparent', - 'url': BRIGHTCOVE_URL_TEMPLATE % (brightcove_user_id, brightcove_video_id), - 'ie_key': 'BrightcoveNew', + result = { 'id': video_id, 'title': media['title'], 'like_count': media.get('totalUpvotes'), @@ -124,6 +137,18 @@ class FancodeVodIE(InfoExtractor): 'availability': self._availability(needs_premium=is_premium), } + if brightcove_video_id: + result.update({ + '_type': 'url_transparent', + 'url': BRIGHTCOVE_URL_TEMPLATE % (brightcove_user_id, brightcove_video_id), + 'ie_key': 'BrightcoveNew' + }) + + else: + result['formats'] = self._extract_m3u8_formats(source_url, video_id) + + return result + class FancodeLiveIE(FancodeVodIE): IE_NAME = 'fancode:live' From b1198e898971f3029366df681b879a3580e5ca20 Mon Sep 17 00:00:00 2001 From: zenerdi0de Date: Sat, 1 Oct 2022 01:36:55 +0530 Subject: [PATCH 2/2] tests --- yt_dlp/extractor/fancode.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/yt_dlp/extractor/fancode.py b/yt_dlp/extractor/fancode.py index d1c3e0c4e..f6ee3d2c0 100644 --- a/yt_dlp/extractor/fancode.py +++ b/yt_dlp/extractor/fancode.py @@ -16,20 +16,7 @@ class FancodeVodIE(InfoExtractor): _TESTS = [{ 'url': 'https://fancode.com/video/15043/match-preview-pbks-vs-mi', - 'params': { - 'skip_download': True, - }, - 'info_dict': { - 'id': '6249806281001', - 'ext': 'mp4', - 'title': 'Match Preview: PBKS vs MI', - 'thumbnail': r're:^https?://.*\.jpg$', - "timestamp": 1619081590, - 'view_count': int, - 'like_count': int, - 'upload_date': '20210422', - 'uploader_id': '6008340455001' - } + 'only_matching': True }, { 'url': 'https://fancode.com/video/15043', 'only_matching': True, @@ -42,11 +29,11 @@ class FancodeVodIE(InfoExtractor): 'id': '35441', 'ext': 'mp4', 'title': 'Thriller! India fightback to clinch 2-wicket win', - 'thumbnail': r're:^https?://.*\.jpg$', - "timestamp": 1619081590, 'view_count': int, 'like_count': int, - 'release_timestamp': 1658702382 + 'release_timestamp': 1658702382, + 'tags': list, + 'release_date': '20220724' } }]