cgtn.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. try_get,
  4. unified_timestamp,
  5. )
  6. class CGTNIE(InfoExtractor):
  7. _VALID_URL = r'https?://news\.cgtn\.com/news/[0-9]{4}-[0-9]{2}-[0-9]{2}/[a-zA-Z0-9-]+-(?P<id>[a-zA-Z0-9-]+)/index\.html'
  8. _TESTS = [
  9. {
  10. 'url': 'https://news.cgtn.com/news/2021-03-09/Up-and-Out-of-Poverty-Ep-1-A-solemn-promise-YuOUaOzGQU/index.html',
  11. 'info_dict': {
  12. 'id': 'YuOUaOzGQU',
  13. 'ext': 'mp4',
  14. 'title': 'Up and Out of Poverty Ep. 1: A solemn promise',
  15. 'thumbnail': r're:^https?://.*\.jpg$',
  16. 'timestamp': 1615295940,
  17. 'upload_date': '20210309',
  18. 'categories': ['Video'],
  19. },
  20. 'params': {
  21. 'skip_download': True,
  22. },
  23. }, {
  24. 'url': 'https://news.cgtn.com/news/2021-06-06/China-Indonesia-vow-to-further-deepen-maritime-cooperation-10REvJCewCY/index.html',
  25. 'info_dict': {
  26. 'id': '10REvJCewCY',
  27. 'ext': 'mp4',
  28. 'title': 'China, Indonesia vow to further deepen maritime cooperation',
  29. 'thumbnail': r're:^https?://.*\.png$',
  30. 'description': 'China and Indonesia vowed to upgrade their cooperation into the maritime sector and also for political security, economy, and cultural and people-to-people exchanges.',
  31. 'creators': ['CGTN'],
  32. 'categories': ['China'],
  33. 'timestamp': 1622950200,
  34. 'upload_date': '20210606',
  35. },
  36. 'params': {
  37. 'skip_download': False,
  38. },
  39. },
  40. ]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. download_url = self._html_search_regex(r'data-video ="(?P<url>.+m3u8)"', webpage, 'download_url')
  45. datetime_str = self._html_search_regex(
  46. r'<span class="date">\s*(.+?)\s*</span>', webpage, 'datetime_str', fatal=False)
  47. category = self._html_search_regex(
  48. r'<span class="section">\s*(.+?)\s*</span>', webpage, 'category', fatal=False)
  49. author = self._search_regex(
  50. r'<div class="news-author-name">\s*(.+?)\s*</div>', webpage, 'author', default=None)
  51. return {
  52. 'id': video_id,
  53. 'title': self._og_search_title(webpage),
  54. 'description': self._og_search_description(webpage, default=None),
  55. 'thumbnail': self._og_search_thumbnail(webpage),
  56. 'formats': self._extract_m3u8_formats(download_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls'),
  57. 'categories': [category] if category else None,
  58. 'creators': [author] if author else None,
  59. 'timestamp': try_get(unified_timestamp(datetime_str), lambda x: x - 8 * 3600),
  60. }