allocine.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. qualities,
  5. remove_end,
  6. strip_or_none,
  7. try_get,
  8. unified_timestamp,
  9. url_basename,
  10. )
  11. class AllocineIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?:article|video|film)/(?:fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=|video-)(?P<id>[0-9]+)(?:\.html)?'
  13. _TESTS = [{
  14. 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
  15. 'md5': '0c9fcf59a841f65635fa300ac43d8269',
  16. 'info_dict': {
  17. 'id': '19546517',
  18. 'display_id': '18635087',
  19. 'ext': 'mp4',
  20. 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
  21. 'description': 'md5:4a754271d9c6f16c72629a8a993ee884',
  22. 'thumbnail': r're:http://.*\.jpg',
  23. 'duration': 39,
  24. 'timestamp': 1404273600,
  25. 'upload_date': '20140702',
  26. 'view_count': int,
  27. },
  28. }, {
  29. 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
  30. 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
  31. 'info_dict': {
  32. 'id': '19540403',
  33. 'display_id': '19540403',
  34. 'ext': 'mp4',
  35. 'title': 'Planes 2 Bande-annonce VF',
  36. 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway',
  37. 'thumbnail': r're:http://.*\.jpg',
  38. 'duration': 69,
  39. 'timestamp': 1385659800,
  40. 'upload_date': '20131128',
  41. 'view_count': int,
  42. },
  43. }, {
  44. 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19544709&cfilm=181290.html',
  45. 'md5': '101250fb127ef9ca3d73186ff22a47ce',
  46. 'info_dict': {
  47. 'id': '19544709',
  48. 'display_id': '19544709',
  49. 'ext': 'mp4',
  50. 'title': 'Dragons 2 - Bande annonce finale VF',
  51. 'description': 'md5:6cdd2d7c2687d4c6aafe80a35e17267a',
  52. 'thumbnail': r're:http://.*\.jpg',
  53. 'duration': 144,
  54. 'timestamp': 1397589900,
  55. 'upload_date': '20140415',
  56. 'view_count': int,
  57. },
  58. }, {
  59. 'url': 'http://www.allocine.fr/video/video-19550147/',
  60. 'md5': '3566c0668c0235e2d224fd8edb389f67',
  61. 'info_dict': {
  62. 'id': '19550147',
  63. 'ext': 'mp4',
  64. 'title': 'Faux Raccord N°123 - Les gaffes de Cliffhanger',
  65. 'description': 'md5:bc734b83ffa2d8a12188d9eb48bb6354',
  66. 'thumbnail': r're:http://.*\.jpg',
  67. },
  68. }]
  69. def _real_extract(self, url):
  70. display_id = self._match_id(url)
  71. webpage = self._download_webpage(url, display_id)
  72. formats = []
  73. quality = qualities(['ld', 'md', 'hd'])
  74. model = self._html_search_regex(
  75. r'data-model="([^"]+)"', webpage, 'data model', default=None)
  76. if model:
  77. model_data = self._parse_json(model, display_id)
  78. video = model_data['videos'][0]
  79. title = video['title']
  80. for video_url in video['sources'].values():
  81. video_id, format_id = url_basename(video_url).split('_')[:2]
  82. formats.append({
  83. 'format_id': format_id,
  84. 'quality': quality(format_id),
  85. 'url': video_url,
  86. })
  87. duration = int_or_none(video.get('duration'))
  88. view_count = int_or_none(video.get('view_count'))
  89. timestamp = unified_timestamp(try_get(
  90. video, lambda x: x['added_at']['date'], str))
  91. else:
  92. video_id = display_id
  93. media_data = self._download_json(
  94. f'http://www.allocine.fr/ws/AcVisiondataV5.ashx?media={video_id}', display_id)
  95. title = remove_end(strip_or_none(self._html_extract_title(webpage), ' - AlloCiné'))
  96. for key, value in media_data['video'].items():
  97. if not key.endswith('Path'):
  98. continue
  99. format_id = key[:-len('Path')]
  100. formats.append({
  101. 'format_id': format_id,
  102. 'quality': quality(format_id),
  103. 'url': value,
  104. })
  105. duration, view_count, timestamp = [None] * 3
  106. return {
  107. 'id': video_id,
  108. 'display_id': display_id,
  109. 'title': title,
  110. 'description': self._og_search_description(webpage),
  111. 'thumbnail': self._og_search_thumbnail(webpage),
  112. 'duration': duration,
  113. 'timestamp': timestamp,
  114. 'view_count': view_count,
  115. 'formats': formats,
  116. }