]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vbox7.py
Merge remote-tracking branch 'lenaten/8tracks'
[yt-dlp.git] / youtube_dl / extractor / vbox7.py
CommitLineData
50451f2a
JMF
1# encoding: utf-8
2from __future__ import unicode_literals
3
01c10ca2 4from .common import InfoExtractor
1cc79574 5from ..compat import (
01c10ca2
PH
6 compat_urllib_parse,
7 compat_urllib_request,
1cc79574
PH
8)
9from ..utils import (
01c10ca2
PH
10 ExtractorError,
11)
12
13
14class Vbox7IE(InfoExtractor):
1cc79574 15 _VALID_URL = r'http://(?:www\.)?vbox7\.com/play:(?P<id>[^/]+)'
6f5ac90c 16 _TEST = {
50451f2a
JMF
17 'url': 'http://vbox7.com/play:249bb972c2',
18 'md5': '99f65c0c9ef9b682b97313e052734c3f',
19 'info_dict': {
20 'id': '249bb972c2',
8e6f8051 21 'ext': 'mp4',
50451f2a
JMF
22 'title': 'Смях! Чудо - чист за секунди - Скрита камера',
23 },
6f5ac90c 24 }
01c10ca2 25
50451f2a 26 def _real_extract(self, url):
1cc79574 27 video_id = self._match_id(url)
01c10ca2
PH
28
29 redirect_page, urlh = self._download_webpage_handle(url, video_id)
50451f2a 30 new_location = self._search_regex(r'window\.location = \'(.*)\';',
9e1a5b84 31 redirect_page, 'redirect location')
01c10ca2 32 redirect_url = urlh.geturl() + new_location
50451f2a 33 webpage = self._download_webpage(redirect_url, video_id,
9e1a5b84 34 'Downloading redirect page')
01c10ca2
PH
35
36 title = self._html_search_regex(r'<title>(.*)</title>',
9e1a5b84 37 webpage, 'title').split('/')[0].strip()
01c10ca2 38
01c10ca2 39 info_url = "http://vbox7.com/play/magare.do"
50451f2a 40 data = compat_urllib_parse.urlencode({'as3': '1', 'vid': video_id})
01c10ca2
PH
41 info_request = compat_urllib_request.Request(info_url, data)
42 info_request.add_header('Content-Type', 'application/x-www-form-urlencoded')
50451f2a 43 info_response = self._download_webpage(info_request, video_id, 'Downloading info webpage')
01c10ca2 44 if info_response is None:
50451f2a 45 raise ExtractorError('Unable to extract the media url')
01c10ca2
PH
46 (final_url, thumbnail_url) = map(lambda x: x.split('=')[1], info_response.split('&'))
47
50451f2a
JMF
48 return {
49 'id': video_id,
50 'url': final_url,
50451f2a 51 'title': title,
01c10ca2 52 'thumbnail': thumbnail_url,
50451f2a 53 }