1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-20 09:52:50 +01:00

finish upgrade, cleanup

This commit is contained in:
Audrey 2024-05-14 15:24:16 -04:00
parent 8d9fd25060
commit 104e991b28

View File

@ -1,9 +1,12 @@
import itertools
import json import json
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
ExtractorError,
float_or_none, float_or_none,
join_nonempty, join_nonempty,
parse_iso8601,
traverse_obj, traverse_obj,
url_or_none, url_or_none,
) )
@ -12,48 +15,54 @@
class DailyWireBaseIE(InfoExtractor): class DailyWireBaseIE(InfoExtractor):
_GRAPHQL_API = 'https://v2server.dailywire.com/app/graphql' _GRAPHQL_API = 'https://v2server.dailywire.com/app/graphql'
_GRAPHQL_QUERIES = { _GRAPHQL_QUERIES = {
'getEpisodeBySlug': 'query getEpisodeBySlug($slug: String!) {episode(where: {slug: $slug}) {id,title,status,slug,isLive,description,createdAt,scheduleAt,updatedAt,image,allowedCountryNames,allowedContinents,rating,show {id,name,slug,belongsTo},segments {id,image,title,liveChatAccess,audio,video,duration,watchTime,description,videoAccess,muxAssetId,muxPlaybackId,captions {id}},createdBy {firstName,lastName},discussionId}}', 'getClipBySlug': 'query getClipBySlug($slug:String!){clip(where:{slug:$slug}){id,name,slug,description,image,show{id,name,slug},thumbnail,duration,createdBy{firstName,lastName},createdAt,videoURL}}',
'getVideoBySlug': 'query getVideoBySlug($slug: String!) {video(where: {slug: $slug}) {id,name,slug,status,description,metadata,image,clips {id,name,slug,image,show {id,name,slug},video {id,name,slug},thumbnail,duration,clipAccess,createdAt,updatedAt},scheduleAt,allowedContinents,allowedCountryNames,rating,thumbnail,videoURL,logoImage,duration,createdBy {firstName,lastName},createdAt,updatedAt,watchTime,liveChatAccess,videoAccess,captions {id}}}', 'getEpisodeBySlug': 'query getEpisodeBySlug($slug:String!){episode(where:{slug:$slug}){id,title,slug,description,createdAt,image,show{id,name,slug},segments{audio,video,duration,},createdBy{firstName,lastName}}}',
'getClipBySlug': 'query getClipBySlug($slug: String!) {clip(where: {slug: $slug}) {id,name,slug,description,image,show {id,name,slug},video {id,status,name,slug},thumbnail,duration,clipAccess,createdBy {firstName,lastName},createdAt,updatedAt,videoURL,captions {id}}}', 'getPodcastEpisodes': 'query getPodcastEpisodes($where: PodcastEpisodeWhereInput, $orderBy: PodcastEpisodeOrderBy, $skip: Int, $first: Int) {listPodcastEpisode(where: $where, orderBy: $orderBy, skip: $skip, first: $first) {...ResPodcastEpisode}}, fragment ResPodcastEpisode on getPodcastEpisodeRes {id,title,description,slug,thumbnail,createdAt,audio,duration,podcast {id,name,slug,author {firstName,lastName}},season {id,name,slug}}',
'getShowBySlug': 'query getShowBySlug($slug: String!) {show(where: {slug: $slug}) {id,slug,belongsTo,name,description,image,logoImage,backgroundImage,hostImage,createdAt,updatedAt,author {firstName,lastName},episodes(where: {status_not_in: [DRAFT, UNPUBLISHED]},first: 1,orderBy: createdAt_DESC) {id,image,title,slug,status,createdAt,scheduleAt,description,show {id,name,slug,belongsTo},segments {id,title,muxAssetId,muxPlaybackId,audio}},seasons(orderBy: weight_DESC) {id,name,slug,orderBy}}}', 'getSeasonEpisodes': 'query getSeasonEpisodes($where:getSeasonEpisodesInput!,$first:Int,$skip:Int){getSeasonEpisodes(where:$where,first:$first,skip:$skip){episode{slug}}}',
'getSeasonEpisodes': 'query getSeasonEpisodes($where: getSeasonEpisodesInput!, $first: Int, $skip: Int) {getSeasonEpisodes(where: $where, first: $first, skip: $skip) {id,episode {id,title,slug,image,description,updatedAt,scheduleAt,createdAt,discussionId,isLive,status}}}', 'getShowBySlug': 'query getShowBySlug($slug:String!){show(where:{slug:$slug}){id,name,description,image,seasons(orderBy:weight_DESC){id,name,slug}}}',
'getVideoBySlug': 'query getVideoBySlug($slug:String!){video(where:{slug:$slug}){id,name,slug,description,image,thumbnail,videoURL,duration,createdBy{firstName,lastName},createdAt}}',
} }
_GRAPHQL_VIDEO_QUERIES = { _GRAPHQL_VIDEO_QUERIES = {
'clips': 'getClipBySlug',
'episode': 'getEpisodeBySlug', 'episode': 'getEpisodeBySlug',
'videos': 'getVideoBySlug', 'videos': 'getVideoBySlug',
'clips': 'getClipBySlug',
} }
_GRAPHQL_JSON_PATH = { _GRAPHQL_JSON_PATH = {
'getEpisodeBySlug': ('data', 'episode'),
'getVideoBySlug': ('data', 'video'),
'getClipBySlug': ('data', 'clip'), 'getClipBySlug': ('data', 'clip'),
'getSeasonEpisodes': ('data', 'getSeasonEpisodes'), 'getEpisodeBySlug': ('data', 'episode'),
'getPodcastEpisodes': ('data', 'listPodcastEpisode'),
'getSeasonEpisodes': ('data', 'getSeasonEpisodes', ..., 'episode', 'slug'),
'getShowBySlug': ('data', 'show'), 'getShowBySlug': ('data', 'show'),
'getVideoBySlug': ('data', 'video'),
}
_API_HEADERS = {
'Apollographql-Client-Name': 'DW_WEBSITE',
'Content-Type': 'application/json',
'Origin': 'https://www.dailywire.com',
'Referer': 'https://www.dailywire.com/',
} }
_ACCESS_TOKEN = None
def _get_auth(self): def _real_initialize(self):
t = self._get_cookies('https://www.dailywire.com').get('accessToken') if access_token := self._get_cookies('https://www.dailywire.com').get('accessToken'):
if t: self._API_HEADERS['Authorization'] = f'Bearer {access_token.value}'
self._ACCESS_TOKEN = t.value
def _call_api(self, slug, query, variables): def _call_api(self, slug, query, variables, message='Downloading JSON from GraphQL API'):
headers = {
'Apollographql-Client-Name': 'DW_WEBSITE',
'Content-Type': 'application/json',
'Origin': 'https://www.dailywire.com',
'Referer': 'https://www.dailywire.com/'}
self._get_auth() ### I doubt this is how you are supposed to set _TOKEN
if self._ACCESS_TOKEN:
headers['Authorization'] = f'Bearer {self._ACCESS_TOKEN}'
json_data = self._download_json( json_data = self._download_json(
self._GRAPHQL_API, slug, 'Downloading JSON from GraphQL API', data=json.dumps({ self._GRAPHQL_API, slug, message, data=json.dumps(
'query': self._GRAPHQL_QUERIES[query], 'variables': variables}).encode(), headers=headers) {'query': self._GRAPHQL_QUERIES[query], 'variables': variables}).encode(),
headers=self._API_HEADERS)
return traverse_obj(json_data, self._GRAPHQL_JSON_PATH.get(query, ())) return traverse_obj(json_data, self._GRAPHQL_JSON_PATH.get(query, ()))
def _paginate(self, slug, query, where):
for i in itertools.count(0):
page = self._call_api(slug,
query, {'where': where, 'first': 10, 'skip': i * 10},
message=f'Downloading page {i + 1}')
if not page:
break
yield page
class DailyWireIE(DailyWireBaseIE): class DailyWireIE(DailyWireBaseIE):
_VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>episode|videos|clips)/(?P<id>[\w-]+)' _VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>episode|videos|clips)/(?P<id>[\w-]+)'
@ -66,39 +75,79 @@ class DailyWireIE(DailyWireBaseIE):
'title': '1. Fauci', 'title': '1. Fauci',
'description': 'md5:9df630347ef85081b7e97dd30bc22853', 'description': 'md5:9df630347ef85081b7e97dd30bc22853',
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/ckzsl50xnqpy30850in3v4bu7/ckzsl50xnqpy30850in3v4bu7-1648237399554.jpg', 'thumbnail': 'https://daily-wire-production.imgix.net/episodes/ckzsl50xnqpy30850in3v4bu7/ckzsl50xnqpy30850in3v4bu7-1648237399554.jpg',
'creator': 'Caroline Roberts',
'series_id': 'ckzplm0a097fn0826r2vc3j7h', 'series_id': 'ckzplm0a097fn0826r2vc3j7h',
'series': 'China: The Enemy Within', 'series': 'China: The Enemy Within',
} 'upload_date': '20220218',
}, { 'creators': ['Caroline Roberts'],
'url': 'https://www.dailywire.com/episode/ep-124-bill-maher', 'timestamp': 1645182003,
'info_dict': {
'id': 'cl0ngbaalplc80894sfdo9edf',
'ext': 'mp3',
'display_id': 'ep-124-bill-maher',
'title': 'Ep. 124 - Bill Maher',
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/cl0ngbaalplc80894sfdo9edf/cl0ngbaalplc80894sfdo9edf-1647065568518.jpg',
'creator': 'Caroline Roberts',
'description': 'md5:adb0de584bcfa9c41374999d9e324e98',
'series_id': 'cjzvep7270hp00786l9hwccob',
'series': 'The Sunday Special',
} }
}, { }, {
'url': 'https://www.dailywire.com/videos/the-hyperions', 'url': 'https://www.dailywire.com/videos/the-hyperions',
'only_matching': True, 'only_matching': True,
}, {
'skip': 'premium only',
'url': 'https://www.dailywire.com/episode/ep-3-avery-s-niece-new',
'info_dict': {
'id': 'clm8geguv3qku0870ewvcu0ed',
'display_id': 'ep-3-avery-s-niece-new',
'title': 'Ep 3 - Averys Niece',
'description': 'md5:861ab336bd2bab2abebc25a1479a42e0',
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/clm8geguv3qku0870ewvcu0ed/clm8geguv3qku0870ewvcu0ed-1694047935734.png',
'series_id': 'clim20ue5f8160838ecz7ba8q',
'ext': 'mp4',
'subtitles': {'en-US': [{'ext': 'vtt'}]},
'timestamp': 1694062826,
'series': 'Convicting a Murderer',
'creators': ['Scott Bowler '],
'upload_date': '20230907',
},
}, {
'skip': 'premium only',
'url': 'https://www.dailywire.com/clips/the-making-of-run-hide-fight',
'info_dict': {
'id': 'ckjutyd6810dd0806ivcq2526',
'display_id': 'the-making-of-run-hide-fight',
'title': 'The Making of Run Hide Fight',
'description': 'md5:085297d753b73ad87bdd8b050cc10d2c',
'thumbnail': 'https://image.media.dailywire.com/K7OqsPwWH5c9hpWT68CHeZ4vRUtoz5Le/thumbnail.png',
'duration': 916.790889,
'creators': ['Paul Snyder'],
'upload_date': '20210113',
'timestamp': 1610506443,
'ext': 'mp4',
},
}, {
'skip': 'premium only',
'url': 'https://www.dailywire.com/videos/choosing-death-the-legacy-of-roe',
'info_dict': {
'id': 'cl3260dva6pjr097819zw506s',
'display_id': 'choosing-death-the-legacy-of-roe',
'title': 'Choosing Death [The Legacy of Roe]',
'description': 'md5:b07597f0ef32130365427a05fd1ccd25',
'duration': 2618.0738,
'timestamp': 1652308821,
'upload_date': '20220511',
'thumbnail': 'https://image.media.dailywire.com/FBgIBgmq635VuqTgWKjcGviEjJ2vJ02Zz/thumbnail.png',
'subtitles': {'en-US': [{'ext': 'vtt'}]},
'ext': 'mp4',
},
}] }]
def _real_extract(self, url): def _real_extract(self, url):
sites_type, slug = self._match_valid_url(url).group('sites_type', 'id') sites_type, slug = self._match_valid_url(url).group('sites_type', 'id')
episode_info = self._call_api(slug, self._GRAPHQL_VIDEO_QUERIES[sites_type], {'slug': slug}) episode_data = self._call_api(slug, self._GRAPHQL_VIDEO_QUERIES[sites_type], {'slug': slug})
urls = traverse_obj(episode_info, if not episode_data:
(('segments', 'clips'), ..., ('video', 'audio')), expected_type=url_or_none) or [ raise ExtractorError('video not found')
episode_info.get('videoURL') if episode_info.get('videoURL') != 'Access Denied' else None]
### print(urls) urls = traverse_obj(episode_data,
(('segments', 'clips'), ..., ('video', 'audio'))
) or [episode_data.get('videoURL')]
### add warning about auth if no formats and no auth ? if 'Access Denied' in urls:
self.report_warning(f'It looks like {slug} requires a login. Try passing cookies and try again.')
urls = [url_or_none(u) for u in urls if url_or_none(u)]
formats, subtitles = [], {} formats, subtitles = [], {}
for url in urls: for url in urls:
@ -109,24 +158,27 @@ def _real_extract(self, url):
formats.extend(format_) formats.extend(format_)
self._merge_subtitles(subs_, target=subtitles) self._merge_subtitles(subs_, target=subtitles)
return { return {
'id': episode_info['id'], 'id': episode_data.get('id'),
'display_id': slug, 'display_id': slug,
'title': traverse_obj(episode_info, 'title', 'name'), 'title': traverse_obj(episode_data, 'title', 'name'),
'description': episode_info.get('description'), 'description': episode_data.get('description'),
'creator': join_nonempty(('createdBy', 'firstName'), ('createdBy', 'lastName'), from_dict=episode_info, delim=' '), 'creator': join_nonempty(('createdBy', 'firstName'), ('createdBy', 'lastName'),
'duration': float_or_none(episode_info.get('duration')), from_dict=episode_data, delim=' '),
'is_live': episode_info.get('isLive'), 'duration': float_or_none(episode_data.get('duration')),
'thumbnail': traverse_obj(episode_info, 'thumbnail', 'image', expected_type=url_or_none), 'timestamp': parse_iso8601(episode_data.get('createdAt')),
'is_live': episode_data.get('isLive'),
'thumbnail': traverse_obj(episode_data, 'thumbnail', 'image', expected_type=url_or_none),
'formats': formats, 'formats': formats,
'subtitles': subtitles, 'subtitles': subtitles,
'series_id': traverse_obj(episode_info, ('show', 'id')), 'series_id': traverse_obj(episode_data, ('show', 'id')),
'series': traverse_obj(episode_info, ('show', 'name')), 'series': traverse_obj(episode_data, ('show', 'name')),
} ### test to make sure all values are properly extracted }
class DailyWirePodcastIE(DailyWireBaseIE): ### need to rewrite this class DailyWirePodcastIE(DailyWireBaseIE):
_VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>podcasts)/(?P<podcaster>[\w-]+/(?P<id>[\w-]+))' _VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>podcasts)/(?P<podcaster>[\w-]+)/?(?P<id>[\w-]+)?'
_TESTS = [{ _TESTS = [{
'note': 'serves shorter ad-free stream with paid cookies',
'url': 'https://www.dailywire.com/podcasts/morning-wire/get-ready-for-recession-6-15-22', 'url': 'https://www.dailywire.com/podcasts/morning-wire/get-ready-for-recession-6-15-22',
'info_dict': { 'info_dict': {
'id': 'cl4f01d0w8pbe0a98ydd0cfn1', 'id': 'cl4f01d0w8pbe0a98ydd0cfn1',
@ -134,45 +186,120 @@ class DailyWirePodcastIE(DailyWireBaseIE): ### need to rewrite this
'display_id': 'get-ready-for-recession-6-15-22', 'display_id': 'get-ready-for-recession-6-15-22',
'title': 'Get Ready for Recession | 6.15.22', 'title': 'Get Ready for Recession | 6.15.22',
'description': 'md5:c4afbadda4e1c38a4496f6d62be55634', 'description': 'md5:c4afbadda4e1c38a4496f6d62be55634',
'thumbnail': 'https://daily-wire-production.imgix.net/podcasts/ckx4otgd71jm508699tzb6hf4-1639506575562.jpg', 'thumbnail': 'https://daily-wire-production.imgix.net/podcasts/ckx4otgd71jm508699tzb6hf4-1667859984424.jpg',
'duration': 900.117667, 'duration': 900.117667,
'timestamp': 1655261631,
'season_id': 'morning-wire-morning-wire-podcast-season',
'series_id': 'morning-wire',
'creators': ['Georgia Howe'],
'season': '2022',
'series': 'Morning Wire',
'upload_date': '20220615',
} }
}, {
'url': 'https://www.dailywire.com/podcasts/enough',
'info_dict': {
'id': 'ckx4kvm8710i80869lvuu1b8z',
'title': 'Enough',
'display_id': 'enough',
},
'playlist_mincount': 7,
}] }]
def _real_extract(self, url): def _real_extract(self, url):
raise Exception('currently broken') ### podcaster, slug = self._match_valid_url(url).group('podcaster', 'id')
slug, episode_info = self._get_json(url)
audio_id = traverse_obj(episode_info, 'audioMuxPlaybackId', 'VUsAipTrBVSgzw73SpC2DAJD401TYYwEp')
return { def _extract_pod_ep_info(episode_data):
'id': episode_info['id'], print(episode_data)
'url': f'https://stream.media.dailywire.com/{audio_id}/audio.m4a', return {
'display_id': slug, 'id': episode_data.get('id'),
'title': episode_info.get('title'), 'url': episode_data.get('audio'),
'duration': float_or_none(episode_info.get('duration')), 'display_id': episode_data.get('slug'),
'thumbnail': episode_info.get('thumbnail'), 'title': episode_data.get('title'),
'description': episode_info.get('description'), 'duration': float_or_none(episode_data.get('duration')),
} 'timestamp': parse_iso8601(episode_data.get('createdAt')),
'thumbnail': episode_data.get('thumbnail'),
'description': episode_data.get('description'),
'creator': join_nonempty(('podcast', 'author', 'firstName'),
('podcast', 'author', 'lastName'),
from_dict=episode_data, delim=' '),
'season': traverse_obj(episode_data, ('season', 'name')),
'season_id': traverse_obj(episode_data, ('season', 'slug')),
'series': traverse_obj(episode_data, ('podcast', 'name')),
'series_id': traverse_obj(episode_data, ('podcast', 'slug')),
}
if slug:
episodes = self._call_api(slug, 'getPodcastEpisodes', {'where': {'slug': slug}})
if episode_data := traverse_obj(episodes, ..., get_all=False):
return _extract_pod_ep_info(episode_data)
else:
episodes = [
episode for page in
self._paginate(podcaster, 'getPodcastEpisodes', {'podcast': {'slug': podcaster}})
for episode in page
]
if episodes:
podcast_data = traverse_obj(episodes, (..., 'podcast'), {}, get_all=False)
return self.playlist_result(
[_extract_pod_ep_info(e) for e in episodes],
podcast_data.get('id'), podcast_data.get('name'), podcast_data.get('description'),
display_id=podcast_data.get('slug'), thumbnail=podcast_data.get('coverImage'))
raise ExtractorError('Podcast not found')
class DailyWireShowIE(DailyWireBaseIE): class DailyWireShowIE(DailyWireBaseIE):
_VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>show)/(?P<id>[\w-]+)' _VALID_URL = r'https?://(?:www\.)dailywire(?:\.com)/(?P<sites_type>show)/(?P<id>[\w-]+)'
_TESTS = [ _TESTS = [{
] 'skip': 'premium only',
'url': 'https://www.dailywire.com/show/apollo-11-what-we-saw',
def _real_extract(self, url): 'playlist_mincount': 28,
sites_type, slug = self._match_valid_url(url).group('sites_type', 'id') 'info_dict': {
'id': 'ckixsvamonvl40862ysxve50i',
show = self._call_api(slug, 'getShowBySlug', {'slug': slug}) 'thumbnail': 'https://daily-wire-production.imgix.net/shows/ckixsvamonvl40862ysxve50i-1679082975554.jpg',
'title': 'What We Saw',
for season in show.get('seasons', []): 'description': 'md5:98d2a7d5cc8175494a4ca611058ed440',
season['episodes'] = [] },
while episode_page := self._call_api(season['slug'], 'getSeasonEpisodes', {'where': {'season': {'id': season['id']}}, 'params': {
'first': 10, 'skip': len(season['episodes']) or None}): 'skip_download': True,
season['episodes'] += [episode['episode'] for episode in episode_page] },
'playlist': [{
return self.playlist_result( 'info_dict': {
[self.url_result(f'https://www.dailywire.com/episode/{e["slug"]}') 'id': 'cltf80tk79fxi0942c7h394b5',
for season in show['seasons'] for e in season['episodes']], 'season_id': 'what-we-saw-season-3-an-empire-of-terror-season',
show.get('id'), show.get('name'), show.get('description')) 'ext': 'mp4',
'display_id': 'season-3-an-empire-of-terror',
'display_id': 'season-3-an-empire-of-terror',
'series_id': 'ckixsvamonvl40862ysxve50i',
'title': 'Season 3: An Empire of Terror',
'description': 'What We Saw: An Empire of Terror premieres on March 6, 2024.',
'creators': ['Scott Bowler '],
'upload_date': '20240306',
'timestamp': 1709704832,
'thumbnail': 'https://daily-wire-production.imgix.net/episodes/cltf80tk79fxi0942c7h394b5/cltf80tk79fxi0942c7h394b5-1709694601671.png',
'series': 'What We Saw',
}}]
}]
def _real_extract(self, url):
slug = self._match_valid_url(url).group('id')
show_data = self._call_api(slug, 'getShowBySlug', {'slug': slug})
if not show_data:
raise ExtractorError('Show not found')
for season_data in show_data.get('seasons', []):
season_data['episodes'] = [
episode for page in
self._paginate(season_data.get('slug'), 'getSeasonEpisodes', {'season': {'id': season_data.get('id')}})
for episode in page
]
return self.playlist_result(
[self.url_result(f'https://www.dailywire.com/episode/{episode_slug}',
season_id=season_data.get('slug'), season=season_data.get('title'), url_transparent=True)
for season_data in show_data.get('seasons', []) for episode_slug in season_data['episodes']],
show_data.get('id'), show_data.get('name'), show_data.get('description'),
thumbnail=show_data.get('image'))