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.

105 lines
3.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse_urlparse
  6. from ..utils import (
  7. ExtractorError,
  8. qualities,
  9. unified_strdate,
  10. clean_html,
  11. )
  12. class UltimediaIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?ultimedia\.com/default/index/video[^/]+/id/(?P<id>[\d+a-z]+)'
  14. _TESTS = [{
  15. # news
  16. 'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
  17. 'md5': '276a0e49de58c7e85d32b057837952a2',
  18. 'info_dict': {
  19. 'id': 's8uk0r',
  20. 'ext': 'mp4',
  21. 'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
  22. 'description': 'md5:3e5c8fd65791487333dda5db8aed32af',
  23. 'thumbnail': 're:^https?://.*\.jpg',
  24. 'upload_date': '20150317',
  25. },
  26. }, {
  27. # music
  28. 'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
  29. 'md5': '2ea3513813cf230605c7e2ffe7eca61c',
  30. 'info_dict': {
  31. 'id': 'xvpfp8',
  32. 'ext': 'mp4',
  33. 'title': "Two - C'est la vie (Clip)",
  34. 'description': 'Two',
  35. 'thumbnail': 're:^https?://.*\.jpg',
  36. 'upload_date': '20150224',
  37. },
  38. }]
  39. def _real_extract(self, url):
  40. video_id = self._match_id(url)
  41. webpage = self._download_webpage(url, video_id)
  42. deliver_url = self._proto_relative_url(self._search_regex(
  43. r'<iframe[^>]+src="((?:https?:)?//(?:www\.)?ultimedia\.com/deliver/[^"]+)"',
  44. webpage, 'deliver URL'), compat_urllib_parse_urlparse(url).scheme + ':')
  45. deliver_page = self._download_webpage(
  46. deliver_url, video_id, 'Downloading iframe page')
  47. if '>This video is currently not available' in deliver_page:
  48. raise ExtractorError(
  49. 'Video %s is currently not available' % video_id, expected=True)
  50. player = self._parse_json(
  51. self._search_regex(
  52. r"jwplayer\('player(?:_temp)?'\)\.setup\(({.+?})\)\.on",
  53. deliver_page, 'player'),
  54. video_id)
  55. quality = qualities(['flash', 'html5'])
  56. formats = []
  57. for mode in player['modes']:
  58. video_url = mode.get('config', {}).get('file')
  59. if not video_url:
  60. continue
  61. if re.match(r'https?://www\.youtube\.com/.+?', video_url):
  62. return self.url_result(video_url, 'Youtube')
  63. formats.append({
  64. 'url': video_url,
  65. 'format_id': mode.get('type'),
  66. 'quality': quality(mode.get('type')),
  67. })
  68. self._sort_formats(formats)
  69. thumbnail = player.get('image')
  70. title = clean_html((
  71. self._html_search_regex(
  72. r'(?s)<div\s+id="catArticle">.+?</div>(.+?)</h1>',
  73. webpage, 'title', default=None) or
  74. self._search_regex(
  75. r"var\s+nameVideo\s*=\s*'([^']+)'",
  76. deliver_page, 'title')))
  77. description = clean_html(self._html_search_regex(
  78. r'(?s)<span>Description</span>(.+?)</p>', webpage,
  79. 'description', fatal=False))
  80. upload_date = unified_strdate(self._search_regex(
  81. r'Ajouté le\s*<span>([^<]+)', webpage,
  82. 'upload date', fatal=False))
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description,
  87. 'thumbnail': thumbnail,
  88. 'upload_date': upload_date,
  89. 'formats': formats,
  90. }