- format_note = media_content.attrib['type']
- filesize = int(media_content.attrib['fileSize'])
- formats.append({'url': url,
- 'format_note': format_note,
- 'format': '%s %s' % (format_note, format_bytes(filesize)),
- 'filesize': filesize,
- })
- return formats
-
- formats = []
-
- for media_group in item.findall('./{http://search.yahoo.com/mrss/}group'):
- formats.extend(process_formats(media_group))
-
- # Sometimes there are no media:groups in item, but there is media:content
- # right in item (usually when there is the only media source)
- formats.extend(process_formats(item))
-
- # Sort by file size
- formats.sort(key=lambda fmt: fmt['filesize'])
- return formats
-
- def _extract_title(self, html):
- title = self._html_search_meta(u'title', html, u'title')
- if title is None:
- title = self._og_search_title(html)
- TITLE_SUFFIX = u' (Channel 9)'
- if title is not None and title.endswith(TITLE_SUFFIX):
- title = title[:-len(TITLE_SUFFIX)]
- return title
-
- def _extract_description(self, html):
- DESCRIPTION_REGEX = r'''(?sx)
- <div\s+class="entry-content">\s*
- <div\s+id="entry-body">\s*
- (?P<description>.+?)\s*
- </div>\s*
- </div>
- '''
- m = re.search(DESCRIPTION_REGEX, html)
- if m is not None:
- return m.group('description')
- return self._html_search_meta(u'description', html, u'description')
-
- def _extract_duration(self, html):
- m = re.search(r'data-video_duration="(?P<hours>\d{2}):(?P<minutes>\d{2}):(?P<seconds>\d{2})"', html)
- return ((int(m.group('hours')) * 60 * 60) + (int(m.group('minutes')) * 60) + int(m.group('seconds'))) if m else None
-
- def _extract_slides(self, html):
- m = re.search(r'<a href="(?P<slidesurl>[^"]+)" class="slides">Slides</a>', html)
- return m.group('slidesurl') if m is not None else None
-
- def _extract_zip(self, html):
- m = re.search(r'<a href="(?P<zipurl>[^"]+)" class="zip">Zip</a>', html)
- return m.group('zipurl') if m is not None else None
-
- def _extract_avg_rating(self, html):
- m = re.search(r'<p class="avg-rating">Avg Rating: <span>(?P<avgrating>[^<]+)</span></p>', html)
- return float(m.group('avgrating')) if m is not None else 0
-
- def _extract_rating_count(self, html):
- m = re.search(r'<div class="rating-count">\((?P<ratingcount>[^<]+)\)</div>', html)
- return int(self._fix_count(m.group('ratingcount'))) if m is not None else 0
-
- def _extract_view_count(self, html):
- m = re.search(r'<li class="views">\s*<span class="count">(?P<viewcount>[^<]+)</span> Views\s*</li>', html)
- return int(self._fix_count(m.group('viewcount'))) if m is not None else 0
-
- def _extract_comment_count(self, html):
- m = re.search(r'<li class="comments">\s*<a href="#comments">\s*<span class="count">(?P<commentcount>[^<]+)</span> Comments\s*</a>\s*</li>', html)
- return int(self._fix_count(m.group('commentcount'))) if m is not None else 0
-
- def _fix_count(self, count):
- return int(str(count).replace(',', '')) if count is not None else None
-
- def _extract_authors(self, html):
- m = re.search(r'(?s)<li class="author">(.*?)</li>', html)
- if m is None:
- return None
- return re.findall(r'<a href="/Niners/[^"]+">([^<]+)</a>', m.group(1))
-
- def _extract_session_code(self, html):
- m = re.search(r'<li class="code">\s*(?P<code>.+?)\s*</li>', html)
- return m.group('code') if m is not None else None
-
- def _extract_session_day(self, html):
- m = re.search(r'<li class="day">\s*<a href="/Events/[^"]+">(?P<day>[^<]+)</a>\s*</li>', html)
- return m.group('day') if m is not None else None
-
- def _extract_session_room(self, html):
- m = re.search(r'<li class="room">\s*(?P<room>.+?)\s*</li>', html)
- return m.group('room') if m is not None else None
-
- def _extract_session_speakers(self, html):
- return re.findall(r'<a href="/Events/Speakers/[^"]+">([^<]+)</a>', html)
-
- def _extract_content(self, html, content_path):
- # Look for downloadable content
- formats = self._formats_from_html(html)
- slides = self._extract_slides(html)
- zip_ = self._extract_zip(html)
-
- # Nothing to download
- if len(formats) == 0 and slides is None and zip_ is None:
- self._downloader.report_warning(u'None of recording, slides or zip are available for %s' % content_path)
- return
-
- # Extract meta
- title = self._extract_title(html)
- description = self._extract_description(html)
- thumbnail = self._og_search_thumbnail(html)
- duration = self._extract_duration(html)
- avg_rating = self._extract_avg_rating(html)
- rating_count = self._extract_rating_count(html)
- view_count = self._extract_view_count(html)
- comment_count = self._extract_comment_count(html)
-
- common = {'_type': 'video',
- 'id': content_path,
- 'description': description,
- 'thumbnail': thumbnail,
- 'duration': duration,
- 'avg_rating': avg_rating,
- 'rating_count': rating_count,
- 'view_count': view_count,
- 'comment_count': comment_count,
- }
-
- result = []
-
- if slides is not None:
- d = common.copy()
- d.update({ 'title': title + '-Slides', 'url': slides })
- result.append(d)
-
- if zip_ is not None:
- d = common.copy()
- d.update({ 'title': title + '-Zip', 'url': zip_ })
- result.append(d)
-
- if len(formats) > 0:
- d = common.copy()
- d.update({ 'title': title, 'formats': formats })
- result.append(d)
-
- return result
-
- def _extract_entry_item(self, html, content_path):
- contents = self._extract_content(html, content_path)
- if contents is None:
- return contents
-
- authors = self._extract_authors(html)
-
- for content in contents:
- content['authors'] = authors
-
- return contents
-
- def _extract_session(self, html, content_path):
- contents = self._extract_content(html, content_path)
- if contents is None:
- return contents
-
- session_meta = {'session_code': self._extract_session_code(html),
- 'session_day': self._extract_session_day(html),
- 'session_room': self._extract_session_room(html),
- 'session_speakers': self._extract_session_speakers(html),
- }
-
- for content in contents:
- content.update(session_meta)
-
- return contents
-
- def _extract_content_rss(self, rss):
- '''
- Extracts links to entry items right out of RSS feed.
- This approach is faster than extracting from web pages
- one by one, but suffers from some problems.
- Pros:
- - no need to download additional pages
- - provides more media links
- - accurate file size
- Cons:
- - fewer meta data provided
- - links to media files have no appropriate data that may be used as format_id
- - RSS does not contain links to presentation materials (slides, zip)
- '''
- entries = []
- for item in rss.findall('./channel/item'):
- url = item.find('./link').text
- video_id = url.split('/')[-1]
- formats = self._formats_from_rss_item(item)
-
- if len(formats) == 0:
- self._downloader.report_warning(u'The recording for session %s is not yet available' % video_id)
- continue
-
- title = item.find('./title').text
- description = item.find('./description').text
-
- thumbnail = item.find('./{http://search.yahoo.com/mrss/}thumbnail').text
-
- duration_e = item.find('./{http://www.itunes.com/dtds/podcast-1.0.dtd}duration')
- duration = duration_e.text if duration_e is not None else 0
-
- speakers_e = item.find('./{http://purl.org/dc/elements/1.1/}creator')
- speakers = speakers_e.text.split(', ') if speakers_e is not None and speakers_e.text else []
-
- entries.append({'_type': 'video',
- 'id': video_id,
- 'formats': formats,
- 'title': title,
- 'description': description,
- 'thumbnail': thumbnail,
- 'duration': duration,
- 'session_speakers': speakers,
- })
- return entries
-
- def _extract_list(self, content_path):
- rss = self._download_xml(self._RSS_URL % content_path, content_path, u'Downloading RSS')
- if self._EXTRACT_ENTRY_ITEMS_FROM_RSS:
- return self._extract_content_rss(rss)
+ urls.add(q_url)
+ formats.append({
+ 'url': q_url,
+ 'format_id': q,
+ 'quality': quality(q, q_url),
+ })
+
+ self._sort_formats(formats)
+
+ slides = content_data.get('Slides')
+ zip_file = content_data.get('ZipFile')
+
+ if not formats and not slides and not zip_file:
+ raise ExtractorError(
+ 'None of recording, slides or zip are available for %s' % content_path)
+
+ subtitles = {}
+ for caption in content_data.get('Captions', []):
+ caption_url = caption.get('Url')
+ if not caption_url:
+ continue
+ subtitles.setdefault(caption.get('Language', 'en'), []).append({
+ 'url': caption_url,
+ 'ext': 'vtt',
+ })
+
+ common = {
+ 'id': content_id,
+ 'title': title,
+ 'description': clean_html(content_data.get('Description') or content_data.get('Body')),
+ 'thumbnail': content_data.get('Thumbnail') or content_data.get('VideoPlayerPreviewImage'),
+ 'duration': int_or_none(content_data.get('MediaLengthInSeconds')),
+ 'timestamp': parse_iso8601(content_data.get('PublishedDate')),
+ 'avg_rating': int_or_none(content_data.get('Rating')),
+ 'rating_count': int_or_none(content_data.get('RatingCount')),
+ 'view_count': int_or_none(content_data.get('Views')),
+ 'comment_count': int_or_none(content_data.get('CommentCount')),
+ 'subtitles': subtitles,
+ }
+ if is_session:
+ speakers = []
+ for s in content_data.get('Speakers', []):
+ speaker_name = s.get('FullName')
+ if not speaker_name:
+ continue
+ speakers.append(speaker_name)
+
+ common.update({
+ 'session_code': content_data.get('Code'),
+ 'session_room': content_data.get('Room'),
+ 'session_speakers': speakers,
+ })
+ else:
+ authors = []
+ for a in content_data.get('Authors', []):
+ author_name = a.get('DisplayName')
+ if not author_name:
+ continue
+ authors.append(author_name)
+ common['authors'] = authors
+
+ contents = []
+
+ if slides:
+ d = common.copy()
+ d.update({'title': title + '-Slides', 'url': slides})
+ contents.append(d)
+
+ if zip_file:
+ d = common.copy()
+ d.update({'title': title + '-Zip', 'url': zip_file})
+ contents.append(d)
+
+ if formats:
+ d = common.copy()
+ d.update({'title': title, 'formats': formats})
+ contents.append(d)
+ return self.playlist_result(contents)