[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / blogger.py
blob3d6e0330429d925342434402d0d61a94a9d3d9a9
1 from ..utils import (
2 mimetype2ext,
3 parse_duration,
4 parse_qs,
5 str_or_none,
6 traverse_obj,
8 from .common import InfoExtractor
11 class BloggerIE(InfoExtractor):
12 IE_NAME = 'blogger.com'
13 _VALID_URL = r'https?://(?:www\.)?blogger\.com/video\.g\?token=(?P<id>.+)'
14 _EMBED_REGEX = [r'''<iframe[^>]+src=["'](?P<url>(?:https?:)?//(?:www\.)?blogger\.com/video\.g\?token=[^"']+)["']''']
15 _TESTS = [{
16 'url': 'https://www.blogger.com/video.g?token=AD6v5dzEe9hfcARr5Hlq1WTkYy6t-fXH3BBahVhGvVHe5szdEUBEloSEDSTA8-b111089KbfWuBvTN7fnbxMtymsHhXAXwVvyzHH4Qch2cfLQdGxKQrrEuFpC1amSl_9GuLWODjPgw',
17 'md5': 'f1bc19b6ea1b0fd1d81e84ca9ec467ac',
18 'info_dict': {
19 'id': 'BLOGGER-video-3c740e3a49197e16-796',
20 'title': 'BLOGGER-video-3c740e3a49197e16-796',
21 'ext': 'mp4',
22 'thumbnail': r're:^https?://.*',
23 'duration': 76.068,
27 def _real_extract(self, url):
28 token_id = self._match_id(url)
29 webpage = self._download_webpage(url, token_id)
30 data_json = self._search_regex(r'var\s+VIDEO_CONFIG\s*=\s*(\{.*)', webpage, 'JSON data')
31 data = self._parse_json(data_json.encode('utf-8').decode('unicode_escape'), token_id)
32 streams = data['streams']
33 formats = [{
34 'ext': mimetype2ext(traverse_obj(parse_qs(stream['play_url']), ('mime', 0))),
35 'url': stream['play_url'],
36 'format_id': str_or_none(stream.get('format_id')),
37 } for stream in streams]
39 return {
40 'id': data.get('iframe_id', token_id),
41 'title': data.get('iframe_id', token_id),
42 'formats': formats,
43 'thumbnail': data.get('thumbnail'),
44 'duration': parse_duration(traverse_obj(parse_qs(streams[0]['play_url']), ('dur', 0))),