@@ -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 ) {
0 commit comments