startv.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. clean_html,
  5. int_or_none,
  6. traverse_obj,
  7. )
  8. class StarTVIE(InfoExtractor):
  9. _VALID_URL = r'''(?x)
  10. https?://(?:www\.)?startv\.com\.tr/
  11. (?:
  12. (?:dizi|program)/(?:[^/?#&]+)/(?:bolumler|fragmanlar|ekstralar)|
  13. video/arsiv/(?:dizi|program)/(?:[^/?#&]+)
  14. )/
  15. (?P<id>[^/?#&]+)
  16. '''
  17. IE_NAME = 'startv'
  18. _TESTS = [
  19. {
  20. 'url': 'https://www.startv.com.tr/dizi/cocuk/bolumler/3-bolum',
  21. 'md5': '72381a32bcc2e2eb5841e8c8bf68f127',
  22. 'info_dict': {
  23. 'id': '904972',
  24. 'display_id': '3-bolum',
  25. 'ext': 'mp4',
  26. 'title': '3. Bölüm',
  27. 'description': 'md5:3a8049f05a75c2e8747116a673275de4',
  28. 'thumbnail': r're:^https?://.*\.jpg(?:\?.*?)?$',
  29. 'timestamp': 1569281400,
  30. 'upload_date': '20190923',
  31. },
  32. },
  33. {
  34. 'url': 'https://www.startv.com.tr/video/arsiv/dizi/avlu/44-bolum',
  35. 'only_matching': True,
  36. },
  37. {
  38. 'url': 'https://www.startv.com.tr/dizi/cocuk/fragmanlar/5-bolum-fragmani',
  39. 'only_matching': True,
  40. },
  41. {
  42. 'url': 'https://www.startv.com.tr/dizi/cocuk/ekstralar/5-bolumun-nefes-kesen-final-sahnesi',
  43. 'only_matching': True,
  44. },
  45. {
  46. 'url': 'https://www.startv.com.tr/program/burcu-ile-haftasonu/bolumler/1-bolum',
  47. 'only_matching': True,
  48. },
  49. {
  50. 'url': 'https://www.startv.com.tr/program/burcu-ile-haftasonu/fragmanlar/2-fragman',
  51. 'only_matching': True,
  52. },
  53. {
  54. 'url': 'https://www.startv.com.tr/video/arsiv/program/buyukrisk/14-bolumde-hangi-unlu-ne-sordu-',
  55. 'only_matching': True,
  56. },
  57. {
  58. 'url': 'https://www.startv.com.tr/video/arsiv/program/buyukrisk/buyuk-risk-334-bolum',
  59. 'only_matching': True,
  60. },
  61. {
  62. 'url': 'https://www.startv.com.tr/video/arsiv/program/dada/dada-58-bolum',
  63. 'only_matching': True,
  64. },
  65. ]
  66. def _real_extract(self, url):
  67. display_id = self._match_id(url)
  68. webpage = self._download_webpage(url, display_id)
  69. info_url = self._search_regex(
  70. r'(["\'])videoUrl\1\s*:\s*\1(?P<url>(?:(?!\1).)+)\1\s*',
  71. webpage, 'video info url', group='url')
  72. info = traverse_obj(self._download_json(info_url, display_id), 'data', expected_type=dict)
  73. if not info:
  74. raise ExtractorError('Failed to extract API data')
  75. video_id = str(info.get('id'))
  76. title = info.get('title') or self._og_search_title(webpage)
  77. description = clean_html(info.get('description')) or self._og_search_description(webpage, default=None)
  78. thumbnail = self._proto_relative_url(
  79. self._og_search_thumbnail(webpage), scheme='http:')
  80. formats = self._extract_m3u8_formats(
  81. traverse_obj(info, ('flavors', 'hls')), video_id, entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
  82. return {
  83. 'id': video_id,
  84. 'display_id': display_id,
  85. 'title': title,
  86. 'description': description,
  87. 'thumbnail': thumbnail,
  88. 'timestamp': int_or_none(info.get('release_date')),
  89. 'formats': formats,
  90. }