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