]>
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'
84 def _extract_list(self
, video_id
, rss_url
=None):
86 rss_url
= self
._RSS
_URL
% video_id
87 rss
= self
._download
_xml
(rss_url
, video_id
, 'Downloading RSS')
88 entries
= [self
.url_result(session_url
.text
, 'Channel9')
89 for session_url
in rss
.findall('./channel/item/link')]
90 title_text
= rss
.find('./channel/title').text
91 return self
.playlist_result(entries
, video_id
, title_text
)
93 def _real_extract(self
, url
):
94 content_path
, rss
= re
.match(self
._VALID
_URL
, url
).groups()
97 return self
._extract
_list
(content_path
, url
)
99 webpage
= self
._download
_webpage
(
100 url
, content_path
, 'Downloading web page')
102 episode_data
= self
._search
_regex
(
103 r
"data-episode='([^']+)'", webpage
, 'episode data', default
=None)
105 episode_data
= self
._parse
_json
(unescapeHTML(
106 episode_data
), content_path
)
107 content_id
= episode_data
['contentId']
108 is_session
= '/Sessions(' in episode_data
['api']
109 content_url
= 'https://channel9.msdn.com/odata' + episode_data
['api']
111 content_url
+= '?$expand=Speakers'
113 content_url
+= '?$expand=Authors'
114 content_data
= self
._download
_json
(content_url
, content_id
)
115 title
= content_data
['Title']
120 'wmv-low', 'mp4-low',
121 'wmv-mid', 'mp4-mid',
122 'wmv-high', 'mp4-high',
125 quality_key
= qualities(QUALITIES
)
127 def quality(quality_id
, format_url
):
128 return (len(QUALITIES
) if '_Source.' in format_url
129 else quality_key(quality_id
))
137 'Low Quality WMV': 'wmv-low',
138 'Low Quality MP4': 'mp4-low',
139 'Mid Quality WMV': 'wmv-mid',
140 'Mid Quality MP4': 'mp4-mid',
141 'High Quality WMV': 'wmv-high',
142 'High Quality MP4': 'mp4-high',
145 formats_select
= self
._search
_regex
(
146 r
'(?s)<select[^>]+name=["\']format
[^
>]+>(.+?
)</select
', webpage,
147 'formats select
', default=None)
149 for mobj in re.finditer(
150 r'<option
\b[^
>]+\bvalue
=(["\'])(?P<url>(?:(?!\1).)+)\1[^>]*>\s*(?P<format>[^<]+?)\s*<',
152 format_url = mobj.group('url')
153 if format_url in urls:
156 format_id = mobj.group('format')
157 quality_id = SITE_QUALITIES.get(format_id, format_id)
160 'format_id': quality_id,
161 'quality': quality(quality_id, format_url),
162 'vcodec': 'none' if quality_id == 'mp3' else None,
166 'VideoMP4Low': 'mp4-low',
167 'VideoWMV': 'wmv-mid',
168 'VideoMP4Medium': 'mp4-mid',
169 'VideoMP4High': 'mp4-high',
170 'VideoWMVHQ': 'wmv-hq',
173 for format_id, q in API_QUALITIES.items():
174 q_url = content_data.get(format_id)
175 if not q_url or q_url in urls:
181 'quality': quality(q, q_url),
184 self._sort_formats(formats)
186 slides = content_data.get('Slides')
187 zip_file = content_data.get('ZipFile')
189 if not formats and not slides and not zip_file:
190 raise ExtractorError(
191 'None of recording, slides or zip are available for %s' % content_path)
194 for caption in content_data.get('Captions', []):
195 caption_url = caption.get('Url')
198 subtitles.setdefault(caption.get('Language', 'en'), []).append({
206 'description': clean_html(content_data.get('Description') or content_data.get('Body')),
207 'thumbnail': content_data.get('Thumbnail') or content_data.get('VideoPlayerPreviewImage'),
208 'duration': int_or_none(content_data.get('MediaLengthInSeconds')),
209 'timestamp': parse_iso8601(content_data.get('PublishedDate')),
210 'avg_rating': int_or_none(content_data.get('Rating')),
211 'rating_count': int_or_none(content_data.get('RatingCount')),
212 'view_count': int_or_none(content_data.get('Views')),
213 'comment_count': int_or_none(content_data.get('CommentCount')),
214 'subtitles': subtitles,
218 for s in content_data.get('Speakers', []):
219 speaker_name = s.get('FullName')
222 speakers.append(speaker_name)
225 'session_code': content_data.get('Code'),
226 'session_room': content_data.get('Room'),
227 'session_speakers': speakers,
231 for a in content_data.get('Authors', []):
232 author_name = a.get('DisplayName')
235 authors.append(author_name)
236 common['authors'] = authors
242 d.update({'title': title + '-Slides', 'url': slides})
247 d.update({'title': title + '-Zip', 'url': zip_file})
252 d.update({'title': title, 'formats': formats})
254 return self.playlist_result(contents)
256 return self._extract_list(content_path)