logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

skynewsarabia.py (5382B)


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