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.

110 lines
3.9 KiB

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