You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.0 KiB

  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. int_or_none,
  7. smuggle_url,
  8. try_get,
  9. )
  10. class TeleQuebecBaseIE(InfoExtractor):
  11. @staticmethod
  12. def _limelight_result(media_id):
  13. return {
  14. '_type': 'url_transparent',
  15. 'url': smuggle_url(
  16. 'limelight:media:' + media_id, {'geo_countries': ['CA']}),
  17. 'ie_key': 'LimelightMedia',
  18. }
  19. class TeleQuebecIE(TeleQuebecBaseIE):
  20. _VALID_URL = r'https?://zonevideo\.telequebec\.tv/media/(?P<id>\d+)'
  21. _TESTS = [{
  22. # available till 01.01.2023
  23. 'url': 'http://zonevideo.telequebec.tv/media/37578/un-petit-choc-et-puis-repart/un-chef-a-la-cabane',
  24. 'info_dict': {
  25. 'id': '577116881b4b439084e6b1cf4ef8b1b3',
  26. 'ext': 'mp4',
  27. 'title': 'Un petit choc et puis repart!',
  28. 'description': 'md5:b04a7e6b3f74e32d7b294cffe8658374',
  29. 'upload_date': '20180222',
  30. 'timestamp': 1519326631,
  31. },
  32. 'params': {
  33. 'skip_download': True,
  34. },
  35. }, {
  36. # no description
  37. 'url': 'http://zonevideo.telequebec.tv/media/30261',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. media_id = self._match_id(url)
  42. media_data = self._download_json(
  43. 'https://mnmedias.api.telequebec.tv/api/v2/media/' + media_id,
  44. media_id)['media']
  45. info = self._limelight_result(media_data['streamInfo']['sourceId'])
  46. info.update({
  47. 'title': media_data.get('title'),
  48. 'description': try_get(
  49. media_data, lambda x: x['descriptions'][0]['text'], compat_str),
  50. 'duration': int_or_none(
  51. media_data.get('durationInMilliseconds'), 1000),
  52. })
  53. return info
  54. class TeleQuebecEmissionIE(TeleQuebecBaseIE):
  55. _VALID_URL = r'''(?x)
  56. https?://
  57. (?:
  58. [^/]+\.telequebec\.tv/emissions/|
  59. (?:www\.)?telequebec\.tv/
  60. )
  61. (?P<id>[^?#&]+)
  62. '''
  63. _TESTS = [{
  64. 'url': 'http://lindicemcsween.telequebec.tv/emissions/100430013/des-soins-esthetiques-a-377-d-interets-annuels-ca-vous-tente',
  65. 'info_dict': {
  66. 'id': '66648a6aef914fe3badda25e81a4d50a',
  67. 'ext': 'mp4',
  68. 'title': "Des soins esthétiques à 377 % d'intérêts annuels, ça vous tente?",
  69. 'description': 'md5:369e0d55d0083f1fc9b71ffb640ea014',
  70. 'upload_date': '20171024',
  71. 'timestamp': 1508862118,
  72. },
  73. 'params': {
  74. 'skip_download': True,
  75. },
  76. }, {
  77. 'url': 'http://bancpublic.telequebec.tv/emissions/emission-49/31986/jeunes-meres-sous-pression',
  78. 'only_matching': True,
  79. }, {
  80. 'url': 'http://www.telequebec.tv/masha-et-michka/epi059masha-et-michka-3-053-078',
  81. 'only_matching': True,
  82. }, {
  83. 'url': 'http://www.telequebec.tv/documentaire/bebes-sur-mesure/',
  84. 'only_matching': True,
  85. }]
  86. def _real_extract(self, url):
  87. display_id = self._match_id(url)
  88. webpage = self._download_webpage(url, display_id)
  89. media_id = self._search_regex(
  90. r'mediaUID\s*:\s*["\'][Ll]imelight_(?P<id>[a-z0-9]{32})', webpage,
  91. 'limelight id')
  92. info = self._limelight_result(media_id)
  93. info.update({
  94. 'title': self._og_search_title(webpage, default=None),
  95. 'description': self._og_search_description(webpage, default=None),
  96. })
  97. return info
  98. class TeleQuebecLiveIE(InfoExtractor):
  99. _VALID_URL = r'https?://zonevideo\.telequebec\.tv/(?P<id>endirect)'
  100. _TEST = {
  101. 'url': 'http://zonevideo.telequebec.tv/endirect/',
  102. 'info_dict': {
  103. 'id': 'endirect',
  104. 'ext': 'mp4',
  105. 'title': 're:^Télé-Québec - En direct [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  106. 'is_live': True,
  107. },
  108. 'params': {
  109. 'skip_download': True,
  110. },
  111. }
  112. def _real_extract(self, url):
  113. video_id = self._match_id(url)
  114. m3u8_url = None
  115. webpage = self._download_webpage(
  116. 'https://player.telequebec.tv/Tq_VideoPlayer.js', video_id,
  117. fatal=False)
  118. if webpage:
  119. m3u8_url = self._search_regex(
  120. r'm3U8Url\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  121. 'm3u8 url', default=None, group='url')
  122. if not m3u8_url:
  123. m3u8_url = 'https://teleqmmd.mmdlive.lldns.net/teleqmmd/f386e3b206814e1f8c8c1c71c0f8e748/manifest.m3u8'
  124. formats = self._extract_m3u8_formats(
  125. m3u8_url, video_id, 'mp4', m3u8_id='hls')
  126. self._sort_formats(formats)
  127. return {
  128. 'id': video_id,
  129. 'title': self._live_title('Télé-Québec - En direct'),
  130. 'is_live': True,
  131. 'formats': formats,
  132. }