Skip to content

Commit bb3eaa0

Browse files
author
dogatech
committed
add support for stems when moving an album
1 parent 17a5062 commit bb3eaa0

File tree

2 files changed

+57
-8
lines changed

2 files changed

+57
-8
lines changed

be/src/MusicManager.cpp

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,11 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
561561
if (errorCallback) errorCallback(errMsg);
562562
return false;
563563
}
564+
// check if stems directory exists
565+
boost::filesystem::path aSongStemsFullPath(SoulSifterSettings::getInstance().get<string>("dir.stems") + aSongPath.string());
566+
boost::filesystem::path stemsSrc = aSongStemsFullPath.parent_path();
567+
bool stemsExists = boost::filesystem::exists(stemsSrc) && boost::filesystem::is_directory(stemsSrc);
568+
564569

565570
// get new directory
566571
boost::filesystem::path dest(getAlbumFullPath(*album));
@@ -576,6 +581,8 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
576581
if (errorCallback) errorCallback(errMsg);
577582
return false;
578583
}
584+
// now stems
585+
boost::filesystem::path stemsDest(SoulSifterSettings::getInstance().get<string>("dir.stems") + getAlbumSubPath(*album));
579586

580587
// create dest parent directory
581588
boost::filesystem::path destParent = dest.parent_path();
@@ -592,6 +599,23 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
592599
if (errorCallback) errorCallback(errMsg);
593600
return false;
594601
}
602+
// do same for stems
603+
if (stemsExists) {
604+
boost::filesystem::path stemsDestParent = stemsDest.parent_path();
605+
if (!boost::filesystem::exists(stemsDestParent)) {
606+
if (!boost::filesystem::create_directories(stemsDestParent)) {
607+
std::string errMsg("Unable to move stems album " + std::to_string(album->getId()) + ", because parent directory cannot be created.");
608+
LOG(WARNING) << errMsg;
609+
if (errorCallback) errorCallback(errMsg);
610+
return false;
611+
}
612+
} else if (!boost::filesystem::is_directory(stemsDestParent)) {
613+
std::string errMsg("Unable to move stems album " + std::to_string(album->getId()) + ", because destination is not a directory.");
614+
LOG(WARNING) << errMsg;
615+
if (errorCallback) errorCallback(errMsg);
616+
return false;
617+
}
618+
}
595619

596620
// move directory
597621
try {
@@ -602,15 +626,12 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
602626
if (errorCallback) errorCallback(errMsg);
603627
return false;
604628
}
605-
606-
// remove src parent directory if empty
607-
boost::filesystem::path artistDir = src.parent_path();
608-
if (boost::filesystem::is_empty(artistDir)) {
629+
// do same for stems
630+
if (stemsExists) {
609631
try {
610-
boost::filesystem::remove(artistDir);
611-
LOG(INFO) << "Removed empty artist path.";
632+
boost::filesystem::rename(stemsSrc, stemsDest);
612633
} catch (const boost::filesystem::filesystem_error& err) {
613-
std::string errMsg("Error removing directory " + artistDir.string() + ", because " + err.what());
634+
std::string errMsg("Failed moving stems album " + std::to_string(album->getId()) + " (though continuing), because " + err.what());
614635
LOG(WARNING) << errMsg;
615636
if (errorCallback) errorCallback(errMsg);
616637
}
@@ -627,6 +648,7 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
627648
LOG(WARNING) << errMsg;
628649
if (errorCallback) errorCallback(errMsg);
629650
}
651+
// TODO move music video if it exists
630652
}
631653

632654
// update coverfilepath
@@ -642,6 +664,33 @@ bool MusicManager::moveAlbum(Album* album, std::function<void(std::string)> erro
642664
}
643665
}
644666

667+
// remove src parent directory if empty
668+
// do this after the updating of db to buffer ms of time for move to complete. may not be needed, but won't hurt.
669+
boost::filesystem::path artistDir = src.parent_path();
670+
if (boost::filesystem::is_empty(artistDir)) {
671+
try {
672+
boost::filesystem::remove(artistDir);
673+
LOG(INFO) << "Removed empty artist path.";
674+
} catch (const boost::filesystem::filesystem_error& err) {
675+
std::string errMsg("Error removing directory " + artistDir.string() + ", because " + err.what());
676+
LOG(WARNING) << errMsg;
677+
if (errorCallback) errorCallback(errMsg);
678+
}
679+
}
680+
if (stemsExists) {
681+
boost::filesystem::path stemsArtistDir = stemsSrc.parent_path();
682+
if (boost::filesystem::is_empty(stemsArtistDir)) {
683+
try {
684+
boost::filesystem::remove(stemsArtistDir);
685+
LOG(INFO) << "Removed empty artist stems path.";
686+
} catch (const boost::filesystem::filesystem_error& err) {
687+
std::string errMsg("Error removing stems directory " + artistDir.string() + ", because " + err.what());
688+
LOG(WARNING) << errMsg;
689+
if (errorCallback) errorCallback(errMsg);
690+
}
691+
}
692+
}
693+
645694
// cleanup
646695
deleteVectorPointers(songs);
647696
return true;

fe/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "SoulSifter",
33
"version": "1.6.0",
44
"description": "DJ & music organization app.",
5-
"build": 3064,
5+
"build": 3068,
66
"main": "main.js",
77
"scripts": {
88
"fe:build": "vite build",

0 commit comments

Comments
 (0)