]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/videomega.py
Update changelog.
[youtubedl] / youtube_dl / extractor / videomega.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_request
8
9
10 class VideoMegaIE(InfoExtractor):
11 _VALID_URL = r'''(?x)https?://
12 (?:www\.)?videomega\.tv/
13 (?:iframe\.php|cdn\.php)?\?ref=(?P<id>[A-Za-z0-9]+)
14 '''
15 _TEST = {
16 'url': 'http://videomega.tv/?ref=4GNA688SU99US886ANG4',
17 'md5': 'bf5c2f95c4c917536e80936af7bc51e1',
18 'info_dict': {
19 'id': '4GNA688SU99US886ANG4',
20 'ext': 'mp4',
21 'title': 'BigBuckBunny_320x180',
22 'thumbnail': 're:^https?://.*\.jpg$',
23 }
24 }
25
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28
29 iframe_url = 'http://videomega.tv/cdn.php?ref=%s' % video_id
30 req = compat_urllib_request.Request(iframe_url)
31 req.add_header('Referer', url)
32 webpage = self._download_webpage(req, video_id)
33
34 title = self._html_search_regex(
35 r'<title>(.*?)</title>', webpage, 'title')
36 title = re.sub(
37 r'(?:^[Vv]ideo[Mm]ega\.tv\s-\s?|\s?-\svideomega\.tv$)', '', title)
38 thumbnail = self._search_regex(
39 r'<video[^>]+?poster="([^"]+)"', webpage, 'thumbnail', fatal=False)
40 video_url = self._search_regex(
41 r'<source[^>]+?src="([^"]+)"', webpage, 'video URL')
42
43 return {
44 'id': video_id,
45 'title': title,
46 'url': video_url,
47 'thumbnail': thumbnail,
48 'http_headers': {
49 'Referer': iframe_url,
50 },
51 }