]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/nowvideo.py
Merge pull request #2005 from dstftw/ivi.ru
[youtube-dl] / youtube_dl / extractor / nowvideo.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import compat_urlparse
5
6
7 class NowVideoIE(InfoExtractor):
8     _VALID_URL = r'(?:https?://)?(?:www\.)?nowvideo\.ch/video/(?P<id>\w+)'
9     _TEST = {
10         u'url': u'http://www.nowvideo.ch/video/0mw0yow7b6dxa',
11         u'file': u'0mw0yow7b6dxa.flv',
12         u'md5': u'f8fbbc8add72bd95b7850c6a02fc8817',
13         u'info_dict': {
14             u"title": u"youtubedl test video _BaW_jenozKc.mp4"
15         }
16     }
17
18     def _real_extract(self, url):
19         mobj = re.match(self._VALID_URL, url)
20
21         video_id = mobj.group('id')
22         webpage_url = 'http://www.nowvideo.ch/video/' + video_id
23         embed_url = 'http://embed.nowvideo.ch/embed.php?v=' + video_id
24         webpage = self._download_webpage(webpage_url, video_id)
25         embed_page = self._download_webpage(embed_url, video_id,
26             u'Downloading embed page')
27
28         self.report_extraction(video_id)
29
30         video_title = self._html_search_regex(r'<h4>(.*)</h4>',
31             webpage, u'video title')
32
33         video_key = self._search_regex(r'var fkzd="(.*)";',
34             embed_page, u'video key')
35
36         api_call = "http://www.nowvideo.ch/api/player.api.php?file={0}&numOfErrors=0&cid=1&key={1}".format(video_id, video_key)
37         api_response = self._download_webpage(api_call, video_id,
38             u'Downloading API page')
39         video_url = compat_urlparse.parse_qs(api_response)[u'url'][0]
40
41         return [{
42             'id':        video_id,
43             'url':       video_url,
44             'ext':       'flv',
45             'title':     video_title,
46         }]