]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/skynewsarabia.py
[cleanup] Fix infodict returned fields (#8906)
[yt-dlp.git] / yt_dlp / extractor / skynewsarabia.py
CommitLineData
0cc71785 1from .common import InfoExtractor
2from ..compat import compat_str
3from ..utils import (
4 parse_iso8601,
5 parse_duration,
6)
7
8
96929dd1 9class SkyNewsArabiaBaseIE(InfoExtractor):
0cc71785 10 _IMAGE_BASE_URL = 'http://www.skynewsarabia.com/web/images'
11
12 def _call_api(self, path, value):
13 return self._download_json('http://api.skynewsarabia.com/web/rest/v2/%s/%s.json' % (path, value), value)
14
15 def _get_limelight_media_id(self, url):
16 return self._search_regex(r'/media/[^/]+/([a-z0-9]{32})', url, 'limelight media id')
17
18 def _get_image_url(self, image_path_template, width='1600', height='1200'):
19 return self._IMAGE_BASE_URL + image_path_template.format(width=width, height=height)
20
21 def _extract_video_info(self, video_data):
22 video_id = compat_str(video_data['id'])
f4c7ef98 23 topic = video_data.get('topicTitle')
0cc71785 24 return {
25 '_type': 'url_transparent',
26 'url': 'limelight:media:%s' % self._get_limelight_media_id(video_data['videoUrl'][0]['url']),
27 'id': video_id,
28 'title': video_data['headline'],
29 'description': video_data.get('summary'),
30 'thumbnail': self._get_image_url(video_data['mediaAsset']['imageUrl']),
31 'timestamp': parse_iso8601(video_data.get('date')),
32 'duration': parse_duration(video_data.get('runTime')),
f4c7ef98 33 'tags': video_data.get('tags', []),
34 'categories': [topic] if topic else [],
0cc71785 35 'webpage_url': 'http://www.skynewsarabia.com/web/video/%s' % video_id,
36 'ie_key': 'LimelightMedia',
37 }
38
39
96929dd1 40class SkyNewsArabiaIE(SkyNewsArabiaBaseIE):
4975650e 41 IE_NAME = 'skynewsarabia:video'
0cc71785 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
96929dd1 66class SkyNewsArabiaArticleIE(SkyNewsArabiaBaseIE):
f41ffc00 67 IE_NAME = 'skynewsarabia:article'
0cc71785 68 _VALID_URL = r'https?://(?:www\.)?skynewsarabia\.com/web/article/(?P<id>[0-9]+)'
69 _TESTS = [{
70 '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',
71 'info_dict': {
72 'id': '794549',
73 'ext': 'flv',
74 'title': 'بالفيديو.. ألعاب ذكية تحاكي واقع المنطقة',
75 'description': 'md5:0c373d29919a851e080ee4edd0c5d97f',
76 'upload_date': '20151126',
77 'timestamp': 1448559336,
78 'duration': 281.6,
79 },
80 'params': {
81 # rtmp download
82 'skip_download': True,
83 },
84 }, {
85 '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',
86 'info_dict': {
87 'id': '794844',
88 'title': 'إحباط تهريب أسلحة لميليشيات الحوثي وصالح بجنوب اليمن',
89 'description': 'md5:5c927b8b2e805796e7f693538d96fc7e',
90 },
91 'playlist_mincount': 2,
92 }]
93
94 def _real_extract(self, url):
95 article_id = self._match_id(url)
96 article_data = self._call_api('article', article_id)
97 media_asset = article_data['mediaAsset']
98 if media_asset['type'] == 'VIDEO':
f4c7ef98 99 topic = article_data.get('topicTitle')
0cc71785 100 return {
101 '_type': 'url_transparent',
102 'url': 'limelight:media:%s' % self._get_limelight_media_id(media_asset['videoUrl'][0]['url']),
103 'id': article_id,
104 'title': article_data['headline'],
105 'description': article_data.get('summary'),
106 'thumbnail': self._get_image_url(media_asset['imageUrl']),
107 'timestamp': parse_iso8601(article_data.get('date')),
f4c7ef98 108 'tags': article_data.get('tags', []),
109 'categories': [topic] if topic else [],
0cc71785 110 'webpage_url': url,
111 'ie_key': 'LimelightMedia',
112 }
113 entries = [self._extract_video_info(item) for item in article_data.get('inlineItems', []) if item['type'] == 'VIDEO']
114 return self.playlist_result(entries, article_id, article_data['headline'], article_data.get('summary'))