]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/clubic.py
debian/control: Add B-D on pandoc and zip. Closes: #828905.
[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'https?://(?:www\.)?clubic\.com/video/(?:[^/]+/)*video.*-(?P<id>[0-9]+)\.html'
16
17 _TESTS = [{
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 'url': 'http://www.clubic.com/video/video-clubic-week-2-0-apple-iphone-6s-et-plus-mais-surtout-le-pencil-469792.html',
29 'only_matching': True,
30 }]
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34 video_id = mobj.group('id')
35
36 player_url = 'http://player.m6web.fr/v1/player/clubic/%s.html' % video_id
37 player_page = self._download_webpage(player_url, video_id)
38
39 config_json = self._search_regex(
40 r'(?m)M6\.Player\.config\s*=\s*(\{.+?\});$', player_page,
41 'configuration')
42 config = json.loads(config_json)
43
44 video_info = config['videoInfo']
45 sources = config['sources']
46 quality_order = qualities(['sd', 'hq'])
47
48 formats = [{
49 'format_id': src['streamQuality'],
50 'url': src['src'],
51 'quality': quality_order(src['streamQuality']),
52 } for src in sources]
53 self._sort_formats(formats)
54
55 return {
56 'id': video_id,
57 'title': video_info['title'],
58 'formats': formats,
59 'description': clean_html(video_info.get('description')),
60 'thumbnail': config.get('poster'),
61 }