]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clubic.py
debian/control: Add recommends on aria2 | wget | curl to use external downloaders.
[youtubedl] / youtube_dl / extractor / clubic.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import json
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9 clean_html,
10 qualities,
11 )
12
13
14 class ClubicIE(InfoExtractor):
15 _VALID_URL = r'http://(?:www\.)?clubic\.com/video/[^/]+/video.*-(?P<id>[0-9]+)\.html'
16
17 _TEST = {
18 'url': 'http://www.clubic.com/video/clubic-week/video-clubic-week-2-0-le-fbi-se-lance-dans-la-photo-d-identite-448474.html',
19 'md5': '1592b694ba586036efac1776b0b43cd3',
20 'info_dict': {
21 'id': '448474',
22 'ext': 'mp4',
23 'title': 'Clubic Week 2.0 : le FBI se lance dans la photo d\u0092identité',
24 'description': 're:Gueule de bois chez Nokia. Le constructeur a indiqué cette.*',
25 'thumbnail': 're:^http://img\.clubic\.com/.*\.jpg$',
26 }
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32
33 player_url = 'http://player.m6web.fr/v1/player/clubic/%s.html' % video_id
34 player_page = self._download_webpage(player_url, video_id)
35
36 config_json = self._search_regex(
37 r'(?m)M6\.Player\.config\s*=\s*(\{.+?\});$', player_page,
38 'configuration')
39 config = json.loads(config_json)
40
41 video_info = config['videoInfo']
42 sources = config['sources']
43 quality_order = qualities(['sd', 'hq'])
44
45 formats = [{
46 'format_id': src['streamQuality'],
47 'url': src['src'],
48 'quality': quality_order(src['streamQuality']),
49 } for src in sources]
50 self._sort_formats(formats)
51
52 return {
53 'id': video_id,
54 'title': video_info['title'],
55 'formats': formats,
56 'description': clean_html(video_info.get('description')),
57 'thumbnail': config.get('poster'),
58 }