You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.9 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. parse_iso8601,
  7. xpath_text,
  8. )
  9. class NerdistIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?nerdist\.com/vepisode/(?P<id>[^/?#]+)'
  11. _TEST = {
  12. 'url': 'http://www.nerdist.com/vepisode/exclusive-which-dc-characters-w',
  13. 'md5': '3698ed582931b90d9e81e02e26e89f23',
  14. 'info_dict': {
  15. 'display_id': 'exclusive-which-dc-characters-w',
  16. 'id': 'RPHpvJyr',
  17. 'ext': 'mp4',
  18. 'title': 'Your TEEN TITANS Revealed! Who\'s on the show?',
  19. 'thumbnail': 're:^https?://.*/thumbs/.*\.jpg$',
  20. 'description': 'Exclusive: Find out which DC Comics superheroes will star in TEEN TITANS Live-Action TV Show on Nerdist News with Jessica Chobot!',
  21. 'uploader': 'Eric Diaz',
  22. 'upload_date': '20150202',
  23. 'timestamp': 1422892808,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. display_id = self._match_id(url)
  28. webpage = self._download_webpage(url, display_id)
  29. video_id = self._search_regex(
  30. r'''(?x)<script\s+(?:type="text/javascript"\s+)?
  31. src="https?://content\.nerdist\.com/players/([a-zA-Z0-9_]+)-''',
  32. webpage, 'video ID')
  33. timestamp = parse_iso8601(self._html_search_meta(
  34. 'shareaholic:article_published_time', webpage, 'upload date'))
  35. uploader = self._html_search_meta(
  36. 'shareaholic:article_author_name', webpage, 'article author')
  37. doc = self._download_xml(
  38. 'http://content.nerdist.com/jw6/%s.xml' % video_id, video_id)
  39. video_info = doc.find('.//item')
  40. title = xpath_text(video_info, './title', fatal=True)
  41. description = xpath_text(video_info, './description')
  42. thumbnail = xpath_text(
  43. video_info, './{http://rss.jwpcdn.com/}image', 'thumbnail')
  44. formats = []
  45. for source in video_info.findall('./{http://rss.jwpcdn.com/}source'):
  46. vurl = source.attrib['file']
  47. ext = determine_ext(vurl)
  48. if ext == 'm3u8':
  49. formats.extend(self._extract_m3u8_formats(
  50. vurl, video_id, entry_protocol='m3u8_native', ext='mp4',
  51. preference=0))
  52. elif ext == 'smil':
  53. formats.extend(self._extract_smil_formats(
  54. vurl, video_id, fatal=False
  55. ))
  56. else:
  57. formats.append({
  58. 'format_id': ext,
  59. 'url': vurl,
  60. })
  61. self._sort_formats(formats)
  62. return {
  63. 'id': video_id,
  64. 'display_id': display_id,
  65. 'title': title,
  66. 'description': description,
  67. 'thumbnail': thumbnail,
  68. 'timestamp': timestamp,
  69. 'formats': formats,
  70. 'uploader': uploader,
  71. }