]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/indavideo.py
[yandexmusic] Capture and output API errors
[youtube-dl] / youtube_dl / extractor / indavideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6     int_or_none,
7     parse_age_limit,
8     parse_iso8601,
9 )
10
11
12 class IndavideoEmbedIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:(?:embed\.)?indavideo\.hu/player/video/|assets\.indavideo\.hu/swf/player\.swf\?.*\b(?:v(?:ID|id))=)(?P<id>[\da-f]+)'
14     _TESTS = [{
15         'url': 'http://indavideo.hu/player/video/1bdc3c6d80/',
16         'md5': 'f79b009c66194acacd40712a6778acfa',
17         'info_dict': {
18             'id': '1837039',
19             'ext': 'mp4',
20             'title': 'Cicatánc',
21             'description': '',
22             'thumbnail': 're:^https?://.*\.jpg$',
23             'uploader': 'cukiajanlo',
24             'uploader_id': '83729',
25             'timestamp': 1439193826,
26             'upload_date': '20150810',
27             'duration': 72,
28             'age_limit': 0,
29             'tags': ['tánc', 'cica', 'cuki', 'cukiajanlo', 'newsroom'],
30         },
31     }, {
32         'url': 'http://embed.indavideo.hu/player/video/1bdc3c6d80?autostart=1&hide=1',
33         'only_matching': True,
34     }, {
35         'url': 'http://assets.indavideo.hu/swf/player.swf?v=fe25e500&vID=1bdc3c6d80&autostart=1&hide=1&i=1',
36         'only_matching': True,
37     }]
38
39     def _real_extract(self, url):
40         video_id = self._match_id(url)
41
42         video = self._download_json(
43             'http://amfphp.indavideo.hu/SYm0json.php/player.playerHandler.getVideoData/%s' % video_id,
44             video_id)['data']
45
46         title = video['title']
47
48         video_urls = video.get('video_files', [])
49         video_file = video.get('video_file')
50         if video:
51             video_urls.append(video_file)
52         video_urls = list(set(video_urls))
53
54         video_prefix = video_urls[0].rsplit('/', 1)[0]
55
56         for flv_file in video.get('flv_files', []):
57             flv_url = '%s/%s' % (video_prefix, flv_file)
58             if flv_url not in video_urls:
59                 video_urls.append(flv_url)
60
61         formats = [{
62             'url': video_url,
63             'height': self._search_regex(r'\.(\d{3,4})\.mp4$', video_url, 'height', default=None),
64         } for video_url in video_urls]
65         self._sort_formats(formats)
66
67         timestamp = video.get('date')
68         if timestamp:
69             # upload date is in CEST
70             timestamp = parse_iso8601(timestamp + ' +0200', ' ')
71
72         thumbnails = [{
73             'url': self._proto_relative_url(thumbnail)
74         } for thumbnail in video.get('thumbnails', [])]
75
76         tags = [tag['title'] for tag in video.get('tags') or []]
77
78         return {
79             'id': video.get('id') or video_id,
80             'title': title,
81             'description': video.get('description'),
82             'thumbnails': thumbnails,
83             'uploader': video.get('user_name'),
84             'uploader_id': video.get('user_id'),
85             'timestamp': timestamp,
86             'duration': int_or_none(video.get('length')),
87             'age_limit': parse_age_limit(video.get('age_limit')),
88             'tags': tags,
89             'formats': formats,
90         }
91
92
93 class IndavideoIE(InfoExtractor):
94     _VALID_URL = r'https?://(?:.+?\.)?indavideo\.hu/video/(?P<id>[^/#?]+)'
95     _TESTS = [{
96         'url': 'http://indavideo.hu/video/Vicces_cica_1',
97         'md5': '8c82244ba85d2a2310275b318eb51eac',
98         'info_dict': {
99             'id': '1335611',
100             'display_id': 'Vicces_cica_1',
101             'ext': 'mp4',
102             'title': 'Vicces cica',
103             'description': 'Játszik a tablettel. :D',
104             'thumbnail': 're:^https?://.*\.jpg$',
105             'uploader': 'Jet_Pack',
106             'uploader_id': '491217',
107             'timestamp': 1390821212,
108             'upload_date': '20140127',
109             'duration': 7,
110             'age_limit': 0,
111             'tags': ['vicces', 'macska', 'cica', 'ügyes', 'nevetés', 'játszik', 'Cukiság', 'Jet_Pack'],
112         },
113     }, {
114         'url': 'http://index.indavideo.hu/video/2015_0728_beregszasz',
115         'only_matching': True,
116     }, {
117         'url': 'http://auto.indavideo.hu/video/Sajat_utanfutoban_a_kis_tacsko',
118         'only_matching': True,
119     }, {
120         'url': 'http://erotika.indavideo.hu/video/Amator_tini_punci',
121         'only_matching': True,
122     }, {
123         'url': 'http://film.indavideo.hu/video/f_hrom_nagymamm_volt',
124         'only_matching': True,
125     }, {
126         'url': 'http://palyazat.indavideo.hu/video/Embertelen_dal_Dodgem_egyuttes',
127         'only_matching': True,
128     }]
129
130     def _real_extract(self, url):
131         display_id = self._match_id(url)
132
133         webpage = self._download_webpage(url, display_id)
134         embed_url = self._search_regex(
135             r'<link[^>]+rel="video_src"[^>]+href="(.+?)"', webpage, 'embed url')
136
137         return {
138             '_type': 'url_transparent',
139             'ie_key': 'IndavideoEmbed',
140             'url': embed_url,
141             'display_id': display_id,
142         }