telequebec.py 6.8 KB

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