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.

95 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import os.path
  5. from .common import InfoExtractor
  6. from ..compat import compat_urlparse
  7. from ..utils import (
  8. url_basename,
  9. remove_start,
  10. )
  11. class DemocracynowIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?democracynow.org/(?P<id>[^\?]*)'
  13. IE_NAME = 'democracynow'
  14. _TESTS = [{
  15. 'url': 'http://www.democracynow.org/shows/2015/7/3',
  16. 'md5': '3757c182d3d84da68f5c8f506c18c196',
  17. 'info_dict': {
  18. 'id': '2015-0703-001',
  19. 'ext': 'mp4',
  20. 'title': 'Daily Show',
  21. },
  22. }, {
  23. 'url': 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree',
  24. 'info_dict': {
  25. 'id': '2015-0703-001',
  26. 'ext': 'mp4',
  27. 'title': '"This Flag Comes Down Today": Bree Newsome Scales SC Capitol Flagpole, Takes Down Confederate Flag',
  28. 'description': 'md5:4d2bc4f0d29f5553c2210a4bc7761a21',
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. }]
  34. def _real_extract(self, url):
  35. display_id = self._match_id(url)
  36. webpage = self._download_webpage(url, display_id)
  37. json_data = self._parse_json(self._search_regex(
  38. r'<script[^>]+type="text/json"[^>]*>\s*({[^>]+})', webpage, 'json'),
  39. display_id)
  40. title = json_data['title']
  41. formats = []
  42. video_id = None
  43. for key in ('file', 'audio', 'video', 'high_res_video'):
  44. media_url = json_data.get(key, '')
  45. if not media_url:
  46. continue
  47. media_url = re.sub(r'\?.*', '', compat_urlparse.urljoin(url, media_url))
  48. video_id = video_id or remove_start(os.path.splitext(url_basename(media_url))[0], 'dn')
  49. formats.append({
  50. 'url': media_url,
  51. 'vcodec': 'none' if key == 'audio' else None,
  52. })
  53. self._sort_formats(formats)
  54. default_lang = 'en'
  55. subtitles = {}
  56. def add_subtitle_item(lang, info_dict):
  57. if lang not in subtitles:
  58. subtitles[lang] = []
  59. subtitles[lang].append(info_dict)
  60. # chapter_file are not subtitles
  61. if 'caption_file' in json_data:
  62. add_subtitle_item(default_lang, {
  63. 'url': compat_urlparse.urljoin(url, json_data['caption_file']),
  64. })
  65. for subtitle_item in json_data.get('captions', []):
  66. lang = subtitle_item.get('language', '').lower() or default_lang
  67. add_subtitle_item(lang, {
  68. 'url': compat_urlparse.urljoin(url, subtitle_item['url']),
  69. })
  70. description = self._og_search_description(webpage, default=None)
  71. return {
  72. 'id': video_id or display_id,
  73. 'title': title,
  74. 'description': description,
  75. 'thumbnail': json_data.get('image'),
  76. 'subtitles': subtitles,
  77. 'formats': formats,
  78. }