]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/dhm.py
Credit @ossi96 for dhm (#5305)
[youtube-dl] / youtube_dl / extractor / dhm.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     xpath_text,
6     parse_duration,
7 )
8
9
10 class DHMIE(InfoExtractor):
11     IE_DESC = 'Filmarchiv - Deutsches Historisches Museum'
12     _VALID_URL = r'http://www\.dhm\.de/filmarchiv/die-filme/(?P<id>[^/]+)'
13
14     _TEST = {
15         'url': 'http://www.dhm.de/filmarchiv/die-filme/the-marshallplan-at-work-in-west-germany/',
16         'md5': '11c475f670209bf6acca0b2b7ef51827',
17         'info_dict': {
18             'id': 'the-marshallplan-at-work-in-west-germany',
19             'ext': 'flv',
20             'title': 'MARSHALL PLAN AT WORK IN WESTERN GERMANY, THE',
21             'description': 'md5:1fabd480c153f97b07add61c44407c82',
22             'duration': 660,
23             'thumbnail': 're:^https?://.*\.jpg$',
24         }
25     }
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29
30         webpage = self._download_webpage(url, video_id)
31
32         playlist_url = self._search_regex(
33             r"file\s*:\s*'([^']+)'", webpage, 'playlist url')
34
35         playlist = self._download_xml(playlist_url, video_id)
36
37         track = playlist.find(
38             './{http://xspf.org/ns/0/}trackList/{http://xspf.org/ns/0/}track')
39
40         video_url = xpath_text(
41             track, './{http://xspf.org/ns/0/}location',
42             'video url', fatal=True)
43         thumbnail = xpath_text(
44             track, './{http://xspf.org/ns/0/}image',
45             'thumbnail')
46
47         title = self._search_regex(
48             [r'dc:title="([^"]+)"', r'<title> &raquo;([^<]+)</title>'],
49             webpage, 'title').strip()
50         description = self._html_search_regex(
51             r'<p><strong>Description:</strong>(.+?)</p>',
52             webpage, 'description', fatal=False)
53         duration = parse_duration(self._search_regex(
54             r'<em>Length\s*</em>\s*:\s*</strong>([^<]+)',
55             webpage, 'duration', fatal=False))
56
57         return {
58             'id': video_id,
59             'url': video_url,
60             'title': title,
61             'description': description,
62             'duration': duration,
63             'thumbnail': thumbnail,
64         }