fix: fixed bugs in downloader (#1342)

This commit is contained in:
JellyBrick
2023-10-23 00:19:01 +09:00
committed by GitHub
parent fa4c69d228
commit 8a89bbccf7
2 changed files with 21 additions and 10 deletions

View File

@ -22,8 +22,20 @@ export function isEnabled(plugin: string) {
return pluginConfig !== undefined && pluginConfig.enabled; return pluginConfig !== undefined && pluginConfig.enabled;
} }
export function setOptions<T>(plugin: string, options: T) { /**
* Set options for a plugin
* @param plugin Plugin name
* @param options Options to set
* @param exclude Options to exclude from the options object
*/
export function setOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
const plugins = store.get('plugins') as Record<string, T>; const plugins = store.get('plugins') as Record<string, T>;
// HACK: This is a workaround for preventing changed options from being overwritten
exclude.forEach((key) => {
if (Object.prototype.hasOwnProperty.call(options, key)) {
delete options[key as keyof T];
}
});
store.set('plugins', { store.set('plugins', {
...plugins, ...plugins,
[plugin]: { [plugin]: {
@ -33,8 +45,8 @@ export function setOptions<T>(plugin: string, options: T) {
}); });
} }
export function setMenuOptions<T>(plugin: string, options: T) { export function setMenuOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
setOptions(plugin, options); setOptions(plugin, options, exclude);
if (store.get('options.restartOnConfigChanges')) { if (store.get('options.restartOnConfigChanges')) {
restart(); restart();
} }
@ -45,11 +57,11 @@ export function getOptions<T>(plugin: string): T {
} }
export function enable(plugin: string) { export function enable(plugin: string) {
setMenuOptions(plugin, { enabled: true }); setMenuOptions(plugin, { enabled: true }, []);
} }
export function disable(plugin: string) { export function disable(plugin: string) {
setMenuOptions(plugin, { enabled: false }); setMenuOptions(plugin, { enabled: false }, []);
} }
export default { export default {

View File

@ -84,8 +84,8 @@ export const getCookieFromWindow = async (win: BrowserWindow) => {
url: 'https://music.youtube.com', url: 'https://music.youtube.com',
}) })
) )
.map((it) => it.name + '=' + it.value + ';') .map((it) => it.name + '=' + it.value)
.join(''); .join(';');
}; };
export default async (win_: BrowserWindow) => { export default async (win_: BrowserWindow) => {
@ -450,12 +450,11 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
try { try {
givenUrl = new URL(givenUrl ?? ''); givenUrl = new URL(givenUrl ?? '');
} catch { } catch {
return; givenUrl = new URL(win.webContents.getURL());
} }
const playlistId = const playlistId =
getPlaylistID(givenUrl) || getPlaylistID(givenUrl) ||
getPlaylistID(new URL(win.webContents.getURL())) ||
getPlaylistID(new URL(playingUrl)); getPlaylistID(new URL(playingUrl));
if (!playlistId) { if (!playlistId) {
@ -604,7 +603,7 @@ function getFFmpegMetadataArgs(metadata: CustomSongInfo) {
// Playlist radio modifier needs to be cut from playlist ID // Playlist radio modifier needs to be cut from playlist ID
const INVALID_PLAYLIST_MODIFIER = 'RDAMPL'; const INVALID_PLAYLIST_MODIFIER = 'RDAMPL';
const getPlaylistID = (aURL: URL) => { const getPlaylistID = (aURL?: URL): string | null | undefined => {
const result = const result =
aURL?.searchParams.get('list') || aURL?.searchParams.get('playlist'); aURL?.searchParams.get('list') || aURL?.searchParams.get('playlist');
if (result?.startsWith(INVALID_PLAYLIST_MODIFIER)) { if (result?.startsWith(INVALID_PLAYLIST_MODIFIER)) {