]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/springboardplatform.py
debian/control: Set 'Rules-Requires-Root: no'.
[youtubedl] / youtube_dl / extractor / springboardplatform.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 ExtractorError,
9 int_or_none,
10 xpath_attr,
11 xpath_text,
12 xpath_element,
13 unescapeHTML,
14 unified_timestamp,
15 )
16
17
18 class SpringboardPlatformIE(InfoExtractor):
19 _VALID_URL = r'''(?x)
20 https?://
21 cms\.springboardplatform\.com/
22 (?:
23 (?:previews|embed_iframe)/(?P<index>\d+)/video/(?P<id>\d+)|
24 xml_feeds_advanced/index/(?P<index_2>\d+)/rss3/(?P<id_2>\d+)
25 )
26 '''
27 _TESTS = [{
28 'url': 'http://cms.springboardplatform.com/previews/159/video/981017/0/0/1',
29 'md5': '5c3cb7b5c55740d482561099e920f192',
30 'info_dict': {
31 'id': '981017',
32 'ext': 'mp4',
33 'title': 'Redman "BUD like YOU" "Usher Good Kisser" REMIX',
34 'description': 'Redman "BUD like YOU" "Usher Good Kisser" REMIX',
35 'thumbnail': r're:^https?://.*\.jpg$',
36 'timestamp': 1409132328,
37 'upload_date': '20140827',
38 'duration': 193,
39 },
40 }, {
41 'url': 'http://cms.springboardplatform.com/embed_iframe/159/video/981017/rab007/rapbasement.com/1/1',
42 'only_matching': True,
43 }, {
44 'url': 'http://cms.springboardplatform.com/embed_iframe/20/video/1731611/ki055/kidzworld.com/10',
45 'only_matching': True,
46 }, {
47 'url': 'http://cms.springboardplatform.com/xml_feeds_advanced/index/159/rss3/981017/0/0/1/',
48 'only_matching': True,
49 }]
50
51 @staticmethod
52 def _extract_urls(webpage):
53 return [
54 mobj.group('url')
55 for mobj in re.finditer(
56 r'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//cms\.springboardplatform\.com/embed_iframe/\d+/video/\d+.*?)\1',
57 webpage)]
58
59 def _real_extract(self, url):
60 mobj = re.match(self._VALID_URL, url)
61 video_id = mobj.group('id') or mobj.group('id_2')
62 index = mobj.group('index') or mobj.group('index_2')
63
64 video = self._download_xml(
65 'http://cms.springboardplatform.com/xml_feeds_advanced/index/%s/rss3/%s'
66 % (index, video_id), video_id)
67
68 item = xpath_element(video, './/item', 'item', fatal=True)
69
70 content = xpath_element(
71 item, './{http://search.yahoo.com/mrss/}content', 'content',
72 fatal=True)
73 title = unescapeHTML(xpath_text(item, './title', 'title', fatal=True))
74
75 video_url = content.attrib['url']
76
77 if 'error_video.mp4' in video_url:
78 raise ExtractorError(
79 'Video %s no longer exists' % video_id, expected=True)
80
81 duration = int_or_none(content.get('duration'))
82 tbr = int_or_none(content.get('bitrate'))
83 filesize = int_or_none(content.get('fileSize'))
84 width = int_or_none(content.get('width'))
85 height = int_or_none(content.get('height'))
86
87 description = unescapeHTML(xpath_text(
88 item, './description', 'description'))
89 thumbnail = xpath_attr(
90 item, './{http://search.yahoo.com/mrss/}thumbnail', 'url',
91 'thumbnail')
92
93 timestamp = unified_timestamp(xpath_text(
94 item, './{http://cms.springboardplatform.com/namespaces.html}created',
95 'timestamp'))
96
97 formats = [{
98 'url': video_url,
99 'format_id': 'http',
100 'tbr': tbr,
101 'filesize': filesize,
102 'width': width,
103 'height': height,
104 }]
105
106 m3u8_format = formats[0].copy()
107 m3u8_format.update({
108 'url': re.sub(r'(https?://)cdn\.', r'\1hls.', video_url) + '.m3u8',
109 'ext': 'mp4',
110 'format_id': 'hls',
111 'protocol': 'm3u8_native',
112 })
113 formats.append(m3u8_format)
114
115 self._sort_formats(formats)
116
117 return {
118 'id': video_id,
119 'title': title,
120 'description': description,
121 'thumbnail': thumbnail,
122 'timestamp': timestamp,
123 'duration': duration,
124 'formats': formats,
125 }