]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/sport5.py
[generic] Extract m3u8 formats from JSON-LD
[yt-dlp.git] / yt_dlp / extractor / sport5.py
CommitLineData
b6674528 1# coding: utf-8
2from __future__ import unicode_literals
3
b6674528 4
5from .common import InfoExtractor
0b75c2a8 6from ..utils import ExtractorError
b6674528 7
8
9class Sport5IE(InfoExtractor):
5886b38d 10 _VALID_URL = r'https?://(?:www|vod)?\.sport5\.co\.il/.*\b(?:Vi|docID)=(?P<id>\d+)'
0b75c2a8
S
11 _TESTS = [
12 {
b6674528 13 'url': 'http://vod.sport5.co.il/?Vc=147&Vi=176331&Page=1',
14 'info_dict': {
15 'id': 's5-Y59xx1-GUh2',
16 'ext': 'mp4',
0b75c2a8
S
17 'title': 'ולנסיה-קורדובה 0:3',
18 'description': 'אלקאסר, גאייה ופגולי סידרו לקבוצה של נונו ניצחון על קורדובה ואת המקום הראשון בליגה',
19 'duration': 228,
20 'categories': list,
21 },
22 'skip': 'Blocked outside of Israel',
b6674528 23 }, {
24 'url': 'http://www.sport5.co.il/articles.aspx?FolderID=3075&docID=176372&lang=HE',
25 'info_dict': {
26 'id': 's5-SiXxx1-hKh2',
27 'ext': 'mp4',
0b75c2a8
S
28 'title': 'GOALS_CELTIC_270914.mp4',
29 'description': '',
30 'duration': 87,
31 'categories': list,
32 },
33 'skip': 'Blocked outside of Israel',
b6674528 34 }
35 ]
36
37 def _real_extract(self, url):
5ad28e7f 38 mobj = self._match_valid_url(url)
0b75c2a8 39 media_id = mobj.group('id')
b6674528 40
0b75c2a8 41 webpage = self._download_webpage(url, media_id)
b6674528 42
ec85ded8 43 video_id = self._html_search_regex(r'clipId=([\w-]+)', webpage, 'video id')
b6674528 44
0b75c2a8
S
45 metadata = self._download_xml(
46 'http://sport5-metadata-rr-d.nsacdn.com/vod/vod/%s/HDS/metadata.xml' % video_id,
47 video_id)
b6674528 48
0b75c2a8
S
49 error = metadata.find('./Error')
50 if error is not None:
51 raise ExtractorError(
52 '%s returned error: %s - %s' % (
53 self.IE_NAME,
54 error.find('./Name').text,
55 error.find('./Description').text),
56 expected=True)
b6674528 57
0b75c2a8
S
58 title = metadata.find('./Title').text
59 description = metadata.find('./Description').text
60 duration = int(metadata.find('./Duration').text)
b6674528 61
0b75c2a8
S
62 posters_el = metadata.find('./PosterLinks')
63 thumbnails = [{
64 'url': thumbnail.text,
65 'width': int(thumbnail.get('width')),
66 'height': int(thumbnail.get('height')),
67 } for thumbnail in posters_el.findall('./PosterIMG')] if posters_el is not None else []
68
69 categories_el = metadata.find('./Categories')
70 categories = [
71 cat.get('name') for cat in categories_el.findall('./Category')
72 ] if categories_el is not None else []
b6674528 73
0b75c2a8
S
74 formats = [{
75 'url': fmt.text,
76 'ext': 'mp4',
77 'vbr': int(fmt.get('bitrate')),
78 'width': int(fmt.get('width')),
79 'height': int(fmt.get('height')),
80 } for fmt in metadata.findall('./PlaybackLinks/FileURL')]
b6674528 81 self._sort_formats(formats)
82
83 return {
0b75c2a8 84 'id': video_id,
b6674528 85 'title': title,
0b75c2a8
S
86 'description': description,
87 'thumbnails': thumbnails,
b6674528 88 'duration': duration,
0b75c2a8 89 'categories': categories,
b6674528 90 'formats': formats,
5f6a1245 91 }