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.

207 lines
6.9 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. unified_timestamp,
  10. )
  11. class TeleQuebecBaseIE(InfoExtractor):
  12. @staticmethod
  13. def _limelight_result(media_id):
  14. return {
  15. '_type': 'url_transparent',
  16. 'url': smuggle_url(
  17. 'limelight:media:' + media_id, {'geo_countries': ['CA']}),
  18. 'ie_key': 'LimelightMedia',
  19. }
  20. class TeleQuebecIE(TeleQuebecBaseIE):
  21. _VALID_URL = r'''(?x)
  22. https?://
  23. (?:
  24. zonevideo\.telequebec\.tv/media|
  25. coucou\.telequebec\.tv/videos
  26. )/(?P<id>\d+)
  27. '''
  28. _TESTS = [{
  29. # available till 01.01.2023
  30. 'url': 'http://zonevideo.telequebec.tv/media/37578/un-petit-choc-et-puis-repart/un-chef-a-la-cabane',
  31. 'info_dict': {
  32. 'id': '577116881b4b439084e6b1cf4ef8b1b3',
  33. 'ext': 'mp4',
  34. 'title': 'Un petit choc et puis repart!',
  35. 'description': 'md5:b04a7e6b3f74e32d7b294cffe8658374',
  36. 'upload_date': '20180222',
  37. 'timestamp': 1519326631,
  38. },
  39. 'params': {
  40. 'skip_download': True,
  41. },
  42. }, {
  43. # no description
  44. 'url': 'http://zonevideo.telequebec.tv/media/30261',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'https://coucou.telequebec.tv/videos/41788/idee-de-genie/l-heure-du-bain',
  48. 'only_matching': True,
  49. }]
  50. def _real_extract(self, url):
  51. media_id = self._match_id(url)
  52. media_data = self._download_json(
  53. 'https://mnmedias.api.telequebec.tv/api/v2/media/' + media_id,
  54. media_id)['media']
  55. info = self._limelight_result(media_data['streamInfo']['sourceId'])
  56. info.update({
  57. 'title': media_data.get('title'),
  58. 'description': try_get(
  59. media_data, lambda x: x['descriptions'][0]['text'], compat_str),
  60. 'duration': int_or_none(
  61. media_data.get('durationInMilliseconds'), 1000),
  62. })
  63. return info
  64. class TeleQuebecSquatIE(InfoExtractor):
  65. _VALID_URL = r'https://squat\.telequebec\.tv/videos/(?P<id>\d+)'
  66. _TESTS = [{
  67. 'url': 'https://squat.telequebec.tv/videos/9314',
  68. 'info_dict': {
  69. 'id': 'd59ae78112d542e793d83cc9d3a5b530',
  70. 'ext': 'mp4',
  71. 'title': 'Poupeflekta',
  72. 'description': 'md5:2f0718f8d2f8fece1646ee25fb7bce75',
  73. 'duration': 1351,
  74. 'timestamp': 1569057600,
  75. 'upload_date': '20190921',
  76. 'series': 'Miraculous : Les Aventures de Ladybug et Chat Noir',
  77. 'season': 'Saison 3',
  78. 'season_number': 3,
  79. 'episode_number': 57,
  80. },
  81. 'params': {
  82. 'skip_download': True,
  83. },
  84. }]
  85. def _real_extract(self, url):
  86. video_id = self._match_id(url)
  87. video = self._download_json(
  88. 'https://squat.api.telequebec.tv/v1/videos/%s' % video_id,
  89. video_id)
  90. media_id = video['sourceId']
  91. return {
  92. '_type': 'url_transparent',
  93. 'url': 'http://zonevideo.telequebec.tv/media/%s' % media_id,
  94. 'ie_key': TeleQuebecIE.ie_key(),
  95. 'id': media_id,
  96. 'title': video.get('titre'),
  97. 'description': video.get('description'),
  98. 'timestamp': unified_timestamp(video.get('datePublication')),
  99. 'series': video.get('container'),
  100. 'season': video.get('saison'),
  101. 'season_number': int_or_none(video.get('noSaison')),
  102. 'episode_number': int_or_none(video.get('episode')),
  103. }
  104. class TeleQuebecEmissionIE(TeleQuebecBaseIE):
  105. _VALID_URL = r'''(?x)
  106. https?://
  107. (?:
  108. [^/]+\.telequebec\.tv/emissions/|
  109. (?:www\.)?telequebec\.tv/
  110. )
  111. (?P<id>[^?#&]+)
  112. '''
  113. _TESTS = [{
  114. 'url': 'http://lindicemcsween.telequebec.tv/emissions/100430013/des-soins-esthetiques-a-377-d-interets-annuels-ca-vous-tente',
  115. 'info_dict': {
  116. 'id': '66648a6aef914fe3badda25e81a4d50a',
  117. 'ext': 'mp4',
  118. 'title': "Des soins esthétiques à 377 % d'intérêts annuels, ça vous tente?",
  119. 'description': 'md5:369e0d55d0083f1fc9b71ffb640ea014',
  120. 'upload_date': '20171024',
  121. 'timestamp': 1508862118,
  122. },
  123. 'params': {
  124. 'skip_download': True,
  125. },
  126. }, {
  127. 'url': 'http://bancpublic.telequebec.tv/emissions/emission-49/31986/jeunes-meres-sous-pression',
  128. 'only_matching': True,
  129. }, {
  130. 'url': 'http://www.telequebec.tv/masha-et-michka/epi059masha-et-michka-3-053-078',
  131. 'only_matching': True,
  132. }, {
  133. 'url': 'http://www.telequebec.tv/documentaire/bebes-sur-mesure/',
  134. 'only_matching': True,
  135. }]
  136. def _real_extract(self, url):
  137. display_id = self._match_id(url)
  138. webpage = self._download_webpage(url, display_id)
  139. media_id = self._search_regex(
  140. r'mediaUID\s*:\s*["\'][Ll]imelight_(?P<id>[a-z0-9]{32})', webpage,
  141. 'limelight id')
  142. info = self._limelight_result(media_id)
  143. info.update({
  144. 'title': self._og_search_title(webpage, default=None),
  145. 'description': self._og_search_description(webpage, default=None),
  146. })
  147. return info
  148. class TeleQuebecLiveIE(InfoExtractor):
  149. _VALID_URL = r'https?://zonevideo\.telequebec\.tv/(?P<id>endirect)'
  150. _TEST = {
  151. 'url': 'http://zonevideo.telequebec.tv/endirect/',
  152. 'info_dict': {
  153. 'id': 'endirect',
  154. 'ext': 'mp4',
  155. 'title': 're:^Télé-Québec - En direct [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  156. 'is_live': True,
  157. },
  158. 'params': {
  159. 'skip_download': True,
  160. },
  161. }
  162. def _real_extract(self, url):
  163. video_id = self._match_id(url)
  164. m3u8_url = None
  165. webpage = self._download_webpage(
  166. 'https://player.telequebec.tv/Tq_VideoPlayer.js', video_id,
  167. fatal=False)
  168. if webpage:
  169. m3u8_url = self._search_regex(
  170. r'm3U8Url\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
  171. 'm3u8 url', default=None, group='url')
  172. if not m3u8_url:
  173. m3u8_url = 'https://teleqmmd.mmdlive.lldns.net/teleqmmd/f386e3b206814e1f8c8c1c71c0f8e748/manifest.m3u8'
  174. formats = self._extract_m3u8_formats(
  175. m3u8_url, video_id, 'mp4', m3u8_id='hls')
  176. self._sort_formats(formats)
  177. return {
  178. 'id': video_id,
  179. 'title': self._live_title('Télé-Québec - En direct'),
  180. 'is_live': True,
  181. 'formats': formats,
  182. }