]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/canalc2.py
debian/copyright: Use HTTPS for Format: field.
[youtubedl] / youtube_dl / extractor / canalc2.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 parse_duration
8
9
10 class Canalc2IE(InfoExtractor):
11 IE_NAME = 'canalc2.tv'
12 _VALID_URL = r'https?://(?:(?:www\.)?canalc2\.tv/video/|archives-canalc2\.u-strasbg\.fr/video\.asp\?.*\bidVideo=)(?P<id>\d+)'
13
14 _TESTS = [{
15 'url': 'http://www.canalc2.tv/video/12163',
16 'md5': '060158428b650f896c542dfbb3d6487f',
17 'info_dict': {
18 'id': '12163',
19 'ext': 'mp4',
20 'title': 'Terrasses du Numérique',
21 'duration': 122,
22 },
23 }, {
24 'url': 'http://archives-canalc2.u-strasbg.fr/video.asp?idVideo=11427&voir=oui',
25 'only_matching': True,
26 }]
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30
31 webpage = self._download_webpage(
32 'http://www.canalc2.tv/video/%s' % video_id, video_id)
33
34 formats = []
35 for _, video_url in re.findall(r'file\s*=\s*(["\'])(.+?)\1', webpage):
36 if video_url.startswith('rtmp://'):
37 rtmp = re.search(
38 r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
39 formats.append({
40 'url': rtmp.group('url'),
41 'format_id': 'rtmp',
42 'ext': 'flv',
43 'app': rtmp.group('app'),
44 'play_path': rtmp.group('play_path'),
45 'page_url': url,
46 })
47 else:
48 formats.append({
49 'url': video_url,
50 'format_id': 'http',
51 })
52 self._sort_formats(formats)
53
54 title = self._html_search_regex(
55 r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.*?)</h3>', webpage, 'title')
56 duration = parse_duration(self._search_regex(
57 r'id=["\']video_duree["\'][^>]*>([^<]+)',
58 webpage, 'duration', fatal=False))
59
60 return {
61 'id': video_id,
62 'title': title,
63 'duration': duration,
64 'formats': formats,
65 }