Merge remote-tracking branch 'jaimeMF/yt-toplists'
[youtube-dl] / youtube_dl / extractor / myspass.py
1 import os.path
2
3 from .common import InfoExtractor
4 from ..utils import (
5     compat_urllib_parse_urlparse,
6
7     ExtractorError,
8 )
9
10
11 class MySpassIE(InfoExtractor):
12     _VALID_URL = r'http://www\.myspass\.de/.*'
13     _TEST = {
14         u'url': u'http://www.myspass.de/myspass/shows/tvshows/absolute-mehrheit/Absolute-Mehrheit-vom-17022013-Die-Highlights-Teil-2--/11741/',
15         u'file': u'11741.mp4',
16         u'md5': u'0b49f4844a068f8b33f4b7c88405862b',
17         u'info_dict': {
18             u"description": u"Wer kann in die Fu\u00dfstapfen von Wolfgang Kubicki treten und die Mehrheit der Zuschauer hinter sich versammeln? Wird vielleicht sogar die Absolute Mehrheit geknackt und der Jackpot von 200.000 Euro mit nach Hause genommen?", 
19             u"title": u"Absolute Mehrheit vom 17.02.2013 - Die Highlights, Teil 2"
20         }
21     }
22
23     def _real_extract(self, url):
24         META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
25
26         # video id is the last path element of the URL
27         # usually there is a trailing slash, so also try the second but last
28         url_path = compat_urllib_parse_urlparse(url).path
29         url_parent_path, video_id = os.path.split(url_path)
30         if not video_id:
31             _, video_id = os.path.split(url_parent_path)
32
33         # get metadata
34         metadata_url = META_DATA_URL_TEMPLATE % video_id
35         metadata = self._download_xml(metadata_url, video_id)
36
37         # extract values from metadata
38         url_flv_el = metadata.find('url_flv')
39         if url_flv_el is None:
40             raise ExtractorError(u'Unable to extract download url')
41         video_url = url_flv_el.text
42         extension = os.path.splitext(video_url)[1][1:]
43         title_el = metadata.find('title')
44         if title_el is None:
45             raise ExtractorError(u'Unable to extract title')
46         title = title_el.text
47         format_id_el = metadata.find('format_id')
48         if format_id_el is None:
49             format = 'mp4'
50         else:
51             format = format_id_el.text
52         description_el = metadata.find('description')
53         if description_el is not None:
54             description = description_el.text
55         else:
56             description = None
57         imagePreview_el = metadata.find('imagePreview')
58         if imagePreview_el is not None:
59             thumbnail = imagePreview_el.text
60         else:
61             thumbnail = None
62         info = {
63             'id': video_id,
64             'url': video_url,
65             'title': title,
66             'ext': extension,
67             'format': format,
68             'thumbnail': thumbnail,
69             'description': description
70         }
71         return [info]