]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/canalc2.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / canalc2.py
CommitLineData
cd0abcc0 1import re
cd0abcc0
PR
2
3from .common import InfoExtractor
b1bf0635 4from ..utils import parse_duration
cd0abcc0 5
e86ea47c 6
cd0abcc0 7class Canalc2IE(InfoExtractor):
6b361ad5 8 IE_NAME = 'canalc2.tv'
7a34302e 9 _VALID_URL = r'https?://(?:(?:www\.)?canalc2\.tv/video/|archives-canalc2\.u-strasbg\.fr/video\.asp\?.*\bidVideo=)(?P<id>\d+)'
cd0abcc0 10
7a34302e 11 _TESTS = [{
b0f001a6 12 'url': 'http://www.canalc2.tv/video/12163',
0568c352
PH
13 'md5': '060158428b650f896c542dfbb3d6487f',
14 'info_dict': {
15 'id': '12163',
dde97ea8 16 'ext': 'mp4',
608945d4
S
17 'title': 'Terrasses du Numérique',
18 'duration': 122,
b0f001a6 19 },
7a34302e
S
20 }, {
21 'url': 'http://archives-canalc2.u-strasbg.fr/video.asp?idVideo=11427&voir=oui',
22 'only_matching': True,
23 }]
cd0abcc0
PR
24
25 def _real_extract(self, url):
b0f001a6 26 video_id = self._match_id(url)
7a34302e
S
27
28 webpage = self._download_webpage(
add96eb9 29 f'http://www.canalc2.tv/video/{video_id}', video_id)
7a34302e 30
38f59e27
S
31 title = self._html_search_regex(
32 r'(?s)class="[^"]*col_description[^"]*">.*?<h3>(.+?)</h3>',
33 webpage, 'title')
34
7a34302e
S
35 formats = []
36 for _, video_url in re.findall(r'file\s*=\s*(["\'])(.+?)\1', webpage):
37 if video_url.startswith('rtmp://'):
38 rtmp = re.search(
39 r'^(?P<url>rtmp://[^/]+/(?P<app>.+/))(?P<play_path>mp4:.+)$', video_url)
40 formats.append({
41 'url': rtmp.group('url'),
42 'format_id': 'rtmp',
43 'ext': 'flv',
44 'app': rtmp.group('app'),
45 'play_path': rtmp.group('play_path'),
46 'page_url': url,
47 })
48 else:
49 formats.append({
50 'url': video_url,
51 'format_id': 'http',
52 })
ff242459 53
38f59e27
S
54 if formats:
55 info = {
56 'formats': formats,
57 }
58 else:
59 info = self._parse_html5_media_entries(url, webpage, url)[0]
60
38f59e27 61 info.update({
0568c352 62 'id': video_id,
0568c352 63 'title': title,
38f59e27
S
64 'duration': parse_duration(self._search_regex(
65 r'id=["\']video_duree["\'][^>]*>([^<]+)',
66 webpage, 'duration', fatal=False)),
67 })
68 return info