aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/sport5.py
blob: 9a4e39a43edc4ab363bbe97f39d53b33908df461 (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
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from youtube_dl.utils import compat_str, compat_urlretrieve



class Sport5IE(InfoExtractor):
    _VALID_URL = r'http://.*sport5\.co\.il'
    _TESTS = [{
            'url': 'http://vod.sport5.co.il/?Vc=147&Vi=176331&Page=1',
            'info_dict': {
                'id': 's5-Y59xx1-GUh2',
                'ext': 'mp4',
                'title': 'md5:4a2a5eba7e7dc88fdc446cbca8a41c79',
            }
        }, {
            'url': 'http://www.sport5.co.il/articles.aspx?FolderID=3075&docID=176372&lang=HE',
            'info_dict': {
                'id': 's5-SiXxx1-hKh2',
                'ext': 'mp4',
                'title': 'md5:5cb1c6bfc0f16086e59f6683013f8e02',
            }
        }
    ]

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

        webpage = self._download_webpage(url, '')

        media_id = self._html_search_regex('clipId=(s5-\w+-\w+)', webpage, 'media id')

        xml = self._download_xml(
            'http://sport5-metadata-rr-d.nsacdn.com/vod/vod/%s/HDS/metadata.xml' % media_id,
            media_id, 'Downloading media XML')

        title = xml.find('./Title').text
        duration = xml.find('./Duration').text
        description = xml.find('./Description').text
        thumbnail = xml.find('./PosterLinks/PosterIMG').text
        player_url = xml.find('./PlaybackLinks/PlayerUrl').text
        file_els = xml.findall('./PlaybackLinks/FileURL')

        formats = []

        for file_el in file_els:
            bitrate = file_el.attrib.get('bitrate')
            width = int(file_el.attrib.get('width'))
            height = int(file_el.attrib.get('height'))
            formats.append({
                'url': compat_str(file_el.text),
                'ext': 'mp4',
                'height': height,
                'width': width
            })

        self._sort_formats(formats)

        return {
            'id': media_id,
            'title': title,
            'thumbnail': thumbnail,
            'duration': duration,
            'formats': formats,
            'player_url': player_url,
        }