[walla] Add new extractor
[youtube-dl] / youtube_dl / extractor / walla.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 import re
6
7 from .common import InfoExtractor
8
9
10 class WallaIE(InfoExtractor):
11     _VALID_URL = r'http://vod\.walla\.co\.il/\w+/(?P<id>\d+)'
12     _TEST = {
13         'url': 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one',
14         'info_dict': {
15             'id': '2642630',
16             'ext': 'flv',
17             'title': 'וואן דיירקשן: ההיסטריה',
18         }
19     }
20
21     def _real_extract(self, url):
22         mobj = re.match(self._VALID_URL, url)
23         
24         video_id = mobj.group('id')
25
26         config_url = 'http://video2.walla.co.il/?w=null/null/%s/@@/video/flv_pl' % video_id
27         
28         webpage = self._download_webpage(config_url, video_id, '')
29
30         media_id = self._html_search_regex(r'<media_id>(\d+)</media_id>', webpage, video_id, 'extract media id')
31
32         prefix = '0' if len(media_id) == 7 else ''
33
34         series =  '%s%s' % (prefix, media_id[0:2])
35         session = media_id[2:5]
36         episode = media_id[5:7]
37         
38         title = self._html_search_regex(r'<title>(.*)</title>', webpage, video_id, 'title')
39
40         default_quality = self._html_search_regex(r'<qualities defaultType="(\d+)">', webpage, video_id, 0)
41
42         quality = default_quality if default_quality else '40'
43
44         media_path = '/%s/%s/%s' % (series, session, media_id) #self._html_search_regex(r'<quality type="%s">.*<src>(.*)</src>' % default_quality ,webpage, '', flags=re.DOTALL) 
45
46         playpath = 'mp4:media/%s/%s/%s-%s' % (series, session, media_id, quality) #self._html_search_regex(r'<quality type="%s">.*<src>(.*)</src>' % default_quality ,webpage, '', flags=re.DOTALL) 
47
48         subtitles = {}
49
50         subtitle_url = self._html_search_regex(r'<subtitles.*<src>(.*)</src>.*</subtitle>', webpage, video_id, 0)
51
52         print subtitle_url
53
54         if subtitle_url:
55             subtitles_page = self._download_webpage(subtitle_url, video_id, '')
56             subtitles['heb'] = subtitles_page
57
58         return {
59             'id': video_id,
60             'title': title,
61             'url': 'rtmp://wafla.walla.co.il:1935/vod',
62             'player_url': 'http://isc.walla.co.il/w9/swf/video_swf/vod/WallaMediaPlayerAvod.swf',
63             'page_url': url,
64             'app': "vod",
65             'play_path': playpath,
66             'tc_url': 'rtmp://wafla.walla.co.il:1935/vod',
67             'rtmp_protocol': 'rtmp',
68             'ext': 'flv',
69             'subtitles': subtitles,
70         }