]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/channel9.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
16 class Channel9IE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.)?(?:channel9\.msdn\.com|s\.ch9\.ms)/(?P<contentpath>.+?)(?P<rss>/RSS)?/?(?:[?#&]|$)'
22 'url': 'http://channel9.msdn.com/Events/TechEd/Australia/2013/KOS002',
23 'md5': '32083d4eaf1946db6d454313f44510ca',
25 'id': '6c413323-383a-49dc-88f9-a22800cab024',
27 'title': 'Developer Kick-Off Session: Stuff We Love',
28 'description': 'md5:b80bf9355a503c193aff7ec6cd5a7731',
30 'thumbnail': r
're:https?://.*\.jpg',
31 'timestamp': 1377717420,
32 'upload_date': '20130828',
33 'session_code': 'KOS002',
34 'session_room': 'Arena 1A',
35 'session_speakers': ['Andrew Coates', 'Brady Gaster', 'Mads Kristensen', 'Ed Blankenship', 'Patrick Klug'],
38 'url': 'http://channel9.msdn.com/posts/Self-service-BI-with-Power-BI-nuclear-testing',
39 'md5': 'dcf983ee6acd2088e7188c3cf79b46bc',
41 'id': 'fe8e435f-bb93-4e01-8e97-a28c01887024',
43 'title': 'Self-service BI with Power BI - nuclear testing',
44 'description': 'md5:2d17fec927fc91e9e17783b3ecc88f54',
46 'thumbnail': r
're:https?://.*\.jpg',
47 'timestamp': 1386381991,
48 'upload_date': '20131207',
49 'authors': ['Mike Wilmot'],
52 # low quality mp4 is best
53 'url': 'https://channel9.msdn.com/Events/CPP/CppCon-2015/Ranges-for-the-Standard-Library',
55 'id': '33ad69d2-6a4e-4172-83a1-a523013dec76',
57 'title': 'Ranges for the Standard Library',
58 'description': 'md5:9895e0a9fd80822d2f01c454b8f4a372',
60 'thumbnail': r
're:https?://.*\.jpg',
61 'upload_date': '20150930',
62 'timestamp': 1443640735,
65 'skip_download': True,
68 'url': 'https://channel9.msdn.com/Niners/Splendid22/Queue/76acff796e8f411184b008028e0d492b/RSS',
70 'id': 'Niners/Splendid22/Queue/76acff796e8f411184b008028e0d492b',
73 'playlist_mincount': 100,
75 'url': 'https://channel9.msdn.com/Events/DEVintersection/DEVintersection-2016/RSS',
76 'only_matching': True,
78 'url': 'https://channel9.msdn.com/Events/Speakers/scott-hanselman/RSS?UrlSafeName=scott-hanselman',
79 'only_matching': True,
82 _RSS_URL
= 'http://channel9.msdn.com/%s/RSS'
85 def _extract_urls(webpage
):
87 r
'<iframe[^>]+src=["\'](https?
://channel9\
.msdn\
.com
/(?
:[^
/]+/)+)player
\b',
90 def _extract_list(self, video_id, rss_url=None):
92 rss_url = self._RSS_URL % video_id
93 rss = self._download_xml(rss_url, video_id, 'Downloading RSS
')
94 entries = [self.url_result(session_url.text, 'Channel9
')
95 for session_url in rss.findall('./channel
/item
/link
')]
96 title_text = rss.find('./channel
/title
').text
97 return self.playlist_result(entries, video_id, title_text)
99 def _real_extract(self, url):
100 content_path, rss = re.match(self._VALID_URL, url).groups()
103 return self._extract_list(content_path, url)
105 webpage = self._download_webpage(
106 url, content_path, 'Downloading web page
')
108 episode_data = self._search_regex(
109 r"data-episode='([^
']+)'", webpage, 'episode data', default=None)
111 episode_data = self._parse_json(unescapeHTML(
112 episode_data), content_path)
113 content_id = episode_data['contentId']
114 is_session = '/Sessions(' in episode_data['api']
115 content_url = 'https://channel9.msdn.com/odata' + episode_data['api']
117 content_url += '?$expand=Speakers'
119 content_url += '?$expand=Authors'
120 content_data = self._download_json(content_url, content_id)
121 title = content_data['Title']
126 'wmv-low', 'mp4-low',
127 'wmv-mid', 'mp4-mid',
128 'wmv-high', 'mp4-high',
131 quality_key = qualities(QUALITIES)
133 def quality(quality_id, format_url):
134 return (len(QUALITIES) if '_Source.' in format_url
135 else quality_key(quality_id))
143 'Low Quality WMV': 'wmv-low',
144 'Low Quality MP4': 'mp4-low',
145 'Mid Quality WMV': 'wmv-mid',
146 'Mid Quality MP4': 'mp4-mid',
147 'High Quality WMV': 'wmv-high',
148 'High Quality MP4': 'mp4-high',
151 formats_select = self._search_regex(
152 r'(?s)<select[^>]+name=["\']format
[^
>]+>(.+?
)</select
', webpage,
153 'formats select
', default=None)
155 for mobj in re.finditer(
156 r'<option
\b[^
>]+\bvalue
=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*(?P<format>[^<]+?)\s*<',
158 format_url = mobj.group('url')
159 if format_url in urls:
162 format_id = mobj.group('format')
163 quality_id = SITE_QUALITIES.get(format_id, format_id)
166 'format_id': quality_id,
167 'quality': quality(quality_id, format_url),
168 'vcodec': 'none' if quality_id == 'mp3' else None,
172 'VideoMP4Low': 'mp4-low',
173 'VideoWMV': 'wmv-mid',
174 'VideoMP4Medium': 'mp4-mid',
175 'VideoMP4High': 'mp4-high',
176 'VideoWMVHQ': 'wmv-hq',
179 for format_id, q in API_QUALITIES.items():
180 q_url = content_data.get(format_id)
181 if not q_url or q_url in urls:
187 'quality': quality(q, q_url),
190 self._sort_formats(formats)
192 slides = content_data.get('Slides')
193 zip_file = content_data.get('ZipFile')
195 if not formats and not slides and not zip_file:
196 raise ExtractorError(
197 'None of recording, slides or zip are available for %s' % content_path)
200 for caption in content_data.get('Captions', []):
201 caption_url = caption.get('Url')
204 subtitles.setdefault(caption.get('Language', 'en'), []).append({
212 'description': clean_html(content_data.get('Description') or content_data.get('Body')),
213 'thumbnail': content_data.get('Thumbnail') or content_data.get('VideoPlayerPreviewImage'),
214 'duration': int_or_none(content_data.get('MediaLengthInSeconds')),
215 'timestamp': parse_iso8601(content_data.get('PublishedDate')),
216 'avg_rating': int_or_none(content_data.get('Rating')),
217 'rating_count': int_or_none(content_data.get('RatingCount')),
218 'view_count': int_or_none(content_data.get('Views')),
219 'comment_count': int_or_none(content_data.get('CommentCount')),
220 'subtitles': subtitles,
224 for s in content_data.get('Speakers', []):
225 speaker_name = s.get('FullName')
228 speakers.append(speaker_name)
231 'session_code': content_data.get('Code'),
232 'session_room': content_data.get('Room'),
233 'session_speakers': speakers,
237 for a in content_data.get('Authors', []):
238 author_name = a.get('DisplayName')
241 authors.append(author_name)
242 common['authors'] = authors
248 d.update({'title': title + '-Slides', 'url': slides})
253 d.update({'title': title + '-Zip', 'url': zip_file})
258 d.update({'title': title, 'formats': formats})
260 return self.playlist_result(contents)
262 return self._extract_list(content_path)