Skip to content

Commit 8a89bbc

Browse files
authored
fix: fixed bugs in downloader (#1342)
1 parent fa4c69d commit 8a89bbc

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/config/plugins.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ export function isEnabled(plugin: string) {
2222
return pluginConfig !== undefined && pluginConfig.enabled;
2323
}
2424

25-
export function setOptions<T>(plugin: string, options: T) {
25+
/**
26+
* Set options for a plugin
27+
* @param plugin Plugin name
28+
* @param options Options to set
29+
* @param exclude Options to exclude from the options object
30+
*/
31+
export function setOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
2632
const plugins = store.get('plugins') as Record<string, T>;
33+
// HACK: This is a workaround for preventing changed options from being overwritten
34+
exclude.forEach((key) => {
35+
if (Object.prototype.hasOwnProperty.call(options, key)) {
36+
delete options[key as keyof T];
37+
}
38+
});
2739
store.set('plugins', {
2840
...plugins,
2941
[plugin]: {
@@ -33,8 +45,8 @@ export function setOptions<T>(plugin: string, options: T) {
3345
});
3446
}
3547

36-
export function setMenuOptions<T>(plugin: string, options: T) {
37-
setOptions(plugin, options);
48+
export function setMenuOptions<T>(plugin: string, options: T, exclude: string[] = ['enabled']) {
49+
setOptions(plugin, options, exclude);
3850
if (store.get('options.restartOnConfigChanges')) {
3951
restart();
4052
}
@@ -45,11 +57,11 @@ export function getOptions<T>(plugin: string): T {
4557
}
4658

4759
export function enable(plugin: string) {
48-
setMenuOptions(plugin, { enabled: true });
60+
setMenuOptions(plugin, { enabled: true }, []);
4961
}
5062

5163
export function disable(plugin: string) {
52-
setMenuOptions(plugin, { enabled: false });
64+
setMenuOptions(plugin, { enabled: false }, []);
5365
}
5466

5567
export default {

src/plugins/downloader/back.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export const getCookieFromWindow = async (win: BrowserWindow) => {
8484
url: 'https://music.youtube.com',
8585
})
8686
)
87-
.map((it) => it.name + '=' + it.value + ';')
88-
.join('');
87+
.map((it) => it.name + '=' + it.value)
88+
.join(';');
8989
};
9090

9191
export default async (win_: BrowserWindow) => {
@@ -450,12 +450,11 @@ export async function downloadPlaylist(givenUrl?: string | URL) {
450450
try {
451451
givenUrl = new URL(givenUrl ?? '');
452452
} catch {
453-
return;
453+
givenUrl = new URL(win.webContents.getURL());
454454
}
455455

456456
const playlistId =
457457
getPlaylistID(givenUrl) ||
458-
getPlaylistID(new URL(win.webContents.getURL())) ||
459458
getPlaylistID(new URL(playingUrl));
460459

461460
if (!playlistId) {
@@ -604,7 +603,7 @@ function getFFmpegMetadataArgs(metadata: CustomSongInfo) {
604603
// Playlist radio modifier needs to be cut from playlist ID
605604
const INVALID_PLAYLIST_MODIFIER = 'RDAMPL';
606605

607-
const getPlaylistID = (aURL: URL) => {
606+
const getPlaylistID = (aURL?: URL): string | null | undefined => {
608607
const result =
609608
aURL?.searchParams.get('list') || aURL?.searchParams.get('playlist');
610609
if (result?.startsWith(INVALID_PLAYLIST_MODIFIER)) {

0 commit comments

Comments
 (0)