]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/lecture2go.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / lecture2go.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 determine_ext,
6 determine_protocol,
7 parse_duration,
8 int_or_none,
9 )
10
11
12 class Lecture2GoIE(InfoExtractor):
13 _VALID_URL = r'https?://lecture2go\.uni-hamburg\.de/veranstaltungen/-/v/(?P<id>\d+)'
14 _TEST = {
15 'url': 'https://lecture2go.uni-hamburg.de/veranstaltungen/-/v/17473',
16 'md5': 'ac02b570883020d208d405d5a3fd2f7f',
17 'info_dict': {
18 'id': '17473',
19 'ext': 'mp4',
20 'title': '2 - Endliche Automaten und reguläre Sprachen',
21 'creator': 'Frank Heitmann',
22 'duration': 5220,
23 },
24 'params': {
25 # m3u8 download
26 'skip_download': True,
27 }
28 }
29
30 def _real_extract(self, url):
31 video_id = self._match_id(url)
32 webpage = self._download_webpage(url, video_id)
33
34 title = self._html_search_regex(r'<em[^>]+class="title">(.+)</em>', webpage, 'title')
35
36 formats = []
37 for url in set(re.findall(r'var\s+playerUri\d+\s*=\s*"([^"]+)"', webpage)):
38 ext = determine_ext(url)
39 protocol = determine_protocol({'url': url})
40 if ext == 'f4m':
41 formats.extend(self._extract_f4m_formats(url, video_id, f4m_id='hds'))
42 elif ext == 'm3u8':
43 formats.extend(self._extract_m3u8_formats(url, video_id, ext='mp4', m3u8_id='hls'))
44 else:
45 if protocol == 'rtmp':
46 continue # XXX: currently broken
47 formats.append({
48 'format_id': protocol,
49 'url': url,
50 })
51
52 creator = self._html_search_regex(
53 r'<div[^>]+id="description">([^<]+)</div>', webpage, 'creator', fatal=False)
54 duration = parse_duration(self._html_search_regex(
55 r'Duration:\s*</em>\s*<em[^>]*>([^<]+)</em>', webpage, 'duration', fatal=False))
56 view_count = int_or_none(self._html_search_regex(
57 r'Views:\s*</em>\s*<em[^>]+>(\d+)</em>', webpage, 'view count', fatal=False))
58
59 return {
60 'id': video_id,
61 'title': title,
62 'formats': formats,
63 'creator': creator,
64 'duration': duration,
65 'view_count': view_count,
66 }