1 from .common
import InfoExtractor
3 from ..compat
import compat_str
12 class FancodeVodIE(InfoExtractor
):
13 IE_NAME
= 'fancode:vod'
15 _VALID_URL
= r
'https?://(?:www\.)?fancode\.com/video/(?P<id>[0-9]+)\b'
18 'url': 'https://fancode.com/video/15043/match-preview-pbks-vs-mi',
20 'skip_download': True,
23 'id': '6249806281001',
25 'title': 'Match Preview: PBKS vs MI',
26 'thumbnail': r
're:^https?://.*\.jpg$',
27 "timestamp": 1619081590,
30 'upload_date': '20210422',
31 'uploader_id': '6008340455001'
34 'url': 'https://fancode.com/video/15043',
35 'only_matching': True,
39 _NETRC_MACHINE
= 'fancode'
41 _LOGIN_HINT
= 'Use "--username refresh --password <refresh_token>" to login using a refresh token'
44 'content-type': 'application/json',
45 'origin': 'https://fancode.com',
46 'referer': 'https://fancode.com',
49 def _perform_login(self
, username
, password
):
50 # Access tokens are shortlived, so get them using the refresh token.
51 if username
!= 'refresh':
52 self
.report_warning(f
'Login using username and password is not currently supported. {self._LOGIN_HINT}')
56 "query":"mutation RefreshToken($refreshToken: String\\u0021) { refreshToken(refreshToken: $refreshToken) { accessToken }}",
60 "operationName":"RefreshToken"
63 token_json
= self
.download_gql('refresh token', data
, "Getting the Access token")
64 self
._ACCESS
_TOKEN
= try_get(token_json
, lambda x
: x
['data']['refreshToken']['accessToken'])
65 if self
._ACCESS
_TOKEN
is None:
66 self
.report_warning('Failed to get Access token')
68 self
.headers
.update({'Authorization': 'Bearer %s' % self._ACCESS_TOKEN}
)
70 def _check_login_required(self
, is_available
, is_premium
):
72 if is_premium
and self
._ACCESS
_TOKEN
is None:
73 msg
= f
'This video is only available for registered users. {self._LOGIN_HINT}'
74 elif not is_available
and self
._ACCESS
_TOKEN
is not None:
75 msg
= 'This video isn\'t available to the current logged in account'
77 self
.raise_login_required(msg
, metadata_available
=True, method
=None)
79 def download_gql(self
, variable
, data
, note
, fatal
=False, headers
=headers
):
80 return self
._download
_json
(
81 'https://www.fancode.com/graphql', variable
,
82 data
=data
.encode(), note
=note
,
83 headers
=headers
, fatal
=fatal
)
85 def _real_extract(self
, url
):
87 BRIGHTCOVE_URL_TEMPLATE
= 'https://players.brightcove.net/%s/default_default/index.html?videoId=%s'
88 video_id
= self
._match
_id
(url
)
90 brightcove_user_id
= '6008340455001'
92 "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 }}",
96 "contentDataType":"DEFAULT"
99 "operationName":"Video"
102 metadata_json
= self
.download_gql(video_id
, data
, note
='Downloading metadata')
104 media
= try_get(metadata_json
, lambda x
: x
['data']['media'], dict) or {}
105 brightcove_video_id
= try_get(media
, lambda x
: x
['mediaSource']['brightcove'], compat_str
)
107 if brightcove_video_id
is None:
108 raise ExtractorError('Unable to extract brightcove Video ID')
110 is_premium
= media
.get('isPremium')
112 self
._check
_login
_required
(media
.get('isUserEntitled'), is_premium
)
115 '_type': 'url_transparent',
116 'url': BRIGHTCOVE_URL_TEMPLATE
% (brightcove_user_id
, brightcove_video_id
),
117 'ie_key': 'BrightcoveNew',
119 'title': media
['title'],
120 'like_count': media
.get('totalUpvotes'),
121 'view_count': media
.get('totalViews'),
122 'tags': media
.get('tags'),
123 'release_timestamp': parse_iso8601(media
.get('publishedTime')),
124 'availability': self
._availability
(needs_premium
=is_premium
),
128 class FancodeLiveIE(FancodeVodIE
):
129 IE_NAME
= 'fancode:live'
131 _VALID_URL
= r
'https?://(www\.)?fancode\.com/match/(?P<id>[0-9]+).+'
134 'url': 'https://fancode.com/match/35328/cricket-fancode-ecs-hungary-2021-bub-vs-blb?slug=commentary',
138 'title': 'BUB vs BLB',
139 "timestamp": 1624863600,
141 'upload_date': '20210628',
145 'url': 'https://fancode.com/match/35328/',
146 'only_matching': True,
148 'url': 'https://fancode.com/match/35567?slug=scorecard',
149 'only_matching': True,
152 def _real_extract(self
, url
):
154 id = self
._match
_id
(url
)
156 "query":"query MatchResponse($id: Int\\u0021, $isLoggedIn: Boolean\\u0021) { match: matchWithScores(id: $id) { id matchDesc mediaId videoStreamId videoStreamUrl { ...VideoSource } liveStreams { videoStreamId videoStreamUrl { ...VideoSource } contentId } name startTime streamingStatus isPremium isUserEntitled @include(if: $isLoggedIn) status metaTags bgImage { src } sport { name slug } tour { id name } squads { name shortName } liveStreams { contentId } mediaId }}fragment VideoSource on VideoSource { title description posterUrl url deliveryType playerType}",
161 "operationName":"MatchResponse"
164 info_json
= self
.download_gql(id, data
, "Info json")
166 match_info
= try_get(info_json
, lambda x
: x
['data']['match'])
168 if match_info
.get('streamingStatus') != "STARTED":
169 raise ExtractorError('The stream can\'t be accessed', expected
=True)
170 self
._check
_login
_required
(match_info
.get('isUserEntitled'), True) # all live streams are premium only
174 'title': match_info
.get('name'),
175 'formats': self
._extract
_akamai
_formats
(try_get(match_info
, lambda x
: x
['videoStreamUrl']['url']), id),
176 'ext': mimetype2ext(try_get(match_info
, lambda x
: x
['videoStreamUrl']['deliveryType'])),
178 'release_timestamp': parse_iso8601(match_info
.get('startTime'))