mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Downloads land in Albums, Playlists or Tracks folders
This commit is contained in:
+24
-5
@@ -39,6 +39,8 @@ pub struct JobRequest {
|
|||||||
pub trim: Option<Trim>,
|
pub trim: Option<Trim>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub playlist: Option<String>,
|
pub playlist: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub kind: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
@@ -654,11 +656,17 @@ async fn cleanup(dir: &Path, stem: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_dir(settings: &Settings, req: &JobRequest) -> PathBuf {
|
pub fn target_dir(settings: &Settings, req: &JobRequest) -> PathBuf {
|
||||||
let base = PathBuf::from(&settings.output_dir);
|
let base = PathBuf::from(&settings.output_dir);
|
||||||
match (&req.folder, settings.collection_folders) {
|
let named = req.folder.as_deref().map(str::trim).filter(|n| !n.is_empty() && settings.collection_folders);
|
||||||
(Some(name), true) if !name.trim().is_empty() => base.join(sanitize(name)),
|
match (req.kind.as_deref(), named) {
|
||||||
_ => base,
|
(Some("album"), Some(name)) => base.join("Albums").join(sanitize(name)),
|
||||||
|
(Some("playlist"), Some(name)) => {
|
||||||
|
let lists = PathBuf::from(&settings.playlists_dir);
|
||||||
|
if settings.playlists_dir.trim().is_empty() { base.join("Playlists") } else { lists }.join(sanitize(name))
|
||||||
|
}
|
||||||
|
(None, Some(name)) => base.join(sanitize(name)),
|
||||||
|
_ => base.join("Tracks"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -764,11 +772,22 @@ mod tests {
|
|||||||
assert!(plan(&entry(Some(128), false, vec![720]), &save(SaveAs::Mp3, 320, 0), false).is_err());
|
assert!(plan(&entry(Some(128), false, vec![720]), &save(SaveAs::Mp3, 320, 0), false).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn sorts_downloads_into_albums_playlists_and_tracks() {
|
||||||
|
let settings = Settings { output_dir: "M".into(), playlists_dir: "M/Playlists".into(), collection_folders: true, ..Default::default() };
|
||||||
|
let req = |kind: Option<&str>, folder: Option<&str>| JobRequest { entry: entry(None, false, vec![]), meta: TagFields::default(), folder: folder.map(String::from), trim: None, playlist: None, kind: kind.map(String::from) };
|
||||||
|
assert_eq!(target_dir(&settings, &req(Some("album"), Some("Luxury"))), PathBuf::from("M").join("Albums").join("Luxury"));
|
||||||
|
assert_eq!(target_dir(&settings, &req(Some("playlist"), Some("Late night"))), PathBuf::from("M/Playlists").join("Late night"));
|
||||||
|
assert_eq!(target_dir(&settings, &req(Some("track"), None)), PathBuf::from("M").join("Tracks"));
|
||||||
|
let flat = Settings { collection_folders: false, ..settings.clone() };
|
||||||
|
assert_eq!(target_dir(&flat, &req(Some("album"), Some("Luxury"))), PathBuf::from("M").join("Tracks"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn builds_stems_and_escapes_templates() {
|
fn builds_stems_and_escapes_templates() {
|
||||||
let settings = Settings { output_dir: "out".into(), ..Default::default() };
|
let settings = Settings { output_dir: "out".into(), ..Default::default() };
|
||||||
let meta = TagFields { title: "100% Night".into(), track_number: Some(3), track_total: Some(120), ..Default::default() };
|
let meta = TagFields { title: "100% Night".into(), track_number: Some(3), track_total: Some(120), ..Default::default() };
|
||||||
let req = JobRequest { entry: entry(None, false, vec![]), meta, folder: Some("Nova - Glass: Vol 1".into()), trim: None, playlist: None };
|
let req = JobRequest { entry: entry(None, false, vec![]), meta, folder: Some("Nova - Glass: Vol 1".into()), trim: None, playlist: None, kind: None };
|
||||||
let stem = file_stem(&settings, &req);
|
let stem = file_stem(&settings, &req);
|
||||||
assert_eq!(stem, "003 - Nova - 100% Night");
|
assert_eq!(stem, "003 - Nova - 100% Night");
|
||||||
assert_eq!(template_escape(&stem), "003 - Nova - 100%% Night");
|
assert_eq!(template_escape(&stem), "003 - Nova - 100%% Night");
|
||||||
|
|||||||
@@ -628,8 +628,22 @@ function finalMeta(c, e) {
|
|||||||
|
|
||||||
function folderFor(c) {
|
function folderFor(c) {
|
||||||
if (c.data.single || c.releaseType === "search") return null;
|
if (c.data.single || c.releaseType === "search") return null;
|
||||||
if (isRelease(c)) return [c.album.artist, c.album.title].filter(Boolean).join(" - ");
|
return c.album.title || null;
|
||||||
return c.album.title;
|
}
|
||||||
|
|
||||||
|
function kindFor(c) {
|
||||||
|
if (c.data.single || c.releaseType === "search") return "track";
|
||||||
|
return isRelease(c) ? "album" : "playlist";
|
||||||
|
}
|
||||||
|
|
||||||
|
function destFor(c) {
|
||||||
|
const s = state.settings;
|
||||||
|
const sep = s.outputDir.includes("/") ? "/" : "\\";
|
||||||
|
const folder = s.collectionFolders ? folderFor(c) : null;
|
||||||
|
const kind = kindFor(c);
|
||||||
|
if (folder && kind === "album") return [s.outputDir, "Albums", folder].join(sep);
|
||||||
|
if (folder && kind === "playlist") return [s.playlistsDir || [s.outputDir, "Playlists"].join(sep), folder].join(sep);
|
||||||
|
return [s.outputDir, "Tracks"].join(sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectedEntries(c) {
|
function selectedEntries(c) {
|
||||||
@@ -1214,7 +1228,7 @@ function updateCommit() {
|
|||||||
sel.replaceChildren(h("option", { value: "" }, "No playlist"), ...lists.map((p) => h("option", { value: p.name }, `+ ${p.name}`)));
|
sel.replaceChildren(h("option", { value: "" }, "No playlist"), ...lists.map((p) => h("option", { value: p.name }, `+ ${p.name}`)));
|
||||||
sel.value = lists.some((p) => p.name === keep) ? keep : "";
|
sel.value = lists.some((p) => p.name === keep) ? keep : "";
|
||||||
sel.hidden = lists.length === 0;
|
sel.hidden = lists.length === 0;
|
||||||
$("#destPath").textContent = folder ? `${state.settings.outputDir}${sep}${folder}` : state.settings.outputDir;
|
$("#destPath").textContent = destFor(c);
|
||||||
$("#attestText").textContent = n > 1 ? `I have the rights to these ${n}` : "I have the rights to this";
|
$("#attestText").textContent = n > 1 ? `I have the rights to these ${n}` : "I have the rights to this";
|
||||||
const btn = $("#downloadBtn");
|
const btn = $("#downloadBtn");
|
||||||
btn.disabled = n === 0 || !state.tools?.ytdlp.path;
|
btn.disabled = n === 0 || !state.tools?.ytdlp.path;
|
||||||
@@ -1237,7 +1251,8 @@ async function startDownload() {
|
|||||||
const ents = selectedEntries(c);
|
const ents = selectedEntries(c);
|
||||||
const folder = state.settings.collectionFolders ? folderFor(c) : null;
|
const folder = state.settings.collectionFolders ? folderFor(c) : null;
|
||||||
const playlist = $("#destPlaylist").value || null;
|
const playlist = $("#destPlaylist").value || null;
|
||||||
const jobs = ents.map((e) => ({ entry: e, meta: finalMeta(c, e), folder, trim: c.trims.get(e.index) || null, playlist }));
|
const kind = kindFor(c);
|
||||||
|
const jobs = ents.map((e) => ({ entry: e, meta: finalMeta(c, e), folder, trim: c.trims.get(e.index) || null, playlist, kind }));
|
||||||
const s = state.settings;
|
const s = state.settings;
|
||||||
try {
|
try {
|
||||||
const ids = await invoke("enqueue", { jobs, save: { saveAs: s.saveAs, mp3Bitrate: s.mp3Bitrate, videoHeight: s.videoHeight, videoContainer: s.videoContainer }, attested: true });
|
const ids = await invoke("enqueue", { jobs, save: { saveAs: s.saveAs, mp3Bitrate: s.mp3Bitrate, videoHeight: s.videoHeight, videoContainer: s.videoContainer }, attested: true });
|
||||||
|
|||||||
+1
-1
@@ -185,7 +185,7 @@
|
|||||||
<div><strong>Save to</strong><span id="setDir"></span></div>
|
<div><strong>Save to</strong><span id="setDir"></span></div>
|
||||||
<button class="btn" id="setDirBtn">Change…</button>
|
<button class="btn" id="setDirBtn">Change…</button>
|
||||||
</div>
|
</div>
|
||||||
<label class="setting"><div><strong>Give albums and playlists their own folder</strong><span>Named “Artist - Album”, or after the playlist.</span></div><input type="checkbox" class="switch" data-key="collectionFolders" /></label>
|
<label class="setting"><div><strong>Give albums and playlists their own folder</strong><span>Albums go in Albums, playlists in Playlists (so they show up as playlists), and single songs in Tracks.</span></div><input type="checkbox" class="switch" data-key="collectionFolders" /></label>
|
||||||
<label class="setting"><div><strong>Number tracks in albums and playlists</strong><span>Keeps files sorted in their original order.</span></div><input type="checkbox" class="switch" data-key="numberTracks" /></label>
|
<label class="setting"><div><strong>Number tracks in albums and playlists</strong><span>Keeps files sorted in their original order.</span></div><input type="checkbox" class="switch" data-key="numberTracks" /></label>
|
||||||
<div class="setting stack">
|
<div class="setting stack">
|
||||||
<div><strong>File names</strong><span>Click a token to add it. Preview: <code id="templatePreview"></code></span></div>
|
<div><strong>File names</strong><span>Click a token to add it. Preview: <code id="templatePreview"></code></span></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user