Merge pull request #7691 from ryandesign/use-PYTHON-env-var
[youtube-dl] / youtube_dl / extractor / karrierevideos.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urlparse
6 from ..utils import (
7     fix_xml_ampersands,
8     float_or_none,
9     xpath_with_ns,
10     xpath_text,
11 )
12
13
14 class KarriereVideosIE(InfoExtractor):
15     _VALID_URL = r'http://(?:www\.)?karrierevideos\.at(?:/[^/]+)+/(?P<id>[^/]+)'
16     _TESTS = [{
17         'url': 'http://www.karrierevideos.at/berufsvideos/mittlere-hoehere-schulen/altenpflegerin',
18         'info_dict': {
19             'id': '32c91',
20             'ext': 'flv',
21             'title': 'AltenpflegerIn',
22             'description': 'md5:dbadd1259fde2159a9b28667cb664ae2',
23             'thumbnail': 're:^http://.*\.png',
24         },
25         'params': {
26             # rtmp download
27             'skip_download': True,
28         }
29     }, {
30         # broken ampersands
31         'url': 'http://www.karrierevideos.at/orientierung/vaeterkarenz-und-neue-chancen-fuer-muetter-baby-was-nun',
32         'info_dict': {
33             'id': '5sniu',
34             'ext': 'flv',
35             'title': 'Väterkarenz und neue Chancen für Mütter - "Baby - was nun?"',
36             'description': 'md5:97092c6ad1fd7d38e9d6a5fdeb2bcc33',
37             'thumbnail': 're:^http://.*\.png',
38         },
39         'params': {
40             # rtmp download
41             'skip_download': True,
42         }
43     }]
44
45     def _real_extract(self, url):
46         video_id = self._match_id(url)
47
48         webpage = self._download_webpage(url, video_id)
49
50         title = (self._html_search_meta('title', webpage, default=None) or
51                  self._search_regex(r'<h1 class="title">([^<]+)</h1>'))
52
53         video_id = self._search_regex(
54             r'/config/video/(.+?)\.xml', webpage, 'video id')
55         playlist = self._download_xml(
56             'http://www.karrierevideos.at/player-playlist.xml.php?p=%s' % video_id,
57             video_id, transform_source=fix_xml_ampersands)
58
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')
80
81         thumbnail = self._html_search_meta(
82             'thumbnail', webpage, 'thumbnail')
83         if thumbnail:
84             thumbnail = compat_urlparse.urljoin(url, thumbnail)
85
86         return {
87             'id': video_id,
88             'url': streamer.replace('rtmpt', 'rtmp'),
89             'play_path': 'mp4:%s' % video_file,
90             'ext': 'flv',
91             'title': title,
92             'description': description,
93             'thumbnail': thumbnail,
94             'uploader': uploader,
95             'duration': duration,
96         }