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