]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/myspass.py
Update changelog.
[youtubedl] / youtube_dl / extractor / myspass.py
1 import os.path
2 import xml.etree.ElementTree
3
4 from .common import InfoExtractor
5 from ..utils import (
6 compat_urllib_parse_urlparse,
7
8 ExtractorError,
9 )
10
11
12 class MySpassIE(InfoExtractor):
13 _VALID_URL = r'http://www.myspass.de/.*'
14
15 def _real_extract(self, url):
16 META_DATA_URL_TEMPLATE = 'http://www.myspass.de/myspass/includes/apps/video/getvideometadataxml.php?id=%s'
17
18 # video id is the last path element of the URL
19 # usually there is a trailing slash, so also try the second but last
20 url_path = compat_urllib_parse_urlparse(url).path
21 url_parent_path, video_id = os.path.split(url_path)
22 if not video_id:
23 _, video_id = os.path.split(url_parent_path)
24
25 # get metadata
26 metadata_url = META_DATA_URL_TEMPLATE % video_id
27 metadata_text = self._download_webpage(metadata_url, video_id)
28 metadata = xml.etree.ElementTree.fromstring(metadata_text.encode('utf-8'))
29
30 # extract values from metadata
31 url_flv_el = metadata.find('url_flv')
32 if url_flv_el is None:
33 raise ExtractorError(u'Unable to extract download url')
34 video_url = url_flv_el.text
35 extension = os.path.splitext(video_url)[1][1:]
36 title_el = metadata.find('title')
37 if title_el is None:
38 raise ExtractorError(u'Unable to extract title')
39 title = title_el.text
40 format_id_el = metadata.find('format_id')
41 if format_id_el is None:
42 format = 'mp4'
43 else:
44 format = format_id_el.text
45 description_el = metadata.find('description')
46 if description_el is not None:
47 description = description_el.text
48 else:
49 description = None
50 imagePreview_el = metadata.find('imagePreview')
51 if imagePreview_el is not None:
52 thumbnail = imagePreview_el.text
53 else:
54 thumbnail = None
55 info = {
56 'id': video_id,
57 'url': video_url,
58 'title': title,
59 'ext': extension,
60 'format': format,
61 'thumbnail': thumbnail,
62 'description': description
63 }
64 return [info]