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.

89 lines
3.1 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=|video-)(?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. 'url': 'http://www.allocine.fr/video/video-19550147/',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. mobj = re.match(self._VALID_URL, url)
  48. typ = mobj.group('typ')
  49. display_id = mobj.group('id')
  50. webpage = self._download_webpage(url, display_id)
  51. if typ == 'film':
  52. video_id = self._search_regex(r'href="/video/player_gen_cmedia=([0-9]+).+"', webpage, 'video id')
  53. else:
  54. player = self._search_regex(r'data-player=\'([^\']+)\'>', webpage, 'data player')
  55. player_data = json.loads(player)
  56. video_id = compat_str(player_data['refMedia'])
  57. xml = self._download_xml('http://www.allocine.fr/ws/AcVisiondataV4.ashx?media=%s' % video_id, display_id)
  58. video = xml.find('.//AcVisionVideo').attrib
  59. quality = qualities(['ld', 'md', 'hd'])
  60. formats = []
  61. for k, v in video.items():
  62. if re.match(r'.+_path', k):
  63. format_id = k.split('_')[0]
  64. formats.append({
  65. 'format_id': format_id,
  66. 'quality': quality(format_id),
  67. 'url': v,
  68. })
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'title': video['videoTitle'],
  73. 'thumbnail': self._og_search_thumbnail(webpage),
  74. 'formats': formats,
  75. 'description': self._og_search_description(webpage),
  76. }