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