]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/skynewsarabia.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / skynewsarabia.py
1 from .common import InfoExtractor
2 from ..utils import (
3 parse_duration,
4 parse_iso8601,
5 )
6
7
8 class SkyNewsArabiaBaseIE(InfoExtractor):
9 _IMAGE_BASE_URL = 'http://www.skynewsarabia.com/web/images'
10
11 def _call_api(self, path, value):
12 return self._download_json(f'http://api.skynewsarabia.com/web/rest/v2/{path}/{value}.json', value)
13
14 def _get_limelight_media_id(self, url):
15 return self._search_regex(r'/media/[^/]+/([a-z0-9]{32})', url, 'limelight media id')
16
17 def _get_image_url(self, image_path_template, width='1600', height='1200'):
18 return self._IMAGE_BASE_URL + image_path_template.format(width=width, height=height)
19
20 def _extract_video_info(self, video_data):
21 video_id = str(video_data['id'])
22 topic = video_data.get('topicTitle')
23 return {
24 '_type': 'url_transparent',
25 'url': 'limelight:media:{}'.format(self._get_limelight_media_id(video_data['videoUrl'][0]['url'])),
26 'id': video_id,
27 'title': video_data['headline'],
28 'description': video_data.get('summary'),
29 'thumbnail': self._get_image_url(video_data['mediaAsset']['imageUrl']),
30 'timestamp': parse_iso8601(video_data.get('date')),
31 'duration': parse_duration(video_data.get('runTime')),
32 'tags': video_data.get('tags', []),
33 'categories': [topic] if topic else [],
34 'webpage_url': f'http://www.skynewsarabia.com/web/video/{video_id}',
35 'ie_key': 'LimelightMedia',
36 }
37
38
39 class SkyNewsArabiaIE(SkyNewsArabiaBaseIE):
40 _WORKING = False
41 IE_NAME = 'skynewsarabia:video'
42 _VALID_URL = r'https?://(?:www\.)?skynewsarabia\.com/web/video/(?P<id>[0-9]+)'
43 _TEST = {
44 'url': 'http://www.skynewsarabia.com/web/video/794902/%D9%86%D8%B5%D9%81-%D9%85%D9%84%D9%8A%D9%88%D9%86-%D9%85%D8%B5%D8%A8%D8%A7%D8%AD-%D8%B4%D8%AC%D8%B1%D8%A9-%D9%83%D8%B1%D9%8A%D8%B3%D9%85%D8%A7%D8%B3',
45 'info_dict': {
46 'id': '794902',
47 'ext': 'flv',
48 'title': 'نصف مليون مصباح على شجرة كريسماس',
49 'description': 'md5:22f1b27f0850eeb10c7e59b1f16eb7c6',
50 'upload_date': '20151128',
51 'timestamp': 1448697198,
52 'duration': 2119,
53 },
54 'params': {
55 # rtmp download
56 'skip_download': True,
57 },
58 }
59
60 def _real_extract(self, url):
61 video_id = self._match_id(url)
62 video_data = self._call_api('video', video_id)
63 return self._extract_video_info(video_data)
64
65
66 class SkyNewsArabiaArticleIE(SkyNewsArabiaBaseIE):
67 _WORKING = False
68 IE_NAME = 'skynewsarabia:article'
69 _VALID_URL = r'https?://(?:www\.)?skynewsarabia\.com/web/article/(?P<id>[0-9]+)'
70 _TESTS = [{
71 'url': 'http://www.skynewsarabia.com/web/article/794549/%D8%A7%D9%94%D8%AD%D8%AF%D8%A7%D8%AB-%D8%A7%D9%84%D8%B4%D8%B1%D9%82-%D8%A7%D9%84%D8%A7%D9%94%D9%88%D8%B3%D8%B7-%D8%AE%D8%B1%D9%8A%D8%B7%D8%A9-%D8%A7%D9%84%D8%A7%D9%94%D9%84%D8%B9%D8%A7%D8%A8-%D8%A7%D9%84%D8%B0%D9%83%D9%8A%D8%A9',
72 'info_dict': {
73 'id': '794549',
74 'ext': 'flv',
75 'title': 'بالفيديو.. ألعاب ذكية تحاكي واقع المنطقة',
76 'description': 'md5:0c373d29919a851e080ee4edd0c5d97f',
77 'upload_date': '20151126',
78 'timestamp': 1448559336,
79 'duration': 281.6,
80 },
81 'params': {
82 # rtmp download
83 'skip_download': True,
84 },
85 }, {
86 'url': 'http://www.skynewsarabia.com/web/article/794844/%D8%A7%D8%B3%D8%AA%D9%87%D8%AF%D8%A7%D9%81-%D9%82%D9%88%D8%A7%D8%B1%D8%A8-%D8%A7%D9%94%D8%B3%D9%84%D8%AD%D8%A9-%D9%84%D9%85%D9%8A%D9%84%D9%8A%D8%B4%D9%8A%D8%A7%D8%AA-%D8%A7%D9%84%D8%AD%D9%88%D8%AB%D9%8A-%D9%88%D8%B5%D8%A7%D9%84%D8%AD',
87 'info_dict': {
88 'id': '794844',
89 'title': 'إحباط تهريب أسلحة لميليشيات الحوثي وصالح بجنوب اليمن',
90 'description': 'md5:5c927b8b2e805796e7f693538d96fc7e',
91 },
92 'playlist_mincount': 2,
93 }]
94
95 def _real_extract(self, url):
96 article_id = self._match_id(url)
97 article_data = self._call_api('article', article_id)
98 media_asset = article_data['mediaAsset']
99 if media_asset['type'] == 'VIDEO':
100 topic = article_data.get('topicTitle')
101 return {
102 '_type': 'url_transparent',
103 'url': 'limelight:media:{}'.format(self._get_limelight_media_id(media_asset['videoUrl'][0]['url'])),
104 'id': article_id,
105 'title': article_data['headline'],
106 'description': article_data.get('summary'),
107 'thumbnail': self._get_image_url(media_asset['imageUrl']),
108 'timestamp': parse_iso8601(article_data.get('date')),
109 'tags': article_data.get('tags', []),
110 'categories': [topic] if topic else [],
111 'webpage_url': url,
112 'ie_key': 'LimelightMedia',
113 }
114 entries = [self._extract_video_info(item) for item in article_data.get('inlineItems', []) if item['type'] == 'VIDEO']
115 return self.playlist_result(entries, article_id, article_data['headline'], article_data.get('summary'))