tva.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import functools
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import float_or_none, int_or_none, smuggle_url, strip_or_none
  5. from ..utils.traversal import traverse_obj
  6. class TVAIE(InfoExtractor):
  7. _VALID_URL = r'https?://videos?\.tva\.ca/details/_(?P<id>\d+)'
  8. _TESTS = [{
  9. 'url': 'https://videos.tva.ca/details/_5596811470001',
  10. 'info_dict': {
  11. 'id': '5596811470001',
  12. 'ext': 'mp4',
  13. 'title': 'Un extrait de l\'épisode du dimanche 8 octobre 2017 !',
  14. 'uploader_id': '5481942443001',
  15. 'upload_date': '20171003',
  16. 'timestamp': 1507064617,
  17. },
  18. 'params': {
  19. # m3u8 download
  20. 'skip_download': True,
  21. },
  22. 'skip': 'HTTP Error 404: Not Found',
  23. }, {
  24. 'url': 'https://video.tva.ca/details/_5596811470001',
  25. 'only_matching': True,
  26. }]
  27. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5481942443001/default_default/index.html?videoId=%s'
  28. def _real_extract(self, url):
  29. video_id = self._match_id(url)
  30. return {
  31. '_type': 'url_transparent',
  32. 'id': video_id,
  33. 'url': smuggle_url(self.BRIGHTCOVE_URL_TEMPLATE % video_id, {'geo_countries': ['CA']}),
  34. 'ie_key': 'BrightcoveNew',
  35. }
  36. class QubIE(InfoExtractor):
  37. _VALID_URL = r'https?://(?:www\.)?qub\.ca/(?:[^/]+/)*[0-9a-z-]+-(?P<id>\d+)'
  38. _TESTS = [{
  39. 'url': 'https://www.qub.ca/tvaplus/tva/alerte-amber/saison-1/episode-01-1000036619',
  40. 'md5': '949490fd0e7aee11d0543777611fbd53',
  41. 'info_dict': {
  42. 'id': '6084352463001',
  43. 'ext': 'mp4',
  44. 'title': 'Ép 01. Mon dernier jour',
  45. 'uploader_id': '5481942443001',
  46. 'upload_date': '20190907',
  47. 'timestamp': 1567899756,
  48. 'description': 'md5:9c0d7fbb90939420c651fd977df90145',
  49. 'thumbnail': r're:https://.+\.jpg',
  50. 'episode': 'Ép 01. Mon dernier jour',
  51. 'episode_number': 1,
  52. 'tags': ['alerte amber', 'alerte amber saison 1', 'surdemande'],
  53. 'duration': 2625.963,
  54. 'season': 'Season 1',
  55. 'season_number': 1,
  56. 'series': 'Alerte Amber',
  57. 'channel': 'TVA',
  58. },
  59. }, {
  60. 'url': 'https://www.qub.ca/tele/video/lcn-ca-vous-regarde-rev-30s-ap369664-1009357943',
  61. 'only_matching': True,
  62. }]
  63. # reference_id also works with old account_id(5481942443001)
  64. # BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5813221784001/default_default/index.html?videoId=ref:%s'
  65. def _real_extract(self, url):
  66. entity_id = self._match_id(url)
  67. webpage = self._download_webpage(url, entity_id)
  68. entity = self._search_nextjs_data(webpage, entity_id)['props']['initialProps']['pageProps']['fallbackData']
  69. video_id = entity['videoId']
  70. episode = strip_or_none(entity.get('name'))
  71. return {
  72. '_type': 'url_transparent',
  73. 'url': f'https://videos.tva.ca/details/_{video_id}',
  74. 'ie_key': TVAIE.ie_key(),
  75. 'id': video_id,
  76. 'title': episode,
  77. 'episode': episode,
  78. **traverse_obj(entity, {
  79. 'description': ('longDescription', {str}),
  80. 'duration': ('durationMillis', {functools.partial(float_or_none, scale=1000)}),
  81. 'channel': ('knownEntities', 'channel', 'name', {str}),
  82. 'series': ('knownEntities', 'videoShow', 'name', {str}),
  83. 'season_number': ('slug', {lambda x: re.search(r'/s(?:ai|ea)son-(\d+)/', x)}, 1, {int_or_none}),
  84. 'episode_number': ('episodeNumber', {int_or_none}),
  85. }),
  86. }