]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vbox7.py
2f3ce46e86a880fa5058c6ebcb2fce28ad913c82
[youtubedl] / youtube_dl / extractor / vbox7.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 compat_urllib_parse,
6 compat_urllib_request,
7
8 ExtractorError,
9 )
10
11
12 class Vbox7IE(InfoExtractor):
13 """Information Extractor for Vbox7"""
14 _VALID_URL = r'(?:http://)?(?:www\.)?vbox7\.com/play:([^/]+)'
15
16 def _real_extract(self,url):
17 mobj = re.match(self._VALID_URL, url)
18 if mobj is None:
19 raise ExtractorError(u'Invalid URL: %s' % url)
20 video_id = mobj.group(1)
21
22 redirect_page, urlh = self._download_webpage_handle(url, video_id)
23 new_location = self._search_regex(r'window\.location = \'(.*)\';', redirect_page, u'redirect location')
24 redirect_url = urlh.geturl() + new_location
25 webpage = self._download_webpage(redirect_url, video_id, u'Downloading redirect page')
26
27 title = self._html_search_regex(r'<title>(.*)</title>',
28 webpage, u'title').split('/')[0].strip()
29
30 ext = "flv"
31 info_url = "http://vbox7.com/play/magare.do"
32 data = compat_urllib_parse.urlencode({'as3':'1','vid':video_id})
33 info_request = compat_urllib_request.Request(info_url, data)
34 info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
35 info_response = self._download_webpage(info_request, video_id, u'Downloading info webpage')
36 if info_response is None:
37 raise ExtractorError(u'Unable to extract the media url')
38 (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
39
40 return [{
41 'id': video_id,
42 'url': final_url,
43 'ext': ext,
44 'title': title,
45 'thumbnail': thumbnail_url,
46 }]