]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/trilulilu.py
Credit @gebn for moviefap
[yt-dlp.git] / youtube_dl / extractor / trilulilu.py
CommitLineData
2caf182f 1# coding: utf-8
b3034f9d
PH
2from __future__ import unicode_literals
3
2caf182f 4import re
341ca8d7
PH
5
6from .common import InfoExtractor
2caf182f 7from ..utils import ExtractorError
341ca8d7
PH
8
9
10class TriluliluIE(InfoExtractor):
2caf182f 11 _VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/(?:video-[^/]+/)?(?P<id>[^/#\?]+)'
341ca8d7 12 _TEST = {
b3034f9d 13 'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1',
2caf182f 14 'md5': 'c1450a00da251e2769b74b9005601cac',
b3034f9d 15 'info_dict': {
2caf182f 16 'id': 'ae2899e124140b',
b3034f9d
PH
17 'ext': 'mp4',
18 'title': 'Big Buck Bunny',
19 'description': ':) pentru copilul din noi',
341ca8d7 20 },
341ca8d7
PH
21 }
22
23 def _real_extract(self, url):
2caf182f
NJ
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)
341ca8d7 35
2caf182f
NJ
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']
341ca8d7
PH
47 title = self._og_search_title(webpage)
48 thumbnail = self._og_search_thumbnail(webpage)
2caf182f 49 description = self._og_search_description(webpage, default=None)
341ca8d7 50
b3034f9d 51 format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/'
2caf182f 52 'video-formats2' % flashvars)
e26f8712 53 format_doc = self._download_xml(
341ca8d7 54 format_url, video_id,
b3034f9d
PH
55 note='Downloading formats',
56 errnote='Error while downloading formats')
5f6a1245 57
341ca8d7 58 video_url_template = (
b3034f9d
PH
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=' %
2caf182f 62 flashvars)
341ca8d7
PH
63 formats = [
64 {
2caf182f 65 'format_id': fnode.text.partition('-')[2],
341ca8d7 66 'url': video_url_template % fnode.text,
471a5ee9 67 'ext': fnode.text.partition('-')[0]
341ca8d7
PH
68 }
69
70 for fnode in format_doc.findall('./formats/format')
71 ]
72
fb7abb31 73 return {
341ca8d7 74 'id': video_id,
2caf182f 75 'display_id': display_id,
341ca8d7
PH
76 'formats': formats,
77 'title': title,
78 'description': description,
79 'thumbnail': thumbnail,
80 }