]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/karrierevideos.py
[ie/generic] Improve direct video link ext detection (#8340)
[yt-dlp.git] / yt_dlp / extractor / karrierevideos.py
CommitLineData
725652e9 1from .common import InfoExtractor
d78c834e
S
2from ..compat import compat_urlparse
3from ..utils import (
4 fix_xml_ampersands,
5 float_or_none,
6 xpath_with_ns,
7 xpath_text,
8)
725652e9
MH
9
10
11class KarriereVideosIE(InfoExtractor):
5886b38d 12 _VALID_URL = r'https?://(?:www\.)?karrierevideos\.at(?:/[^/]+)+/(?P<id>[^/]+)'
d78c834e 13 _TESTS = [{
725652e9
MH
14 'url': 'http://www.karrierevideos.at/berufsvideos/mittlere-hoehere-schulen/altenpflegerin',
15 'info_dict': {
d78c834e
S
16 'id': '32c91',
17 'ext': 'flv',
725652e9 18 'title': 'AltenpflegerIn',
d78c834e 19 'description': 'md5:dbadd1259fde2159a9b28667cb664ae2',
ec85ded8 20 'thumbnail': r're:^http://.*\.png',
725652e9
MH
21 },
22 'params': {
d78c834e
S
23 # rtmp download
24 'skip_download': True,
725652e9 25 }
d78c834e
S
26 }, {
27 # broken ampersands
28 'url': 'http://www.karrierevideos.at/orientierung/vaeterkarenz-und-neue-chancen-fuer-muetter-baby-was-nun',
29 'info_dict': {
30 'id': '5sniu',
31 'ext': 'flv',
32 'title': 'Väterkarenz und neue Chancen für Mütter - "Baby - was nun?"',
33 'description': 'md5:97092c6ad1fd7d38e9d6a5fdeb2bcc33',
ec85ded8 34 'thumbnail': r're:^http://.*\.png',
d78c834e
S
35 },
36 'params': {
37 # rtmp download
38 'skip_download': True,
39 }
40 }]
725652e9
MH
41
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
d78c834e 44
725652e9
MH
45 webpage = self._download_webpage(url, video_id)
46
3089bc74
S
47 title = (self._html_search_meta('title', webpage, default=None)
48 or self._search_regex(r'<h1 class="title">([^<]+)</h1>', webpage, 'video title'))
725652e9 49
d78c834e
S
50 video_id = self._search_regex(
51 r'/config/video/(.+?)\.xml', webpage, 'video id')
f141fefa
YCH
52 # Server returns malformed headers
53 # Force Accept-Encoding: * to prevent gzipped results
725652e9 54 playlist = self._download_xml(
d78c834e 55 'http://www.karrierevideos.at/player-playlist.xml.php?p=%s' % video_id,
f141fefa
YCH
56 video_id, transform_source=fix_xml_ampersands,
57 headers={'Accept-Encoding': '*'})
725652e9 58
d78c834e
S
59 NS_MAP = {
60 'jwplayer': 'http://developer.longtailvideo.com/trac/wiki/FlashFormats'
61 }
62
63 def ns(path):
64 return xpath_with_ns(path, NS_MAP)
65
66 item = playlist.find('./tracklist/item')
67 video_file = xpath_text(
68 item, ns('./jwplayer:file'), 'video url', fatal=True)
69 streamer = xpath_text(
70 item, ns('./jwplayer:streamer'), 'streamer', fatal=True)
71
72 uploader = xpath_text(
73 item, ns('./jwplayer:author'), 'uploader')
74 duration = float_or_none(
75 xpath_text(item, ns('./jwplayer:duration'), 'duration'))
76
77 description = self._html_search_regex(
78 r'(?s)<div class="leadtext">(.+?)</div>',
79 webpage, 'description')
725652e9 80
d78c834e
S
81 thumbnail = self._html_search_meta(
82 'thumbnail', webpage, 'thumbnail')
83 if thumbnail:
84 thumbnail = compat_urlparse.urljoin(url, thumbnail)
725652e9
MH
85
86 return {
87 'id': video_id,
d78c834e
S
88 'url': streamer.replace('rtmpt', 'rtmp'),
89 'play_path': 'mp4:%s' % video_file,
90 'ext': 'flv',
91 'title': title,
725652e9 92 'description': description,
d78c834e
S
93 'thumbnail': thumbnail,
94 'uploader': uploader,
95 'duration': duration,
725652e9 96 }