]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/trilulilu.py
Register new version in the changelog.
[youtubedl] / youtube_dl / extractor / trilulilu.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 ExtractorError
8
9
10 class TriluliluIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/(?:video-[^/]+/)?(?P<id>[^/#\?]+)'
12 _TEST = {
13 'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1',
14 'md5': 'c1450a00da251e2769b74b9005601cac',
15 'info_dict': {
16 'id': 'ae2899e124140b',
17 'ext': 'mp4',
18 'title': 'Big Buck Bunny',
19 'description': ':) pentru copilul din noi',
20 },
21 }
22
23 def _real_extract(self, url):
24 display_id = self._match_id(url)
25 webpage = self._download_webpage(url, display_id)
26
27 if re.search(r'Fişierul nu este disponibil pentru vizionare în ţara dumneavoastră', webpage):
28 raise ExtractorError(
29 'This video is not available in your country.', expected=True)
30 elif re.search('Fişierul poate fi accesat doar de către prietenii lui', webpage):
31 raise ExtractorError('This video is private.', expected=True)
32
33 flashvars_str = self._search_regex(
34 r'block_flash_vars\s*=\s*(\{[^\}]+\})', webpage, 'flashvars', fatal=False, default=None)
35
36 if flashvars_str:
37 flashvars = self._parse_json(flashvars_str, display_id)
38 else:
39 raise ExtractorError(
40 'This page does not contain videos', expected=True)
41
42 if flashvars['isMP3'] == 'true':
43 raise ExtractorError(
44 'Audio downloads are currently not supported', expected=True)
45
46 video_id = flashvars['hash']
47 title = self._og_search_title(webpage)
48 thumbnail = self._og_search_thumbnail(webpage)
49 description = self._og_search_description(webpage, default=None)
50
51 format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/'
52 'video-formats2' % flashvars)
53 format_doc = self._download_xml(
54 format_url, video_id,
55 note='Downloading formats',
56 errnote='Error while downloading formats')
57
58 video_url_template = (
59 'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
60 '&source=site&hash=%(hash)s&username=%(userid)s&'
61 'key=ministhebest&format=%%s&sig=&exp=' %
62 flashvars)
63 formats = [
64 {
65 'format_id': fnode.text.partition('-')[2],
66 'url': video_url_template % fnode.text,
67 'ext': fnode.text.partition('-')[0]
68 }
69
70 for fnode in format_doc.findall('./formats/format')
71 ]
72
73 return {
74 'id': video_id,
75 'display_id': display_id,
76 'formats': formats,
77 'title': title,
78 'description': description,
79 'thumbnail': thumbnail,
80 }