]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/videomega.py
[radiobremen] Fix under Python 2.6 and fix duration
[youtube-dl] / youtube_dl / extractor / videomega.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import (
6     compat_urllib_parse,
7 )
8 from ..utils import (
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         video_id = self._match_id(url)
31         url = 'http://videomega.tv/iframe.php?ref={0:}'.format(video_id)
32         webpage = self._download_webpage(url, video_id)
33
34         escaped_data = self._search_regex(
35             r'unescape\("([^"]+)"\)', webpage, 'escaped data')
36         playlist = compat_urllib_parse.unquote(escaped_data)
37
38         thumbnail = self._search_regex(
39             r'image:\s*"([^"]+)"', playlist, 'thumbnail', fatal=False)
40         url = self._search_regex(r'file:\s*"([^"]+)"', playlist, 'URL')
41         title = remove_start(self._html_search_regex(
42             r'<title>(.*?)</title>', webpage, 'title'), 'VideoMega.tv - ')
43
44         formats = [{
45             'format_id': 'sd',
46             'url': url,
47         }]
48         self._sort_formats(formats)
49
50         return {
51             'id': video_id,
52             'title': title,
53             'formats': formats,
54             'thumbnail': thumbnail,
55         }