allocine.py 3.4 KB

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