logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

noovo.py (3658B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .brightcove import BrightcoveNewIE
  4. from .common import InfoExtractor
  5. from ..compat import compat_str
  6. from ..utils import (
  7. int_or_none,
  8. js_to_json,
  9. smuggle_url,
  10. try_get,
  11. )
  12. class NoovoIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:[^/]+\.)?noovo\.ca/videos/(?P<id>[^/]+/[^/?#&]+)'
  14. _TESTS = [{
  15. # clip
  16. 'url': 'http://noovo.ca/videos/rpm-plus/chrysler-imperial',
  17. 'info_dict': {
  18. 'id': '5386045029001',
  19. 'ext': 'mp4',
  20. 'title': 'Chrysler Imperial',
  21. 'description': 'md5:de3c898d1eb810f3e6243e08c8b4a056',
  22. 'timestamp': 1491399228,
  23. 'upload_date': '20170405',
  24. 'uploader_id': '618566855001',
  25. 'series': 'RPM+',
  26. },
  27. 'params': {
  28. 'skip_download': True,
  29. },
  30. }, {
  31. # episode
  32. 'url': 'http://noovo.ca/videos/l-amour-est-dans-le-pre/episode-13-8',
  33. 'info_dict': {
  34. 'id': '5395865725001',
  35. 'title': 'Épisode 13 : Les retrouvailles',
  36. 'description': 'md5:888c3330f0c1b4476c5bc99a1c040473',
  37. 'ext': 'mp4',
  38. 'timestamp': 1492019320,
  39. 'upload_date': '20170412',
  40. 'uploader_id': '618566855001',
  41. 'series': "L'amour est dans le pré",
  42. 'season_number': 5,
  43. 'episode': 'Épisode 13',
  44. 'episode_number': 13,
  45. },
  46. 'params': {
  47. 'skip_download': True,
  48. },
  49. }]
  50. BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/618566855001/default_default/index.html?videoId=%s'
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. webpage = self._download_webpage(url, video_id)
  54. brightcove_id = self._search_regex(
  55. r'data-video-id=["\'](\d+)', webpage, 'brightcove id')
  56. data = self._parse_json(
  57. self._search_regex(
  58. r'(?s)dataLayer\.push\(\s*({.+?})\s*\);', webpage, 'data',
  59. default='{}'),
  60. video_id, transform_source=js_to_json, fatal=False)
  61. title = try_get(
  62. data, lambda x: x['video']['nom'],
  63. compat_str) or self._html_search_meta(
  64. 'dcterms.Title', webpage, 'title', fatal=True)
  65. description = self._html_search_meta(
  66. ('dcterms.Description', 'description'), webpage, 'description')
  67. series = try_get(
  68. data, lambda x: x['emission']['nom']) or self._search_regex(
  69. r'<div[^>]+class="banner-card__subtitle h4"[^>]*>([^<]+)',
  70. webpage, 'series', default=None)
  71. season_el = try_get(data, lambda x: x['emission']['saison'], dict) or {}
  72. season = try_get(season_el, lambda x: x['nom'], compat_str)
  73. season_number = int_or_none(try_get(season_el, lambda x: x['numero']))
  74. episode_el = try_get(season_el, lambda x: x['episode'], dict) or {}
  75. episode = try_get(episode_el, lambda x: x['nom'], compat_str)
  76. episode_number = int_or_none(try_get(episode_el, lambda x: x['numero']))
  77. return {
  78. '_type': 'url_transparent',
  79. 'ie_key': BrightcoveNewIE.ie_key(),
  80. 'url': smuggle_url(
  81. self.BRIGHTCOVE_URL_TEMPLATE % brightcove_id,
  82. {'geo_countries': ['CA']}),
  83. 'id': brightcove_id,
  84. 'title': title,
  85. 'description': description,
  86. 'series': series,
  87. 'season': season,
  88. 'season_number': season_number,
  89. 'episode': episode,
  90. 'episode_number': episode_number,
  91. }