]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/trilulilu.py
f278951baf0ae38fbbc7c5c405c473a8649e9caf
[youtubedl] / youtube_dl / extractor / trilulilu.py
1 import json
2 import re
3 import xml.etree.ElementTree
4
5 from .common import InfoExtractor
6
7
8 class TriluliluIE(InfoExtractor):
9 _VALID_URL = r'(?x)(?:https?://)?(?:www\.)?trilulilu\.ro/video-(?P<category>[^/]+)/(?P<video_id>[^/]+)'
10 _TEST = {
11 u"url": u"http://www.trilulilu.ro/video-animatie/big-buck-bunny-1",
12 u'file': u"big-buck-bunny-1.mp4",
13 u'info_dict': {
14 u"title": u"Big Buck Bunny",
15 u"description": u":) pentru copilul din noi",
16 },
17 # Server ignores Range headers (--test)
18 u"params": {
19 u"skip_download": True
20 }
21 }
22
23 def _real_extract(self, url):
24 mobj = re.match(self._VALID_URL, url)
25 video_id = mobj.group('video_id')
26
27 webpage = self._download_webpage(url, video_id)
28
29 title = self._og_search_title(webpage)
30 thumbnail = self._og_search_thumbnail(webpage)
31 description = self._og_search_description(webpage)
32
33 log_str = self._search_regex(
34 r'block_flash_vars[ ]=[ ]({[^}]+})', webpage, u'log info')
35 log = json.loads(log_str)
36
37 format_url = (u'http://fs%(server)s.trilulilu.ro/%(hash)s/'
38 u'video-formats2' % log)
39 format_str = self._download_webpage(
40 format_url, video_id,
41 note=u'Downloading formats',
42 errnote=u'Error while downloading formats')
43
44 format_doc = xml.etree.ElementTree.fromstring(format_str)
45
46 video_url_template = (
47 u'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
48 u'&source=site&hash=%(hash)s&username=%(userid)s&'
49 u'key=ministhebest&format=%%s&sig=&exp=' %
50 log)
51 formats = [
52 {
53 'format': fnode.text,
54 'url': video_url_template % fnode.text,
55 }
56
57 for fnode in format_doc.findall('./formats/format')
58 ]
59
60 info = {
61 '_type': 'video',
62 'id': video_id,
63 'formats': formats,
64 'title': title,
65 'description': description,
66 'thumbnail': thumbnail,
67 }
68
69 # TODO: Remove when #980 has been merged
70 info['url'] = formats[-1]['url']
71 info['ext'] = formats[-1]['format'].partition('-')[0]
72
73 return info