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