]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/fancode.py
[cleanup] Revert unnecessary changes in 51d9739f8031fb37d8e25b0e9f1abea561e3d2e3
[yt-dlp.git] / yt_dlp / extractor / fancode.py
CommitLineData
b0089e89 1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5
6from ..compat import compat_str
7from ..utils import (
8 parse_iso8601,
9 ExtractorError,
10 try_get
11)
12
13
14class FancodeVodIE(InfoExtractor):
15 IE_NAME = 'fancode:vod'
16
17 _VALID_URL = r'https?://(?:www\.)?fancode\.com/video/(?P<id>[0-9]+)\b'
18
19 _TESTS = [{
20 'url': 'https://fancode.com/video/15043/match-preview-pbks-vs-mi',
21 'params': {
22 'skip_download': True,
23 'format': 'bestvideo'
24 },
25 'info_dict': {
26 'id': '6249806281001',
27 'ext': 'mp4',
28 'title': 'Match Preview: PBKS vs MI',
29 'thumbnail': r're:^https?://.*\.jpg$',
30 "timestamp": 1619081590,
31 'view_count': int,
32 'like_count': int,
33 'upload_date': '20210422',
34 'uploader_id': '6008340455001'
35 }
36 }, {
37 'url': 'https://fancode.com/video/15043',
38 'only_matching': True,
39 }]
40
41 def _real_extract(self, url):
42
43 BRIGHTCOVE_URL_TEMPLATE = 'https://players.brightcove.net/%s/default_default/index.html?videoId=%s'
44
45 video_id = self._match_id(url)
46 webpage = self._download_webpage(url, video_id)
47 brightcove_user_id = self._html_search_regex(
48 r'(?:https?://)?players\.brightcove\.net/(\d+)/default_default/index(?:\.min)?\.js',
49 webpage, 'user id')
50
51 data = '''{
52 "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 }}",
53 "variables":{
54 "id":%s,
55 "filter":{
56 "contentDataType":"DEFAULT"
57 }
58 },
59 "operationName":"Video"
60 }''' % video_id
61
62 metadata_json = self._download_json(
63 'https://www.fancode.com/graphql', video_id, data=data.encode(), note='Downloading metadata',
64 headers={
65 'content-type': 'application/json',
66 'origin': 'https://fancode.com',
67 'referer': url,
68 })
69
70 media = try_get(metadata_json, lambda x: x['data']['media'], dict) or {}
71 brightcove_video_id = try_get(media, lambda x: x['mediaSource']['brightcove'], compat_str)
72
73 if brightcove_video_id is None:
74 raise ExtractorError('Unable to extract brightcove Video ID')
75
76 is_premium = media.get('isPremium')
77 if is_premium:
78 self.report_warning('this video requires a premium account', video_id)
79
80 return {
81 '_type': 'url_transparent',
82 'url': BRIGHTCOVE_URL_TEMPLATE % (brightcove_user_id, brightcove_video_id),
83 'ie_key': 'BrightcoveNew',
84 'id': video_id,
85 'title': media['title'],
86 'like_count': media.get('totalUpvotes'),
87 'view_count': media.get('totalViews'),
88 'tags': media.get('tags'),
89 'release_timestamp': parse_iso8601(media.get('publishedTime')),
90 'availability': self._availability(needs_premium=is_premium),
91 }