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