Merge remote-tracking branch 'xu-cheng/zsh-completion'
[youtube-dl] / youtube_dl / extractor / walla.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .subtitles import SubtitlesInfoExtractor
7 from ..utils import (
8     xpath_text,
9     int_or_none,
10 )
11
12
13 class WallaIE(SubtitlesInfoExtractor):
14     _VALID_URL = r'http://vod\.walla\.co\.il/[^/]+/(?P<id>\d+)/(?P<display_id>.+)'
15     _TEST = {
16         'url': 'http://vod.walla.co.il/movie/2642630/one-direction-all-for-one',
17         'info_dict': {
18             'id': '2642630',
19             'display_id': 'one-direction-all-for-one',
20             'ext': 'flv',
21             'title': 'וואן דיירקשן: ההיסטריה',
22             'description': 'md5:de9e2512a92442574cdb0913c49bc4d8',
23             'thumbnail': 're:^https?://.*\.jpg',
24             'duration': 3600,
25         },
26         'params': {
27             # rtmp download
28             'skip_download': True,
29         }
30     }
31
32     _SUBTITLE_LANGS = {
33         'עברית': 'heb',
34     }
35
36     def _real_extract(self, url):
37         mobj = re.match(self._VALID_URL, url)
38         video_id = mobj.group('id')
39         display_id = mobj.group('display_id')
40
41         video = self._download_xml(
42             'http://video2.walla.co.il/?w=null/null/%s/@@/video/flv_pl' % video_id,
43             display_id)
44
45         item = video.find('./items/item')
46
47         title = xpath_text(item, './title', 'title')
48         description = xpath_text(item, './synopsis', 'description')
49         thumbnail = xpath_text(item, './preview_pic', 'thumbnail')
50         duration = int_or_none(xpath_text(item, './duration', 'duration'))
51
52         subtitles = {}
53         for subtitle in item.findall('./subtitles/subtitle'):
54             lang = xpath_text(subtitle, './title')
55             subtitles[self._SUBTITLE_LANGS.get(lang, lang)] = xpath_text(subtitle, './src')
56
57         if self._downloader.params.get('listsubtitles', False):
58             self._list_available_subtitles(video_id, subtitles)
59             return
60
61         subtitles = self.extract_subtitles(video_id, subtitles)
62
63         formats = []
64         for quality in item.findall('./qualities/quality'):
65             format_id = xpath_text(quality, './title')
66             fmt = {
67                 'url': 'rtmp://wafla.walla.co.il/vod',
68                 'play_path': xpath_text(quality, './src'),
69                 'player_url': 'http://isc.walla.co.il/w9/swf/video_swf/vod/WallaMediaPlayerAvod.swf',
70                 'page_url': url,
71                 'ext': 'flv',
72                 'format_id': xpath_text(quality, './title'),
73             }
74             m = re.search(r'^(?P<height>\d+)[Pp]', format_id)
75             if m:
76                 fmt['height'] = int(m.group('height'))
77             formats.append(fmt)
78         self._sort_formats(formats)
79
80         return {
81             'id': video_id,
82             'display_id': display_id,
83             'title': title,
84             'description': description,
85             'thumbnail': thumbnail,
86             'duration': duration,
87             'formats': formats,
88             'subtitles': subtitles,
89         }