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.

95 lines
3.5 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor
  6. from ..compat import compat_str
  7. from ..utils import (
  8. qualities,
  9. unescapeHTML,
  10. xpath_element,
  11. )
  12. class AllocineIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?P<typ>article|video|film)/(fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=|video-)(?P<id>[0-9]+)(?:\.html)?'
  14. _TESTS = [{
  15. 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
  16. 'md5': '0c9fcf59a841f65635fa300ac43d8269',
  17. 'info_dict': {
  18. 'id': '19546517',
  19. 'ext': 'mp4',
  20. 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
  21. 'description': 'md5:abcd09ce503c6560512c14ebfdb720d2',
  22. 'thumbnail': 're:http://.*\.jpg',
  23. },
  24. }, {
  25. 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
  26. 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
  27. 'info_dict': {
  28. 'id': '19540403',
  29. 'ext': 'mp4',
  30. 'title': 'Planes 2 Bande-annonce VF',
  31. 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway',
  32. 'thumbnail': 're:http://.*\.jpg',
  33. },
  34. }, {
  35. 'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html',
  36. 'md5': '101250fb127ef9ca3d73186ff22a47ce',
  37. 'info_dict': {
  38. 'id': '19544709',
  39. 'ext': 'mp4',
  40. 'title': 'Dragons 2 - Bande annonce finale VF',
  41. 'description': 'md5:601d15393ac40f249648ef000720e7e3',
  42. 'thumbnail': 're:http://.*\.jpg',
  43. },
  44. }, {
  45. 'url': 'http://www.allocine.fr/video/video-19550147/',
  46. 'only_matching': True,
  47. }]
  48. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. typ = mobj.group('typ')
  51. display_id = mobj.group('id')
  52. webpage = self._download_webpage(url, display_id)
  53. if typ == 'film':
  54. video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
  55. else:
  56. player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player', default=None)
  57. if player:
  58. player_data = json.loads(player)
  59. video_id = compat_str(player_data['refMedia'])
  60. else:
  61. model = self._search_regex(r'data-model="([^"]+)">', webpage, 'data model')
  62. model_data = self._parse_json(unescapeHTML(model), display_id)
  63. video_id = compat_str(model_data['id'])
  64. xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
  65. video = xpath_element(xml, './/AcVisionVideo').attrib
  66. quality = qualities(['ld', 'md', 'hd'])
  67. formats = []
  68. for k, v in video.items():
  69. if re.match(r'.+_path', k):
  70. format_id = k.split('_')[0]
  71. formats.append({
  72. 'format_id': format_id,
  73. 'quality': quality(format_id),
  74. 'url': v,
  75. })
  76. self._sort_formats(formats)
  77. return {
  78. 'id': video_id,
  79. 'title': video['videoTitle'],
  80. 'thumbnail': self._og_search_thumbnail(webpage),
  81. 'formats': formats,
  82. 'description': self._og_search_description(webpage),
  83. }