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.

109 lines
3.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class UltimediaIE(InfoExtractor):
  7. _VALID_URL = r'''(?x)
  8. https?://(?:www\.)?ultimedia\.com/
  9. (?:
  10. deliver/
  11. (?P<embed_type>
  12. generic|
  13. musique
  14. )
  15. (?:/[^/]+)*/
  16. (?:
  17. src|
  18. article
  19. )|
  20. default/index/video
  21. (?P<site_type>
  22. generic|
  23. music
  24. )
  25. /id
  26. )/(?P<id>[\d+a-z]+)'''
  27. _TESTS = [{
  28. # news
  29. 'url': 'https://www.ultimedia.com/default/index/videogeneric/id/s8uk0r',
  30. 'md5': '276a0e49de58c7e85d32b057837952a2',
  31. 'info_dict': {
  32. 'id': 's8uk0r',
  33. 'ext': 'mp4',
  34. 'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
  35. 'thumbnail': 're:^https?://.*\.jpg',
  36. 'duration': 74,
  37. 'upload_date': '20150317',
  38. 'timestamp': 1426604939,
  39. 'uploader_id': '3fszv',
  40. },
  41. }, {
  42. # music
  43. 'url': 'https://www.ultimedia.com/default/index/videomusic/id/xvpfp8',
  44. 'md5': '2ea3513813cf230605c7e2ffe7eca61c',
  45. 'info_dict': {
  46. 'id': 'xvpfp8',
  47. 'ext': 'mp4',
  48. 'title': 'Two - C\'est La Vie (clip)',
  49. 'thumbnail': 're:^https?://.*\.jpg',
  50. 'duration': 233,
  51. 'upload_date': '20150224',
  52. 'timestamp': 1424760500,
  53. 'uploader_id': '3rfzk',
  54. },
  55. }]
  56. @staticmethod
  57. def _extract_url(webpage):
  58. mobj = re.search(
  59. r'<(?:iframe|script)[^>]+src=["\'](?P<url>(?:https?:)?//(?:www\.)?ultimedia\.com/deliver/(?:generic|musique)(?:/[^/]+)*/(?:src|article)/[\d+a-z]+)',
  60. webpage)
  61. if mobj:
  62. return mobj.group('url')
  63. def _real_extract(self, url):
  64. mobj = re.match(self._VALID_URL, url)
  65. video_id = mobj.group('id')
  66. video_type = mobj.group('embed_type') or mobj.group('site_type')
  67. if video_type == 'music':
  68. video_type = 'musique'
  69. deliver_info = self._download_json(
  70. 'http://www.ultimedia.com/deliver/video?video=%s&topic=%s' % (video_id, video_type),
  71. video_id)
  72. yt_id = deliver_info.get('yt_id')
  73. if yt_id:
  74. return self.url_result(yt_id, 'Youtube')
  75. jwconf = deliver_info['jwconf']
  76. formats = []
  77. for source in jwconf['playlist'][0]['sources']:
  78. formats.append({
  79. 'url': source['file'],
  80. 'format_id': source.get('label'),
  81. })
  82. self._sort_formats(formats)
  83. title = deliver_info['title']
  84. thumbnail = jwconf.get('image')
  85. duration = int_or_none(deliver_info.get('duration'))
  86. timestamp = int_or_none(deliver_info.get('release_time'))
  87. uploader_id = deliver_info.get('owner_id')
  88. return {
  89. 'id': video_id,
  90. 'title': title,
  91. 'thumbnail': thumbnail,
  92. 'duration': duration,
  93. 'timestamp': timestamp,
  94. 'uploader_id': uploader_id,
  95. 'formats': formats,
  96. }