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.

96 lines
3.0 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 for July 03, 2015',
  21. 'description': 'md5:80eb927244d6749900de6072c7cc2c86',
  22. },
  23. }, {
  24. 'url': 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree',
  25. 'info_dict': {
  26. 'id': '2015-0703-001',
  27. 'ext': 'mp4',
  28. 'title': '"This Flag Comes Down Today": Bree Newsome Scales SC Capitol Flagpole, Takes Down Confederate Flag',
  29. 'description': 'md5:4d2bc4f0d29f5553c2210a4bc7761a21',
  30. },
  31. 'params': {
  32. 'skip_download': True,
  33. },
  34. }]
  35. def _real_extract(self, url):
  36. display_id = self._match_id(url)
  37. webpage = self._download_webpage(url, display_id)
  38. json_data = self._parse_json(self._search_regex(
  39. r'<script[^>]+type="text/json"[^>]*>\s*({[^>]+})', webpage, 'json'),
  40. display_id)
  41. title = json_data['title']
  42. formats = []
  43. video_id = None
  44. for key in ('file', 'audio', 'video', 'high_res_video'):
  45. media_url = json_data.get(key, '')
  46. if not media_url:
  47. continue
  48. media_url = re.sub(r'\?.*', '', compat_urlparse.urljoin(url, media_url))
  49. video_id = video_id or remove_start(os.path.splitext(url_basename(media_url))[0], 'dn')
  50. formats.append({
  51. 'url': media_url,
  52. 'vcodec': 'none' if key == 'audio' else None,
  53. })
  54. self._sort_formats(formats)
  55. default_lang = 'en'
  56. subtitles = {}
  57. def add_subtitle_item(lang, info_dict):
  58. if lang not in subtitles:
  59. subtitles[lang] = []
  60. subtitles[lang].append(info_dict)
  61. # chapter_file are not subtitles
  62. if 'caption_file' in json_data:
  63. add_subtitle_item(default_lang, {
  64. 'url': compat_urlparse.urljoin(url, json_data['caption_file']),
  65. })
  66. for subtitle_item in json_data.get('captions', []):
  67. lang = subtitle_item.get('language', '').lower() or default_lang
  68. add_subtitle_item(lang, {
  69. 'url': compat_urlparse.urljoin(url, subtitle_item['url']),
  70. })
  71. description = self._og_search_description(webpage, default=None)
  72. return {
  73. 'id': video_id or display_id,
  74. 'title': title,
  75. 'description': description,
  76. 'thumbnail': json_data.get('image'),
  77. 'subtitles': subtitles,
  78. 'formats': formats,
  79. }