[canalc2] Extract duration
[youtube-dl] / 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/(?P<id>\d+)'
13
14     _TEST = {
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         },
22         'params': {
23             'skip_download': True,  # Requires rtmpdump
24         }
25     }
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29         webpage = self._download_webpage(url, video_id)
30         video_url = self._search_regex(
31             r'jwplayer\((["\'])Player\1\)\.setup\({[^}]*file\s*:\s*(["\'])(?P<file>.+?)\2',
32             webpage, 'video_url', group='file')
33         formats = [{'url': video_url}]
34         if video_url.startswith('rtmp://'):
35             rtmp = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
36             formats[0].update({
37                 'url': rtmp.group('url'),
38                 'ext': 'flv',
39                 'app': rtmp.group('app'),
40                 'play_path': rtmp.group('play_path'),
41                 'page_url': url,
42             })
43
44         title = self._html_search_regex(
45             r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.*?)</h3>', webpage, 'title')
46         duration = parse_duration(self._search_regex(
47             r'id=["\']video_duree["\'][^>]*>([^<]+)',
48             webpage, 'duration', fatal=False))
49
50         return {
51             'id': video_id,
52             'title': title,
53             'duration': duration,
54             'formats': formats,
55         }