ultimedia.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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'https?://(?:www\.)?ultimedia\.com/deliver/(?P<type>generic|musique)(?:/[^/]+)*/(?:src|article)/(?P<id>[\d+a-z]+)'
  8. _TESTS = [{
  9. # news
  10. 'url': 'https://www.ultimedia.com/deliver/generic/iframe/mdtk/01601930/zone/1/src/s8uk0r/autoplay/yes/ad/no/width/714/height/435',
  11. 'md5': '276a0e49de58c7e85d32b057837952a2',
  12. 'info_dict': {
  13. 'id': 's8uk0r',
  14. 'ext': 'mp4',
  15. 'title': 'Loi sur la fin de vie: le texte prévoit un renforcement des directives anticipées',
  16. 'thumbnail': 're:^https?://.*\.jpg',
  17. 'duration': 74,
  18. 'upload_date': '20150317',
  19. 'timestamp': 1426604939,
  20. 'uploader_id': '3fszv',
  21. },
  22. }, {
  23. # music
  24. 'url': 'https://www.ultimedia.com/deliver/musique/iframe/mdtk/01601930/zone/1/article/xvpfp8/autoplay/yes/ad/no/width/714/height/435',
  25. 'md5': '2ea3513813cf230605c7e2ffe7eca61c',
  26. 'info_dict': {
  27. 'id': 'xvpfp8',
  28. 'ext': 'mp4',
  29. 'title': 'Two - C\'est La Vie (clip)',
  30. 'thumbnail': 're:^https?://.*\.jpg',
  31. 'duration': 233,
  32. 'upload_date': '20150224',
  33. 'timestamp': 1424760500,
  34. 'uploader_id': '3rfzk',
  35. },
  36. }]
  37. @staticmethod
  38. def _extract_url(webpage):
  39. mobj = re.search(
  40. r'<(?:iframe|script)[^>]+src=["\'](?P<url>(?:https?:)?//(?:www\.)?ultimedia\.com/deliver/(?:generic|musique)(?:/[^/]+)*/(?:src|article)/[\d+a-z]+)',
  41. webpage)
  42. if mobj:
  43. return mobj.group('url')
  44. def _real_extract(self, url):
  45. video_type, video_id = re.match(self._VALID_URL, url).groups()
  46. deliver_info = self._download_json(
  47. 'http://www.ultimedia.com/deliver/video?video=%s&topic=%s' % (video_id, video_type),
  48. video_id)
  49. yt_id = deliver_info.get('yt_id')
  50. if yt_id:
  51. return self.url_result(yt_id, 'Youtube')
  52. jwconf = deliver_info['jwconf']
  53. formats = []
  54. for source in jwconf['playlist'][0]['sources']:
  55. formats.append({
  56. 'url': source['file'],
  57. 'format_id': source.get('label'),
  58. })
  59. self._sort_formats(formats)
  60. title = deliver_info['title']
  61. thumbnail = jwconf.get('image')
  62. duration = int_or_none(deliver_info.get('duration'))
  63. timestamp = int_or_none(deliver_info.get('release_time'))
  64. uploader_id = deliver_info.get('owner_id')
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'thumbnail': thumbnail,
  69. 'duration': duration,
  70. 'timestamp': timestamp,
  71. 'uploader_id': uploader_id,
  72. 'formats': formats,
  73. }