]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/videomega.py
[openfilm] Use compat_urllib_parse_unquote_plus
[yt-dlp.git] / youtube_dl / extractor / videomega.py
CommitLineData
67abbe95
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
bb6e3878
NJ
4import re
5
67abbe95 6from .common import InfoExtractor
eecc0685 7from ..compat import compat_urllib_request
67abbe95
NJ
8
9
10class VideoMegaIE(InfoExtractor):
11 _VALID_URL = r'''(?x)https?://
12 (?:www\.)?videomega\.tv/
eecc0685 13 (?:iframe\.php|cdn\.php)?\?ref=(?P<id>[A-Za-z0-9]+)
67abbe95
NJ
14 '''
15 _TEST = {
eecc0685 16 'url': 'http://videomega.tv/?ref=4GNA688SU99US886ANG4',
a45c0a5d 17 'md5': 'bf5c2f95c4c917536e80936af7bc51e1',
67abbe95 18 'info_dict': {
eecc0685 19 'id': '4GNA688SU99US886ANG4',
67abbe95 20 'ext': 'mp4',
eecc0685 21 'title': 'BigBuckBunny_320x180',
67abbe95
NJ
22 'thumbnail': 're:^https?://.*\.jpg$',
23 }
24 }
25
26 def _real_extract(self, url):
1cc79574 27 video_id = self._match_id(url)
a45c0a5d 28
eecc0685 29 iframe_url = 'http://videomega.tv/cdn.php?ref=%s' % video_id
a45c0a5d
NJ
30 req = compat_urllib_request.Request(iframe_url)
31 req.add_header('Referer', url)
32 webpage = self._download_webpage(req, video_id)
67abbe95 33
eecc0685
NJ
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)
67abbe95 38 thumbnail = self._search_regex(
eecc0685
NJ
39 r'<video[^>]+?poster="([^"]+)"', webpage, 'thumbnail', fatal=False)
40 video_url = self._search_regex(
41 r'<source[^>]+?src="([^"]+)"', webpage, 'video URL')
67abbe95
NJ
42
43 return {
44 'id': video_id,
45 'title': title,
eecc0685 46 'url': video_url,
67abbe95 47 'thumbnail': thumbnail,
e1554a40
JMF
48 'http_headers': {
49 'Referer': iframe_url,
50 },
67abbe95 51 }