Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,10 @@
"label": "Show time codes",
"tooltip": "Show the time codes next to the lyrics"
},
"use-ytm-lyrics-without-proxy": {
"label": "Use YTM lyrics with no proxy",
"tooltip": "Skip the YTM browse proxy and call YouTube Music directly using the app's authenticated session. Useful if you trust your network/region to allow direct browse calls."
},
"convert-chinese-character": {
"label": "Convert Chinese character",
"submenu": {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/synced-lyrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default createPlugin({
defaultTextString: '♪',
lineEffect: 'fancy',
romanization: true,
useYTMLyricsWithoutProxy: false,
} satisfies SyncedLyricsPluginConfig as SyncedLyricsPluginConfig,

menu,
Expand Down
15 changes: 15 additions & 0 deletions src/plugins/synced-lyrics/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,20 @@ export const menu = async (
});
},
},
{
label: t(
'plugins.synced-lyrics.menu.use-ytm-lyrics-without-proxy.label',
),
toolTip: t(
'plugins.synced-lyrics.menu.use-ytm-lyrics-without-proxy.tooltip',
),
type: 'checkbox',
checked: config.useYTMLyricsWithoutProxy,
click(item) {
ctx.setConfig({
useYTMLyricsWithoutProxy: item.checked,
});
},
},
];
};
28 changes: 26 additions & 2 deletions src/plugins/synced-lyrics/providers/YTMusic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { config } from '../renderer/renderer';

import type { LyricProvider, LyricResult, SearchSongInfo } from '../types';
import type { MusicPlayerAppElement } from '@/types/music-player-app-element';

Expand Down Expand Up @@ -39,7 +41,9 @@ export class YTMusic implements LyricProvider {
const { browseId } = lyricsTab?.tabRenderer?.endpoint?.browseEndpoint ?? {};
if (!browseId) return null;

const { contents } = await this.fetchBrowse(browseId);
const browseData = await this.fetchBrowse(browseId);
if (!browseData) return null;
const { contents } = browseData;
if (!contents) return null;

/*
Expand Down Expand Up @@ -122,7 +126,11 @@ export class YTMusic implements LyricProvider {
});
}

private fetchBrowse(browseId: string) {
private fetchBrowse(browseId: string): Promise<BrowseData | null> {
if (config()?.useYTMLyricsWithoutProxy) {
return this.fetchBrowseDirect(browseId);
}

return fetch(this.PROXIED_ENDPOINT + 'browse?prettyPrint=false', {
headers,
method: 'POST',
Expand All @@ -132,6 +140,22 @@ export class YTMusic implements LyricProvider {
}),
}).then((res) => res.json()) as Promise<BrowseData>;
}

// Calls YouTube Music's browse endpoint directly via the app's authenticated
// network manager, which injects the visitor/auth tokens that the request
// would otherwise be missing when called from regions where the unauthenticated
// call is geo-restricted.
private async fetchBrowseDirect(browseId: string): Promise<BrowseData | null> {
const app = document.querySelector<MusicPlayerAppElement>('ytmusic-app');
if (!app) {
return null;
}

return await app.networkManager.fetch<BrowseData, { browseId: string }>(
'/browse?prettyPrint=false',
{ browseId },
);
}
}

interface NextData {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/synced-lyrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type SyncedLyricsPluginConfig = {
showLyricsEvenIfInexact: boolean;
lineEffect: LineEffect;
romanization: boolean;
useYTMLyricsWithoutProxy: boolean;
convertChineseCharacter?:
| 'simplifiedToTraditional'
| 'traditionalToSimplified'
Expand Down