skynewsarabia.py 5.2 KB

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