logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

allocine.py (4962B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. int_or_none,
  7. qualities,
  8. remove_end,
  9. try_get,
  10. unified_timestamp,
  11. url_basename,
  12. )
  13. class AllocineIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?allocine\.fr/(?:article|video|film)/(?:fichearticle_gen_carticle=|player_gen_cmedia=|fichefilm_gen_cfilm=|video-)(?P<id>[0-9]+)(?:\.html)?'
  15. _TESTS = [{
  16. 'url': 'http://www.allocine.fr/article/fichearticle_gen_carticle=18635087.html',
  17. 'md5': '0c9fcf59a841f65635fa300ac43d8269',
  18. 'info_dict': {
  19. 'id': '19546517',
  20. 'display_id': '18635087',
  21. 'ext': 'mp4',
  22. 'title': 'Astérix - Le Domaine des Dieux Teaser VF',
  23. 'description': 'md5:4a754271d9c6f16c72629a8a993ee884',
  24. 'thumbnail': r're:http://.*\.jpg',
  25. 'duration': 39,
  26. 'timestamp': 1404273600,
  27. 'upload_date': '20140702',
  28. 'view_count': int,
  29. },
  30. }, {
  31. 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19540403&cfilm=222257.html',
  32. 'md5': 'd0cdce5d2b9522ce279fdfec07ff16e0',
  33. 'info_dict': {
  34. 'id': '19540403',
  35. 'display_id': '19540403',
  36. 'ext': 'mp4',
  37. 'title': 'Planes 2 Bande-annonce VF',
  38. 'description': 'Regardez la bande annonce du film Planes 2 (Planes 2 Bande-annonce VF). Planes 2, un film de Roberts Gannaway',
  39. 'thumbnail': r're:http://.*\.jpg',
  40. 'duration': 69,
  41. 'timestamp': 1385659800,
  42. 'upload_date': '20131128',
  43. 'view_count': int,
  44. },
  45. }, {
  46. 'url': 'http://www.allocine.fr/video/player_gen_cmedia=19544709&cfilm=181290.html',
  47. 'md5': '101250fb127ef9ca3d73186ff22a47ce',
  48. 'info_dict': {
  49. 'id': '19544709',
  50. 'display_id': '19544709',
  51. 'ext': 'mp4',
  52. 'title': 'Dragons 2 - Bande annonce finale VF',
  53. 'description': 'md5:6cdd2d7c2687d4c6aafe80a35e17267a',
  54. 'thumbnail': r're:http://.*\.jpg',
  55. 'duration': 144,
  56. 'timestamp': 1397589900,
  57. 'upload_date': '20140415',
  58. 'view_count': int,
  59. },
  60. }, {
  61. 'url': 'http://www.allocine.fr/video/video-19550147/',
  62. 'md5': '3566c0668c0235e2d224fd8edb389f67',
  63. 'info_dict': {
  64. 'id': '19550147',
  65. 'ext': 'mp4',
  66. 'title': 'Faux Raccord N°123 - Les gaffes de Cliffhanger',
  67. 'description': 'md5:bc734b83ffa2d8a12188d9eb48bb6354',
  68. 'thumbnail': r're:http://.*\.jpg',
  69. },
  70. }]
  71. def _real_extract(self, url):
  72. display_id = self._match_id(url)
  73. webpage = self._download_webpage(url, display_id)
  74. formats = []
  75. quality = qualities(['ld', 'md', 'hd'])
  76. model = self._html_search_regex(
  77. r'data-model="([^"]+)"', webpage, 'data model', default=None)
  78. if model:
  79. model_data = self._parse_json(model, display_id)
  80. video = model_data['videos'][0]
  81. title = video['title']
  82. for video_url in video['sources'].values():
  83. video_id, format_id = url_basename(video_url).split('_')[:2]
  84. formats.append({
  85. 'format_id': format_id,
  86. 'quality': quality(format_id),
  87. 'url': video_url,
  88. })
  89. duration = int_or_none(video.get('duration'))
  90. view_count = int_or_none(video.get('view_count'))
  91. timestamp = unified_timestamp(try_get(
  92. video, lambda x: x['added_at']['date'], compat_str))
  93. else:
  94. video_id = display_id
  95. media_data = self._download_json(
  96. 'http://www.allocine.fr/ws/AcVisiondataV5.ashx?media=%s' % video_id, display_id)
  97. title = remove_end(
  98. self._html_search_regex(
  99. r'(?s)<title>(.+?)</title>', webpage, 'title').strip(),
  100. ' - AlloCiné')
  101. for key, value in media_data['video'].items():
  102. if not key.endswith('Path'):
  103. continue
  104. format_id = key[:-len('Path')]
  105. formats.append({
  106. 'format_id': format_id,
  107. 'quality': quality(format_id),
  108. 'url': value,
  109. })
  110. duration, view_count, timestamp = [None] * 3
  111. self._sort_formats(formats)
  112. return {
  113. 'id': video_id,
  114. 'display_id': display_id,
  115. 'title': title,
  116. 'description': self._og_search_description(webpage),
  117. 'thumbnail': self._og_search_thumbnail(webpage),
  118. 'duration': duration,
  119. 'timestamp': timestamp,
  120. 'view_count': view_count,
  121. 'formats': formats,
  122. }