Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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,
});
},
},
];
};
24 changes: 23 additions & 1 deletion 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 @@ -122,7 +124,11 @@ export class YTMusic implements LyricProvider {
});
}

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

return fetch(this.PROXIED_ENDPOINT + 'browse?prettyPrint=false', {
headers,
method: 'POST',
Expand All @@ -132,6 +138,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> {
const app = document.querySelector<MusicPlayerAppElement>('ytmusic-app');
if (!app) {
throw new Error('ytmusic-app element not found');
}

return await app.networkManager.fetch<BrowseData, { browseId: string }>(
'/browse?prettyPrint=false',
{ browseId },
);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

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