From d3400c6de1723f80d922241549b90b07909b6e96 Mon Sep 17 00:00:00 2001 From: "cool.gitter.choco" Date: Thu, 6 Feb 2025 17:26:20 -0600 Subject: [PATCH] added custom formatting to everything else (?) --- static/js/artist.js | 8 +++++++- static/js/main.js | 13 ++++++++++++- static/js/playlist.js | 13 +++++++++++-- static/js/track.js | 12 +++++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/static/js/artist.js b/static/js/artist.js index 77eb563..1f51e66 100644 --- a/static/js/artist.js +++ b/static/js/artist.js @@ -242,7 +242,9 @@ async function startDownload(url, type, item, albumType) { deezer = '', spotifyQuality = 'NORMAL', deezerQuality = 'MP3_128', - realTime = false + realTime = false, + customDirFormat = '%ar_album%/%album%', // Default directory format + customTrackFormat = '%tracknum%. %music%' // Default track format } = config; const service = url.includes('open.spotify.com') ? 'spotify' : 'deezer'; @@ -266,6 +268,10 @@ async function startDownload(url, type, item, albumType) { apiUrl += '&real_time=true'; } + // Add custom formatting parameters to the API request + apiUrl += `&custom_dir_format=${encodeURIComponent(customDirFormat)}`; + apiUrl += `&custom_track_format=${encodeURIComponent(customTrackFormat)}`; + try { const response = await fetch(apiUrl); const data = await response.json(); diff --git a/static/js/main.js b/static/js/main.js index da8d1be..cabe426 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -98,6 +98,7 @@ function attachDownloadListeners(items) { } async function startDownload(url, type, item, albumType) { + // Retrieve configuration (if any) from localStorage const config = JSON.parse(localStorage.getItem('activeConfig')) || {}; const { fallback = false, @@ -105,7 +106,9 @@ async function startDownload(url, type, item, albumType) { deezer = '', spotifyQuality = 'NORMAL', deezerQuality = 'MP3_128', - realTime = false + realTime = false, + customTrackFormat = '', + customDirFormat = '' } = config; let service = url.includes('open.spotify.com') ? 'spotify' : 'deezer'; @@ -125,6 +128,14 @@ async function startDownload(url, type, item, albumType) { if (realTime) apiUrl += '&real_time=true'; + // Append custom formatting parameters if present. + if (customTrackFormat) { + apiUrl += `&custom_track_format=${encodeURIComponent(customTrackFormat)}`; + } + if (customDirFormat) { + apiUrl += `&custom_dir_format=${encodeURIComponent(customDirFormat)}`; + } + try { const response = await fetch(apiUrl); const data = await response.json(); diff --git a/static/js/playlist.js b/static/js/playlist.js index ba03d27..f848919 100644 --- a/static/js/playlist.js +++ b/static/js/playlist.js @@ -104,7 +104,6 @@ function renderPlaylist(playlist) { playlist.tracks.items.forEach((item, index) => { const track = item.track; // Create links for track, artist, and album using their IDs. - // Ensure that track.id, track.artists[0].id, and track.album.id are available. const trackLink = `/track/${track.id}`; const artistLink = `/artist/${track.artists[0].id}`; const albumLink = `/album/${track.album.id}`; @@ -208,7 +207,9 @@ async function startDownload(url, type, item, albumType) { deezer = '', spotifyQuality = 'NORMAL', deezerQuality = 'MP3_128', - realTime = false + realTime = false, + customTrackFormat = '', + customDirFormat = '' } = config; const service = url.includes('open.spotify.com') ? 'spotify' : 'deezer'; @@ -238,6 +239,14 @@ async function startDownload(url, type, item, albumType) { apiUrl += '&real_time=true'; } + // Append custom formatting parameters. + if (customTrackFormat) { + apiUrl += `&custom_track_format=${encodeURIComponent(customTrackFormat)}`; + } + if (customDirFormat) { + apiUrl += `&custom_dir_format=${encodeURIComponent(customDirFormat)}`; + } + try { const response = await fetch(apiUrl); const data = await response.json(); diff --git a/static/js/track.js b/static/js/track.js index be6c300..e1a5562 100644 --- a/static/js/track.js +++ b/static/js/track.js @@ -146,7 +146,9 @@ async function startDownload(url, type, item) { deezer = '', spotifyQuality = 'NORMAL', deezerQuality = 'MP3_128', - realTime = false + realTime = false, + customTrackFormat = '', + customDirFormat = '' } = config; const service = url.includes('open.spotify.com') ? 'spotify' : 'deezer'; @@ -164,6 +166,14 @@ async function startDownload(url, type, item) { apiUrl += '&real_time=true'; } + // Append custom formatting parameters if they are set. + if (customTrackFormat) { + apiUrl += `&custom_track_format=${encodeURIComponent(customTrackFormat)}`; + } + if (customDirFormat) { + apiUrl += `&custom_dir_format=${encodeURIComponent(customDirFormat)}`; + } + try { const response = await fetch(apiUrl); const data = await response.json();