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