]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/twentythreevideo.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / twentythreevideo.py
1 from .common import InfoExtractor
2 from ..utils import int_or_none
3
4
5 class TwentyThreeVideoIE(InfoExtractor):
6 IE_NAME = '23video'
7 _VALID_URL = r'https?://(?P<domain>[^.]+\.(?:twentythree\.net|23video\.com|filmweb\.no))/v\.ihtml/player\.html\?(?P<query>.*?\bphoto(?:_|%5f)id=(?P<id>\d+).*)'
8 _TESTS = [{
9 'url': 'https://video.twentythree.net/v.ihtml/player.html?showDescriptions=0&source=site&photo%5fid=20448876&autoPlay=1',
10 'md5': '75fcf216303eb1dae9920d651f85ced4',
11 'info_dict': {
12 'id': '20448876',
13 'ext': 'mp4',
14 'title': 'Video Marketing Minute: Personalized Video',
15 'timestamp': 1513855354,
16 'upload_date': '20171221',
17 'uploader_id': '12258964',
18 'uploader': 'Rasmus Bysted',
19 },
20 }, {
21 'url': 'https://bonnier-publications-danmark.23video.com/v.ihtml/player.html?token=f0dc46476e06e13afd5a1f84a29e31e8&source=embed&photo%5fid=36137620',
22 'only_matching': True,
23 }]
24
25 def _real_extract(self, url):
26 domain, query, photo_id = self._match_valid_url(url).groups()
27 base_url = f'https://{domain}'
28 photo_data = self._download_json(
29 base_url + '/api/photo/list?' + query, photo_id, query={
30 'format': 'json',
31 }, transform_source=lambda s: self._search_regex(r'(?s)({.+})', s, 'photo data'))['photo']
32 title = photo_data['title']
33
34 formats = []
35
36 audio_path = photo_data.get('audio_download')
37 if audio_path:
38 formats.append({
39 'format_id': 'audio',
40 'url': base_url + audio_path,
41 'filesize': int_or_none(photo_data.get('audio_size')),
42 'vcodec': 'none',
43 })
44
45 def add_common_info_to_list(l, template, id_field, id_value):
46 f_base = template % id_value
47 f_path = photo_data.get(f_base + 'download')
48 if not f_path:
49 return
50 l.append({
51 id_field: id_value,
52 'url': base_url + f_path,
53 'width': int_or_none(photo_data.get(f_base + 'width')),
54 'height': int_or_none(photo_data.get(f_base + 'height')),
55 'filesize': int_or_none(photo_data.get(f_base + 'size')),
56 })
57
58 for f in ('mobile_high', 'medium', 'hd', '1080p', '4k'):
59 add_common_info_to_list(formats, 'video_%s_', 'format_id', f)
60
61 thumbnails = []
62 for t in ('quad16', 'quad50', 'quad75', 'quad100', 'small', 'portrait', 'standard', 'medium', 'large', 'original'):
63 add_common_info_to_list(thumbnails, '%s_', 'id', t)
64
65 return {
66 'id': photo_id,
67 'title': title,
68 'timestamp': int_or_none(photo_data.get('creation_date_epoch')),
69 'duration': int_or_none(photo_data.get('video_length')),
70 'view_count': int_or_none(photo_data.get('view_count')),
71 'comment_count': int_or_none(photo_data.get('number_of_comments')),
72 'uploader_id': photo_data.get('user_id'),
73 'uploader': photo_data.get('display_name'),
74 'thumbnails': thumbnails,
75 'formats': formats,
76 }