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.

86 lines
3.0 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. )
  10. class AllocineIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?P<typ>article|video|film)/(fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=)(?P<id>[0-9]+)(?:\.html)?'
  12. _TESTS = [{
  13. 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
  14. 'md5': '0c9fcf59a841f65635fa300ac43d8269',
  15. 'info_dict': {
  16. 'id': '19546517',
  17. 'ext': 'mp4',
  18. 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
  19. 'description': 'md5:abcd09ce503c6560512c14ebfdb720d2',
  20. 'thumbnail': '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. 'ext': 'mp4',
  28. 'title': 'Planes 2 Bande-annonce VF',
  29. 'description': 'md5:eeaffe7c2d634525e21159b93acf3b1e',
  30. 'thumbnail': 're:http://.*\.jpg',
  31. },
  32. }, {
  33. 'url': 'http://www.allocine.fr/film/fichefilm_gen_cfilm=181290.html',
  34. 'md5': '101250fb127ef9ca3d73186ff22a47ce',
  35. 'info_dict': {
  36. 'id': '19544709',
  37. 'ext': 'mp4',
  38. 'title': 'Dragons 2 - Bande annonce finale VF',
  39. 'description': 'md5:71742e3a74b0d692c7fce0dd2017a4ac',
  40. 'thumbnail': 're:http://.*\.jpg',
  41. },
  42. }]
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. typ = mobj.group('typ')
  46. display_id = mobj.group('id')
  47. webpage = self._download_webpage(url, display_id)
  48. if typ == 'film':
  49. video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
  50. else:
  51. player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player')
  52. player_data = json.loads(player)
  53. video_id = compat_str(player_data['refMedia'])
  54. xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
  55. video = xml.find('.//AcVisionVideo').attrib
  56. quality = qualities(['ld', 'md', 'hd'])
  57. formats = []
  58. for k, v in video.items():
  59. if re.match(r'.+_path', k):
  60. format_id = k.split('_')[0]
  61. formats.append({
  62. 'format_id': format_id,
  63. 'quality': quality(format_id),
  64. 'url': v,
  65. })
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'title': video['videoTitle'],
  70. 'thumbnail': self._og_search_thumbnail(webpage),
  71. 'formats': formats,
  72. 'description': self._og_search_description(webpage),
  73. }