ultimedia.py 3.1 KB

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