]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/meta.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / meta.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .pladform import PladformIE
6 from ..utils import (
7 unescapeHTML,
8 int_or_none,
9 ExtractorError,
10 )
11
12
13 class METAIE(InfoExtractor):
14 _VALID_URL = r'https?://video\.meta\.ua/(?:iframe/)?(?P<id>[0-9]+)'
15 _TESTS = [{
16 'url': 'http://video.meta.ua/5502115.video',
17 'md5': '71b6f3ee274bef16f1ab410f7f56b476',
18 'info_dict': {
19 'id': '5502115',
20 'ext': 'mp4',
21 'title': 'Sony Xperia Z camera test [HQ]',
22 'description': 'Xperia Z shoots video in FullHD HDR.',
23 'uploader_id': 'nomobile',
24 'uploader': 'CHЁZA.TV',
25 'upload_date': '20130211',
26 },
27 'add_ie': ['Youtube'],
28 }, {
29 'url': 'http://video.meta.ua/iframe/5502115',
30 'only_matching': True,
31 }, {
32 # pladform embed
33 'url': 'http://video.meta.ua/7121015.video',
34 'only_matching': True,
35 }]
36
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
39 webpage = self._download_webpage(url, video_id)
40
41 st_html5 = self._search_regex(
42 r"st_html5\s*=\s*'#([^']+)'", webpage, 'uppod html5 st', default=None)
43
44 if st_html5:
45 # uppod st decryption algorithm is reverse engineered from function un(s) at uppod.js
46 json_str = ''
47 for i in range(0, len(st_html5), 3):
48 json_str += '&#x0%s;' % st_html5[i:i + 3]
49 uppod_data = self._parse_json(unescapeHTML(json_str), video_id)
50 error = uppod_data.get('customnotfound')
51 if error:
52 raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
53
54 video_url = uppod_data['file']
55 info = {
56 'id': video_id,
57 'url': video_url,
58 'title': uppod_data.get('comment') or self._og_search_title(webpage),
59 'description': self._og_search_description(webpage, default=None),
60 'thumbnail': uppod_data.get('poster') or self._og_search_thumbnail(webpage),
61 'duration': int_or_none(self._og_search_property(
62 'video:duration', webpage, default=None)),
63 }
64 if 'youtube.com/' in video_url:
65 info.update({
66 '_type': 'url_transparent',
67 'ie_key': 'Youtube',
68 })
69 return info
70
71 pladform_url = PladformIE._extract_url(webpage)
72 if pladform_url:
73 return self.url_result(pladform_url)