]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/sport5.py
[bitchute] Fix test (#758)
[yt-dlp.git] / yt_dlp / extractor / sport5.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4
5 from .common import InfoExtractor
6 from ..utils import ExtractorError
7
8
9 class Sport5IE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www|vod)?\.sport5\.co\.il/.*\b(?:Vi|docID)=(?P<id>\d+)'
11 _TESTS = [
12 {
13 'url': 'http://vod.sport5.co.il/?Vc=147&Vi=176331&Page=1',
14 'info_dict': {
15 'id': 's5-Y59xx1-GUh2',
16 'ext': 'mp4',
17 'title': 'ולנסיה-קורדובה 0:3',
18 'description': 'אלקאסר, גאייה ופגולי סידרו לקבוצה של נונו ניצחון על קורדובה ואת המקום הראשון בליגה',
19 'duration': 228,
20 'categories': list,
21 },
22 'skip': 'Blocked outside of Israel',
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',
28 'title': 'GOALS_CELTIC_270914.mp4',
29 'description': '',
30 'duration': 87,
31 'categories': list,
32 },
33 'skip': 'Blocked outside of Israel',
34 }
35 ]
36
37 def _real_extract(self, url):
38 mobj = self._match_valid_url(url)
39 media_id = mobj.group('id')
40
41 webpage = self._download_webpage(url, media_id)
42
43 video_id = self._html_search_regex(r'clipId=([\w-]+)', webpage, 'video id')
44
45 metadata = self._download_xml(
46 'http://sport5-metadata-rr-d.nsacdn.com/vod/vod/%s/HDS/metadata.xml' % video_id,
47 video_id)
48
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)
57
58 title = metadata.find('./Title').text
59 description = metadata.find('./Description').text
60 duration = int(metadata.find('./Duration').text)
61
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 []
73
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')]
81 self._sort_formats(formats)
82
83 return {
84 'id': video_id,
85 'title': title,
86 'description': description,
87 'thumbnails': thumbnails,
88 'duration': duration,
89 'categories': categories,
90 'formats': formats,
91 }