aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/trilulilu.py
blob: 220a05b7b493fb728f3cd3c6dab74208a8f587eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import unicode_literals

import json

from .common import InfoExtractor


class TriluliluIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/video-[^/]+/(?P<id>[^/]+)'
    _TEST = {
        'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1',
        'info_dict': {
            'id': 'big-buck-bunny-1',
            'ext': 'mp4',
            'title': 'Big Buck Bunny',
            'description': ':) pentru copilul din noi',
        },
        # Server ignores Range headers (--test)
        'params': {
            'skip_download': True
        }
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        title = self._og_search_title(webpage)
        thumbnail = self._og_search_thumbnail(webpage)
        description = self._og_search_description(webpage)

        log_str = self._search_regex(
            r'block_flash_vars[ ]=[ ]({[^}]+})', webpage, 'log info')
        log = json.loads(log_str)

        format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/'
                      'video-formats2' % log)
        format_doc = self._download_xml(
            format_url, video_id,
            note='Downloading formats',
            errnote='Error while downloading formats')

        video_url_template = (
            'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
            '&source=site&hash=%(hash)s&username=%(userid)s&'
            'key=ministhebest&format=%%s&sig=&exp=' %
            log)
        formats = [
            {
                'format': fnode.text,
                'url': video_url_template % fnode.text,
                'ext': fnode.text.partition('-')[0]
            }

            for fnode in format_doc.findall('./formats/format')
        ]

        return {
            '_type': 'video',
            'id': video_id,
            'formats': formats,
            'title': title,
            'description': description,
            'thumbnail': thumbnail,
        }