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.

104 lines
3.4 KiB

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