aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/trilulilu.py
blob: 0bf028f6195ba56be22e059bdc83d23cbabff59b (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
66
67
68
69
70
71
72
73
import json
import re
import xml.etree.ElementTree

from .common import InfoExtractor


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

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('video_id')

        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, u'log info')
        log = json.loads(log_str)

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

        format_doc = xml.etree.ElementTree.fromstring(format_str)
 
        video_url_template = (
            u'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
            u'&source=site&hash=%(hash)s&username=%(userid)s&'
            u'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')
        ]

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

        # TODO: Remove when #980 has been merged
        info.update(formats[-1])

        return info