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