2015-11-03 05:36:54 -05:00
|
|
|
import os.path
|
2024-05-26 15:27:21 -04:00
|
|
|
import re
|
2024-06-11 19:09:58 -04:00
|
|
|
import urllib.parse
|
2015-11-03 05:36:54 -05:00
|
|
|
|
2015-07-13 08:41:38 -04:00
|
|
|
from .common import InfoExtractor
|
2015-11-03 05:36:54 -05:00
|
|
|
from ..utils import (
|
|
|
|
remove_start,
|
2024-05-26 15:27:21 -04:00
|
|
|
url_basename,
|
2015-11-03 05:36:54 -05:00
|
|
|
)
|
2015-07-13 08:41:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
class DemocracynowIE(InfoExtractor):
|
2016-09-08 07:29:05 -04:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?democracynow\.org/(?P<id>[^\?]*)'
|
2015-07-13 08:41:38 -04:00
|
|
|
IE_NAME = 'democracynow'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://www.democracynow.org/shows/2015/7/3',
|
2016-04-08 12:19:16 -04:00
|
|
|
'md5': '3757c182d3d84da68f5c8f506c18c196',
|
2015-07-13 08:41:38 -04:00
|
|
|
'info_dict': {
|
|
|
|
'id': '2015-0703-001',
|
|
|
|
'ext': 'mp4',
|
2017-05-01 14:25:09 -04:00
|
|
|
'title': 'Daily Show for July 03, 2015',
|
|
|
|
'description': 'md5:80eb927244d6749900de6072c7cc2c86',
|
2015-07-13 08:41:38 -04:00
|
|
|
},
|
2015-07-17 03:57:08 -04:00
|
|
|
}, {
|
2015-07-13 08:41:38 -04:00
|
|
|
'url': 'http://www.democracynow.org/2015/7/3/this_flag_comes_down_today_bree',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '2015-0703-001',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': '"This Flag Comes Down Today": Bree Newsome Scales SC Capitol Flagpole, Takes Down Confederate Flag',
|
|
|
|
'description': 'md5:4d2bc4f0d29f5553c2210a4bc7761a21',
|
|
|
|
},
|
2016-04-08 12:19:16 -04:00
|
|
|
'params': {
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2015-07-13 08:41:38 -04:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
display_id = self._match_id(url)
|
2016-04-08 12:27:27 -04:00
|
|
|
|
2015-07-13 08:41:38 -04:00
|
|
|
webpage = self._download_webpage(url, display_id)
|
|
|
|
|
2015-11-03 11:09:55 -05:00
|
|
|
json_data = self._parse_json(self._search_regex(
|
2015-11-03 05:36:54 -05:00
|
|
|
r'<script[^>]+type="text/json"[^>]*>\s*({[^>]+})', webpage, 'json'),
|
|
|
|
display_id)
|
2016-04-08 12:27:27 -04:00
|
|
|
|
|
|
|
title = json_data['title']
|
2015-07-13 08:41:38 -04:00
|
|
|
formats = []
|
2015-11-03 05:36:54 -05:00
|
|
|
|
2016-04-08 12:27:27 -04:00
|
|
|
video_id = None
|
|
|
|
|
|
|
|
for key in ('file', 'audio', 'video', 'high_res_video'):
|
|
|
|
media_url = json_data.get(key, '')
|
|
|
|
if not media_url:
|
|
|
|
continue
|
2024-06-11 19:09:58 -04:00
|
|
|
media_url = re.sub(r'\?.*', '', urllib.parse.urljoin(url, media_url))
|
2016-04-08 12:27:27 -04:00
|
|
|
video_id = video_id or remove_start(os.path.splitext(url_basename(media_url))[0], 'dn')
|
|
|
|
formats.append({
|
|
|
|
'url': media_url,
|
|
|
|
'vcodec': 'none' if key == 'audio' else None,
|
|
|
|
})
|
2015-11-03 05:36:54 -05:00
|
|
|
|
2016-04-08 12:27:27 -04:00
|
|
|
default_lang = 'en'
|
2015-07-13 08:41:38 -04:00
|
|
|
subtitles = {}
|
2015-11-03 05:36:54 -05:00
|
|
|
|
|
|
|
def add_subtitle_item(lang, info_dict):
|
|
|
|
if lang not in subtitles:
|
|
|
|
subtitles[lang] = []
|
|
|
|
subtitles[lang].append(info_dict)
|
|
|
|
|
|
|
|
# chapter_file are not subtitles
|
2015-11-03 11:09:55 -05:00
|
|
|
if 'caption_file' in json_data:
|
2015-11-03 05:36:54 -05:00
|
|
|
add_subtitle_item(default_lang, {
|
2024-06-11 19:09:58 -04:00
|
|
|
'url': urllib.parse.urljoin(url, json_data['caption_file']),
|
2015-11-03 05:36:54 -05:00
|
|
|
})
|
|
|
|
|
2015-11-03 11:09:55 -05:00
|
|
|
for subtitle_item in json_data.get('captions', []):
|
2015-11-03 05:36:54 -05:00
|
|
|
lang = subtitle_item.get('language', '').lower() or default_lang
|
|
|
|
add_subtitle_item(lang, {
|
2024-06-11 19:09:58 -04:00
|
|
|
'url': urllib.parse.urljoin(url, subtitle_item['url']),
|
2015-11-03 05:36:54 -05:00
|
|
|
})
|
|
|
|
|
2016-04-08 12:27:27 -04:00
|
|
|
description = self._og_search_description(webpage, default=None)
|
2015-11-03 05:36:54 -05:00
|
|
|
|
|
|
|
return {
|
2015-11-03 11:13:00 -05:00
|
|
|
'id': video_id or display_id,
|
2016-04-08 12:27:27 -04:00
|
|
|
'title': title,
|
2015-07-13 08:41:38 -04:00
|
|
|
'description': description,
|
2016-04-08 12:27:27 -04:00
|
|
|
'thumbnail': json_data.get('image'),
|
2015-07-13 08:41:38 -04:00
|
|
|
'subtitles': subtitles,
|
|
|
|
'formats': formats,
|
|
|
|
}
|