]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/videomega.py
[ssa] Add extractor (Closes #5169)
[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
1cc79574 7from ..compat import (
67abbe95 8 compat_urllib_parse,
a45c0a5d 9 compat_urllib_request,
1cc79574
PH
10)
11from ..utils import (
bb6e3878 12 ExtractorError,
67abbe95
NJ
13 remove_start,
14)
15
16
17class VideoMegaIE(InfoExtractor):
18 _VALID_URL = r'''(?x)https?://
19 (?:www\.)?videomega\.tv/
20 (?:iframe\.php)?\?ref=(?P<id>[A-Za-z0-9]+)
21 '''
22 _TEST = {
a45c0a5d
NJ
23 'url': 'http://videomega.tv/?ref=QR0HCUHI1661IHUCH0RQ',
24 'md5': 'bf5c2f95c4c917536e80936af7bc51e1',
67abbe95 25 'info_dict': {
a45c0a5d 26 'id': 'QR0HCUHI1661IHUCH0RQ',
67abbe95 27 'ext': 'mp4',
a45c0a5d 28 'title': 'Big Buck Bunny',
67abbe95
NJ
29 'thumbnail': 're:^https?://.*\.jpg$',
30 }
31 }
32
33 def _real_extract(self, url):
1cc79574 34 video_id = self._match_id(url)
a45c0a5d
NJ
35
36 iframe_url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id)
37 req = compat_urllib_request.Request(iframe_url)
38 req.add_header('Referer', url)
39 webpage = self._download_webpage(req, video_id)
67abbe95 40
bb6e3878
NJ
41 try:
42 escaped_data = re.findall(r'unescape\("([^"]+)"\)', webpage)[-1]
43 except IndexError:
44 raise ExtractorError('Unable to extract escaped data')
45
67abbe95
NJ
46 playlist = compat_urllib_parse.unquote(escaped_data)
47
48 thumbnail = self._search_regex(
49 r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False)
a45c0a5d 50 video_url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL')
0e59b9ff
PH
51 title = remove_start(self._html_search_regex(
52 r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ')
67abbe95 53
0e59b9ff 54 formats = [{
67abbe95 55 'format_id': 'sd',
a45c0a5d 56 'url': video_url,
0e59b9ff
PH
57 }]
58 self._sort_formats(formats)
67abbe95
NJ
59
60 return {
61 'id': video_id,
62 'title': title,
63 'formats': formats,
64 'thumbnail': thumbnail,
e1554a40
JMF
65 'http_headers': {
66 'Referer': iframe_url,
67 },
67abbe95 68 }