]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/videomega.py
Prepare for upload.
[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 ..utils import (
8 compat_urllib_parse,
9 remove_start,
10 )
11
12
13 class VideoMegaIE(InfoExtractor):
14 _VALID_URL = r'''(?x)https?://
15 (?:www\.)?videomega\.tv/
16 (?:iframe\.php)?\?ref=(?P<id>[A-Za-z0-9]+)
17 '''
18 _TEST = {
19 'url': 'http://videomega.tv/?ref=GKeGPVedBe',
20 'md5': '240fb5bcf9199961f48eb17839b084d6',
21 'info_dict': {
22 'id': 'GKeGPVedBe',
23 'ext': 'mp4',
24 'title': 'XXL - All Sports United',
25 'thumbnail': 're:^https?://.*\.jpg$',
26 }
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32
33 url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id)
34 webpage = self._download_webpage(url, video_id)
35
36 escaped_data = self._search_regex(
37 r'unescape\("([^"]+)"\)', webpage, 'escaped data')
38 playlist = compat_urllib_parse.unquote(escaped_data)
39
40 thumbnail = self._search_regex(
41 r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False)
42 url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL')
43 title = remove_start(self._html_search_regex(
44 r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ')
45
46 formats = [{
47 'format_id': 'sd',
48 'url': url,
49 }]
50 self._sort_formats(formats)
51
52 return {
53 'id': video_id,
54 'title': title,
55 'formats': formats,
56 'thumbnail': thumbnail,
57 }