]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/skynewsarabia.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / skynewsarabia.py
CommitLineData
0cc71785 1from .common import InfoExtractor
2from ..compat import compat_str
3from ..utils import (
0cc71785 4 parse_duration,
e897bd82 5 parse_iso8601,
0cc71785 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):
df773c3d 41 _WORKING = False
4975650e 42 IE_NAME = 'skynewsarabia:video'
0cc71785 43 _VALID_URL = r'https?://(?:www\.)?skynewsarabia\.com/web/video/(?P<id>[0-9]+)'
44 _TEST = {
45 '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',
46 'info_dict': {
47 'id': '794902',
48 'ext': 'flv',
49 'title': 'نصف مليون مصباح على شجرة كريسماس',
50 'description': 'md5:22f1b27f0850eeb10c7e59b1f16eb7c6',
51 'upload_date': '20151128',
52 'timestamp': 1448697198,
53 'duration': 2119,
54 },
55 'params': {
56 # rtmp download
57 'skip_download': True,
58 },
59 }
60
61 def _real_extract(self, url):
62 video_id = self._match_id(url)
63 video_data = self._call_api('video', video_id)
64 return self._extract_video_info(video_data)
65
66
96929dd1 67class SkyNewsArabiaArticleIE(SkyNewsArabiaBaseIE):
df773c3d 68 _WORKING = False
f41ffc00 69 IE_NAME = 'skynewsarabia:article'
0cc71785 70 _VALID_URL = r'https?://(?:www\.)?skynewsarabia\.com/web/article/(?P<id>[0-9]+)'
71 _TESTS = [{
72 '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',
73 'info_dict': {
74 'id': '794549',
75 'ext': 'flv',
76 'title': 'بالفيديو.. ألعاب ذكية تحاكي واقع المنطقة',
77 'description': 'md5:0c373d29919a851e080ee4edd0c5d97f',
78 'upload_date': '20151126',
79 'timestamp': 1448559336,
80 'duration': 281.6,
81 },
82 'params': {
83 # rtmp download
84 'skip_download': True,
85 },
86 }, {
87 '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',
88 'info_dict': {
89 'id': '794844',
90 'title': 'إحباط تهريب أسلحة لميليشيات الحوثي وصالح بجنوب اليمن',
91 'description': 'md5:5c927b8b2e805796e7f693538d96fc7e',
92 },
93 'playlist_mincount': 2,
94 }]
95
96 def _real_extract(self, url):
97 article_id = self._match_id(url)
98 article_data = self._call_api('article', article_id)
99 media_asset = article_data['mediaAsset']
100 if media_asset['type'] == 'VIDEO':
f4c7ef98 101 topic = article_data.get('topicTitle')
0cc71785 102 return {
103 '_type': 'url_transparent',
104 'url': 'limelight:media:%s' % self._get_limelight_media_id(media_asset['videoUrl'][0]['url']),
105 'id': article_id,
106 'title': article_data['headline'],
107 'description': article_data.get('summary'),
108 'thumbnail': self._get_image_url(media_asset['imageUrl']),
109 'timestamp': parse_iso8601(article_data.get('date')),
f4c7ef98 110 'tags': article_data.get('tags', []),
111 'categories': [topic] if topic else [],
0cc71785 112 'webpage_url': url,
113 'ie_key': 'LimelightMedia',
114 }
115 entries = [self._extract_video_info(item) for item in article_data.get('inlineItems', []) if item['type'] == 'VIDEO']
116 return self.playlist_result(entries, article_id, article_data['headline'], article_data.get('summary'))