Skip to content

Commit d297d43

Browse files
committed
initial attempt at downloading albums from playlist tracks
1 parent 8da18c1 commit d297d43

5 files changed

Lines changed: 49 additions & 2 deletions

File tree

cli/src/download.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const listener: Listener = {
1818
},
1919
};
2020

21-
export const downloadLinks = async (
21+
const initialLinks = async (
2222
dz: Deezer,
2323
urls: string[],
2424
settings: Settings,
@@ -27,6 +27,7 @@ export const downloadLinks = async (
2727
const bitrate = settings.maxBitrate ?? TrackFormats.MP3_128;
2828

2929
const downloadObjects = [];
30+
const expandedObjects = [];
3031
for (const url of urls) {
3132
try {
3233
const downloadObject = await generateDownloadObject(
@@ -36,7 +37,6 @@ export const downloadLinks = async (
3637
{ spotify: spotifyPlugin },
3738
listener
3839
);
39-
4040
if (Array.isArray(downloadObject)) {
4141
downloadObjects.concat(downloadObject);
4242
} else {
@@ -59,6 +59,42 @@ export const downloadLinks = async (
5959
}
6060
}
6161
}
62+
return downloadObjects
63+
}
64+
65+
66+
export const downloadLinks = async (
67+
dz: Deezer,
68+
urls: string[],
69+
settings: Settings,
70+
spotifyPlugin: SpotifyPlugin
71+
) => {
72+
const initialObjects = await initialLinks(
73+
dz,
74+
urls,
75+
settings,
76+
spotifyPlugin
77+
)
78+
let downloadObjects = [];
79+
if (settings.downloadAlbumSingles) {
80+
const albumUrls = [];
81+
for (let downloadObject of initialObjects) {
82+
if (downloadObject.type === "playlist") {
83+
for (let track of downloadObject.collection.tracks) {
84+
albumUrls.push(track.album.link)
85+
}
86+
}
87+
}
88+
const uniqueUrls = [...new Set(albumUrls)];
89+
downloadObjects = await initialLinks(
90+
dz,
91+
uniqueUrls,
92+
settings,
93+
spotifyPlugin
94+
)
95+
} else {
96+
downloadObjects = initialObjects;
97+
}
6298

6399
for (let downloadObject of downloadObjects) {
64100
if (downloadObject instanceof Convertable) {

deemix/src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const DEFAULT_SETTINGS: Settings = {
4242
queueConcurrency: 10,
4343
maxBitrate: TrackFormats.MP3_128,
4444
feelingLucky: false,
45+
downloadAlbumSingles: false,
4546
fallbackBitrate: false,
4647
fallbackSearch: false,
4748
fallbackISRC: false,

deemix/src/types/Settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface Settings {
6161
illegalCharacterReplacer?: string;
6262
queueConcurrency?: number;
6363
maxBitrate?: number;
64+
downloadAlbumSingles?: boolean;
6465
fallbackBitrate?: boolean;
6566
fallbackSearch?: boolean;
6667
logErrors?: boolean;

webui/src/client/lang/en.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ const en = {
310310
e: "No, and don't look at the extensions",
311311
l: "Overwrite only if upgrading bitrate (mp3 only)",
312312
},
313+
downloadAlbumSingles: "Download albums of playlist tracks",
313314
fallbackBitrate: "Bitrate fallback",
314315
fallbackSearch: "Search fallback",
315316
fallbackISRC: "Fallback with ISRC search",

webui/src/client/views/SettingsPage.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,14 @@ function canDownload(bitrate: number) {
990990
<div
991991
class="settings-container__third settings-container__third--only-checkbox"
992992
>
993+
994+
<label class="with-checkbox">
995+
<input v-model="settings.downloadAlbumSingles" type="checkbox" />
996+
<span class="checkbox-text">{{
997+
t("settings.downloads.downloadAlbumSingles")
998+
}}</span>
999+
</label>
1000+
9931001
<label class="with-checkbox">
9941002
<input v-model="settings.fallbackBitrate" type="checkbox" />
9951003
<span class="checkbox-text">{{

0 commit comments

Comments
 (0)