mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 12:21:47 +00:00
fix: download/pip button for podcast video
This commit is contained in:
@ -32,10 +32,22 @@ const menuObserver = new MutationObserver(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuUrl = document.querySelector<HTMLAnchorElement>(
|
// check for video (or music)
|
||||||
|
let menuUrl = document.querySelector<HTMLAnchorElement>(
|
||||||
'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint',
|
'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint',
|
||||||
)?.href;
|
)?.href;
|
||||||
if (!menuUrl?.includes('watch?') && doneFirstLoad) {
|
if (!menuUrl?.includes('watch?')) {
|
||||||
|
menuUrl = undefined;
|
||||||
|
// check for podcast
|
||||||
|
for (const it of document.querySelectorAll('tp-yt-paper-listbox [tabindex="-1"] #navigation-endpoint')) {
|
||||||
|
if (it.getAttribute('href')?.includes('podcast/')) {
|
||||||
|
menuUrl = it.getAttribute('href')!;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!menuUrl && doneFirstLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,17 +63,32 @@ export const onRendererLoad = ({
|
|||||||
ipc,
|
ipc,
|
||||||
}: RendererContext<DownloaderPluginConfig>) => {
|
}: RendererContext<DownloaderPluginConfig>) => {
|
||||||
window.download = () => {
|
window.download = () => {
|
||||||
let videoUrl = getSongMenu()
|
const songMenu = getSongMenu();
|
||||||
|
let videoUrl = songMenu
|
||||||
// Selector of first button which is always "Start Radio"
|
// Selector of first button which is always "Start Radio"
|
||||||
?.querySelector(
|
?.querySelector(
|
||||||
'ytmusic-menu-navigation-item-renderer[tabindex="0"] #navigation-endpoint',
|
'ytmusic-menu-navigation-item-renderer[tabindex="0"] #navigation-endpoint',
|
||||||
)
|
)
|
||||||
?.getAttribute('href');
|
?.getAttribute('href');
|
||||||
|
|
||||||
|
if (!videoUrl && songMenu) {
|
||||||
|
for (const it of songMenu.querySelectorAll('ytmusic-menu-navigation-item-renderer[tabindex="-1"] #navigation-endpoint')) {
|
||||||
|
if (it.getAttribute('href')?.includes('podcast/')) {
|
||||||
|
videoUrl = it.getAttribute('href');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (videoUrl) {
|
if (videoUrl) {
|
||||||
if (videoUrl.startsWith('watch?')) {
|
if (videoUrl.startsWith('watch?')) {
|
||||||
videoUrl = defaultConfig.url + '/' + videoUrl;
|
videoUrl = defaultConfig.url + '/' + videoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (videoUrl.startsWith('podcast/')) {
|
||||||
|
videoUrl = defaultConfig.url + '/watch?' + videoUrl.replace('podcast/', 'v=');
|
||||||
|
}
|
||||||
|
|
||||||
if (videoUrl.includes('?playlist=')) {
|
if (videoUrl.includes('?playlist=')) {
|
||||||
ipc.invoke('download-playlist-request', videoUrl);
|
ipc.invoke('download-playlist-request', videoUrl);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -60,10 +60,23 @@ const observer = new MutationObserver(() => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const menuUrl = $<HTMLAnchorElement>(
|
// check for video (or music)
|
||||||
|
let menuUrl = $<HTMLAnchorElement>(
|
||||||
'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint',
|
'tp-yt-paper-listbox [tabindex="0"] #navigation-endpoint',
|
||||||
)?.href;
|
)?.href;
|
||||||
if (!menuUrl?.includes('watch?') && doneFirstLoad) {
|
|
||||||
|
if (!menuUrl?.includes('watch?')) {
|
||||||
|
menuUrl = undefined;
|
||||||
|
// check for podcast
|
||||||
|
for (const it of document.querySelectorAll('tp-yt-paper-listbox [tabindex="-1"] #navigation-endpoint')) {
|
||||||
|
if (it.getAttribute('href')?.includes('podcast/')) {
|
||||||
|
menuUrl = it.getAttribute('href')!;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!menuUrl && doneFirstLoad) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user