]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/movieclips.py
Imported Upstream version 2015.06.04.1
[youtubedl] / youtube_dl / extractor / movieclips.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..compat import (
7 compat_str,
8 )
9 from ..utils import (
10 ExtractorError,
11 clean_html,
12 )
13
14
15 class MovieClipsIE(InfoExtractor):
16 _VALID_URL = r'https?://movieclips\.com/(?P<id>[\da-zA-Z]+)(?:-(?P<display_id>[\da-z-]+))?'
17 _TEST = {
18 'url': 'http://movieclips.com/Wy7ZU-my-week-with-marilyn-movie-do-you-love-me/',
19 'info_dict': {
20 'id': 'Wy7ZU',
21 'display_id': 'my-week-with-marilyn-movie-do-you-love-me',
22 'ext': 'mp4',
23 'title': 'My Week with Marilyn - Do You Love Me?',
24 'description': 'md5:e86795bd332fe3cff461e7c8dc542acb',
25 'thumbnail': 're:^https?://.*\.jpg$',
26 },
27 'params': {
28 # rtmp download
29 'skip_download': True,
30 }
31 }
32
33 def _real_extract(self, url):
34 mobj = re.match(self._VALID_URL, url)
35 video_id = mobj.group('id')
36 display_id = mobj.group('display_id')
37 show_id = display_id or video_id
38
39 config = self._download_xml(
40 'http://config.movieclips.com/player/config/%s' % video_id,
41 show_id, 'Downloading player config')
42
43 if config.find('./country-region').text == 'false':
44 raise ExtractorError(
45 '%s said: %s' % (self.IE_NAME, config.find('./region_alert').text), expected=True)
46
47 properties = config.find('./video/properties')
48 smil_file = properties.attrib['smil_file']
49
50 smil = self._download_xml(smil_file, show_id, 'Downloading SMIL')
51 base_url = smil.find('./head/meta').attrib['base']
52
53 formats = []
54 for video in smil.findall('./body/switch/video'):
55 vbr = int(video.attrib['system-bitrate']) / 1000
56 src = video.attrib['src']
57 formats.append({
58 'url': base_url,
59 'play_path': src,
60 'ext': src.split(':')[0],
61 'vbr': vbr,
62 'format_id': '%dk' % vbr,
63 })
64
65 self._sort_formats(formats)
66
67 title = '%s - %s' % (properties.attrib['clip_movie_title'], properties.attrib['clip_title'])
68 description = clean_html(compat_str(properties.attrib['clip_description']))
69 thumbnail = properties.attrib['image']
70 categories = properties.attrib['clip_categories'].split(',')
71
72 return {
73 'id': video_id,
74 'display_id': display_id,
75 'title': title,
76 'description': description,
77 'thumbnail': thumbnail,
78 'categories': categories,
79 'formats': formats,
80 }