]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/turbo.py
Import Upstream version 2020.01.24
[youtubedl] / youtube_dl / extractor / turbo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 ExtractorError,
10 int_or_none,
11 qualities,
12 xpath_text,
13 )
14
15
16 class TurboIE(InfoExtractor):
17 _VALID_URL = r'https?://(?:www\.)?turbo\.fr/videos-voiture/(?P<id>[0-9]+)-'
18 _API_URL = 'http://www.turbo.fr/api/tv/xml.php?player_generique=player_generique&id={0:}'
19 _TEST = {
20 'url': 'http://www.turbo.fr/videos-voiture/454443-turbo-du-07-09-2014-renault-twingo-3-bentley-continental-gt-speed-ces-guide-achat-dacia.html',
21 'md5': '33f4b91099b36b5d5a91f84b5bcba600',
22 'info_dict': {
23 'id': '454443',
24 'ext': 'mp4',
25 'duration': 3715,
26 'title': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia... ',
27 'description': 'Turbo du 07/09/2014 : Renault Twingo 3, Bentley Continental GT Speed, CES, Guide Achat Dacia...',
28 'thumbnail': r're:^https?://.*\.jpg$',
29 }
30 }
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34 video_id = mobj.group('id')
35
36 webpage = self._download_webpage(url, video_id)
37
38 playlist = self._download_xml(self._API_URL.format(video_id), video_id)
39 item = playlist.find('./channel/item')
40 if item is None:
41 raise ExtractorError('Playlist item was not found', expected=True)
42
43 title = xpath_text(item, './title', 'title')
44 duration = int_or_none(xpath_text(item, './durate', 'duration'))
45 thumbnail = xpath_text(item, './visuel_clip', 'thumbnail')
46 description = self._html_search_meta('description', webpage)
47
48 formats = []
49 get_quality = qualities(['3g', 'sd', 'hq'])
50 for child in item:
51 m = re.search(r'url_video_(?P<quality>.+)', child.tag)
52 if m:
53 quality = compat_str(m.group('quality'))
54 formats.append({
55 'format_id': quality,
56 'url': child.text,
57 'quality': get_quality(quality),
58 })
59 self._sort_formats(formats)
60
61 return {
62 'id': video_id,
63 'title': title,
64 'duration': duration,
65 'thumbnail': thumbnail,
66 'description': description,
67 'formats': formats,
68 }