digiteka.py 3.2 KB

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