]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/blogger.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / blogger.py
1 from .common import InfoExtractor
2 from ..utils import (
3 mimetype2ext,
4 parse_duration,
5 parse_qs,
6 str_or_none,
7 traverse_obj,
8 )
9
10
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,
24 }
25 }]
26
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]
38
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))),
45 }