[indavideo] Add new extractor
[youtube-dl] / youtube_dl / extractor / indavideo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .. import utils
5 from .common import InfoExtractor
6
7
8 class IndavideoIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?indavideo\.hu/video/(?P<id>.+)'
10     _TESTS = [
11         {
12             'url': 'http://indavideo.hu/video/Cicatanc',
13             'md5': 'c8a507a1c7410685f83a06eaeeaafeab',
14             'info_dict': {
15                 'id': '1837039',
16                 'title': 'Cicatánc',
17                 'ext': 'mp4',
18                 'display_id': 'Cicatanc',
19                 'thumbnail': 're:^https?://.*\.jpg$',
20                 'description': '',
21                 'uploader': 'cukiajanlo',
22                 'uploader_id': '83729',
23                 'duration': 72,
24                 'age_limit': 0,
25                 'tags': ['tánc', 'cica', 'cuki', 'cukiajanlo', 'newsroom']
26             },
27         },
28         {
29             'url': 'http://indavideo.hu/video/Vicces_cica_1',
30             'md5': '8c82244ba85d2a2310275b318eb51eac',
31             'info_dict': {
32                 'id': '1335611',
33                 'title': 'Vicces cica',
34                 'ext': 'mp4',
35                 'display_id': 'Vicces_cica_1',
36                 'thumbnail': 're:^https?://.*\.jpg$',
37                 'description': 'Játszik a tablettel. :D',
38                 'uploader': 'Jet_Pack',
39                 'uploader_id': '491217',
40                 'duration': 7,
41                 'age_limit': 0,
42                 'tags': ['vicces', 'macska', 'cica', 'ügyes', 'nevetés', 'játszik', 'Cukiság', 'Jet_Pack'],
43             },
44         },
45     ]
46
47     def _real_extract(self, url):
48         video_disp_id = self._match_id(url)
49         webpage = self._download_webpage(url, video_disp_id)
50
51         embed_url = self._html_search_regex(r'<link rel="video_src" href="(.+?)"/>', webpage, 'embed_url')
52         video_hash = embed_url.split('/')[-1]
53
54         payload = self._download_json('http://amfphp.indavideo.hu/SYm0json.php/player.playerHandler.getVideoData/' + video_hash, video_disp_id)
55         video_info = payload['data']
56
57         thumbnails = video_info.get('thumbnails')
58         if thumbnails:
59             thumbnails = [{'url': self._proto_relative_url(x)} for x in thumbnails]
60
61         tags = video_info.get('tags')
62         if tags:
63             tags = [x['title'] for x in tags]
64
65         return {
66             'id': video_info.get('id'),
67             'title': video_info['title'],
68             'url': video_info['video_file'],
69             'ext': 'mp4',
70             'display_id': video_disp_id,
71             'thumbnails': thumbnails,
72             'description': video_info.get('description'),
73             'uploader': video_info.get('user_name'),
74             # TODO: upload date (it's in CET/CEST)
75             'uploader_id': video_info.get('user_id'),
76             'duration': utils.int_or_none(video_info.get('length')),
77             'age_limit': utils.int_or_none(video_info.get('age_limit')),
78             'tags': tags,
79         }