ultimedia.py 2.9 KB

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