This commit is contained in:
infogulch 2025-01-26 22:19:00 -06:00
parent d69dc87e96
commit 21f5db11da

View File

@ -1,23 +1,51 @@
import json
import time
from .common import InfoExtractor
from ..utils import (
ExtractorError,
determine_ext,
float_or_none,
join_nonempty,
jwt_decode_hs256,
traverse_obj,
url_or_none,
)
class DailyWireBaseIE(InfoExtractor):
_NETRC_MACHINE = 'dailywire'
_GRAPHQL_API = 'https://v2server.dailywire.com/app/graphql'
_GRAPHQL_QUERY = 'query currentPerson { currentPerson { id } }'
_HEADERS = {
'Content-Type': 'application/json',
'apollographql-client-name': 'DW_WEBSITE',
'Origin': 'https://www.dailywire.com',
}
_JSON_PATH = {
'episode': ('props', 'pageProps', 'episodeData', 'episode'),
'videos': ('props', 'pageProps', 'videoData', 'video'),
'podcasts': ('props', 'pageProps', 'episode'),
}
def _perform_login(self, username, password):
if 'Authorization' in self._HEADERS:
return
if username != 'access_token':
raise ExtractorError(
'Login using username and password is not currently supported. '
'Use "--username access_token --password <access_token>" to login using an access token. '
'To get your access_token: login to the website, go to Developer Tools > Storage tab > Local Storage > https://www.dailywire.com > find the Key named access_token > copy the corresponding Value', expected=True)
try:
# validate the token
jwt = jwt_decode_hs256(password)
if time.time() >= jwt['exp']:
raise ValueError('jwt expired')
self._HEADERS['Authorization'] = f'Bearer {password}'
self.report_login()
except ValueError as e:
self.report_warning(f'Provided authorization token is invalid ({e!s}). Continuing as guest')
def _get_json(self, url):
sites_type, slug = self._match_valid_url(url).group('sites_type', 'id')
json_data = self._search_nextjs_data(self._download_webpage(url, slug), slug)
@ -62,24 +90,24 @@ class DailyWireIE(DailyWireBaseIE):
'series_id': 'ckzplm0a097fn0826r2vc3j7h',
'series': 'China: The Enemy Within',
},
# }, {
# 'url': 'https://www.dailywire.com/episode/2-biden',
# 'info_dict': {
# 'id': 'ckzsldx8pqpr50a26qgy90f92',
# 'ext': 'mp4',
# 'display_id': '2-biden',
# 'title': '2. Biden',
# 'description': 'md5:23cbc63f41dc3f22d2651013ada70ce5',
# 'thumbnail': 'https://daily-wire-production.imgix.net/episodes/ckzsldx8pqpr50a26qgy90f92/ckzsldx8pqpr50a26qgy90f92-1648237379060.jpg',
# 'creators': ['Caroline Roberts'],
# 'series_id': 'ckzplm0a097fn0826r2vc3j7h',
# 'series': 'China: The Enemy Within',
# },
}, {
'url': 'https://www.dailywire.com/episode/2-biden',
'info_dict': {
'id': 'ckzsldx8pqpr50a26qgy90f92',
'ext': 'mp4',
'display_id': '2-biden',
'title': '2. Biden',
'description': 'md5:23cbc63f41dc3f22d2651013ada70ce5',
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/ckzsldx8pqpr50a26qgy90f92/ckzsldx8pqpr50a26qgy90f92-1648237379060.jpg',
'creators': ['Caroline Roberts'],
'series_id': 'ckzplm0a097fn0826r2vc3j7h',
'series': 'China: The Enemy Within',
},
}, {
'url': 'https://www.dailywire.com/episode/ep-124-bill-maher',
'info_dict': {
'id': 'cl0ngbaalplc80894sfdo9edf',
'ext': 'mp3', # note: mp3 when anonymous user, mp4 when insider user
'ext': 'mp4', # note: mp3 when anonymous user, mp4 when insider user
'display_id': 'ep-124-bill-maher',
'title': 'Ep. 124 - Bill Maher',
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/cl0ngbaalplc80894sfdo9edf/cl0ngbaalplc80894sfdo9edf-1647065568518.jpg',
@ -98,12 +126,7 @@ def _query_episode(self, url):
result = self._download_json(
self._GRAPHQL_API, slug, note='Downloading JSON from GraphQL API',
data=json.dumps({'query': self._GRAPHQL_QUERY, 'variables': {'slug': slug}}, separators=(',', ':')).encode(),
headers={
'Content-Type': 'application/json',
'apollographql-client-name': 'DW_WEBSITE',
'Origin': 'https://www.dailywire.com',
# 'Authorization': 'Bearer ...',
})['data']['episode']
headers=self._HEADERS)['data']['episode']
# self.to_screen(json.dumps(result))
return slug, result