Skip to content

Commit 9bdd43f

Browse files
author
dogatech
committed
update featuring to properly be parsed
1 parent 0fc3f7f commit 9bdd43f

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

be/src/MusicManager.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,6 @@ void MusicManager::writeTagsToSong(Song* song) {
393393
}
394394
}
395395

396-
// youtube music adds featuring and remixers to artists, so we remove it possibly here
397-
{
398-
std::vector<std::string> artists;
399-
boost::split(artists, updatedSong->getArtist(), boost::is_any_of(","));
400-
for (size_t i = 1; i < artists.size(); ++i) {
401-
if (updatedSong->getTitle().find(trim_copy(artists[i])) == std::string::npos) {
402-
artists[0] += ", " + artists[i];
403-
}
404-
}
405-
updatedSong->setArtist(artists[0]);
406-
}
407-
408396
// handle remix in song title
409397
removeOriginalMix(updatedSong);
410398
copyRemixer(updatedSong);

be/src/MusicVideoService.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,32 @@ string removeSpecialCharsFromPath(string filepath) {
5353
}
5454
}
5555

56+
// trim from start (in place)
57+
static inline void ltrim(std::string &s) {
58+
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
59+
return !std::isspace(ch);
60+
}));
61+
}
62+
63+
// trim from end (in place)
64+
static inline void rtrim(std::string &s) {
65+
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
66+
return !std::isspace(ch);
67+
}).base(), s.end());
68+
}
69+
70+
// trim from both ends (in place)
71+
static inline void trim(std::string &s) {
72+
ltrim(s);
73+
rtrim(s);
74+
}
75+
76+
// trim from both ends (copying)
77+
static inline std::string trim_copy(std::string s) {
78+
trim(s);
79+
return s;
80+
}
81+
5682
} // namespace
5783

5884
future<vector<string>> MusicVideoService::downloadAudioAsync(const string& url) {
@@ -118,10 +144,27 @@ vector<string> MusicVideoService::downloadAudio(const string& url) {
118144
string date;
119145
if (url.find("music.youtube") != std::string::npos) {
120146
// youtube music
147+
song->setTitle(ptree.get<string>("track"));
121148
LOG(DEBUG) << "artist = " << ptree.get<string>("artist");
122149
LOG(DEBUG) << "creator = " << ptree.get<string>("creator");
123-
song->setArtist(ptree.get<string>("creator"));
124-
song->setTitle(ptree.get<string>("track"));
150+
LOG(DEBUG) << "channel = " << ptree.get<string>("channel");
151+
// youtube music adds featuring and remixers to artists, so we remove it possibly here
152+
{
153+
std::vector<std::string> artists;
154+
boost::split(artists, ptree.get<string>("artist"), boost::is_any_of(","));
155+
// remove remixer
156+
for (size_t i = 1; i < artists.size(); ++i) {
157+
if (song->getTitle().find(trim_copy(artists[i])) == std::string::npos) {
158+
artists[0] += ", " + artists[i];
159+
}
160+
}
161+
song->setArtist(artists[0]);
162+
// update featuring
163+
if (song->getArtist().rfind(ptree.get<string>("channel"), 0) == 0
164+
&& ptree.get<string>("artist") != ptree.get<string>("channel")) {
165+
song->setArtist(ptree.get<string>("channel") + " (ft. " + song->getArtist().substr(ptree.get<string>("channel").length() + 2) + ")");
166+
}
167+
}
125168
album->setName(ptree.get<string>("album"));
126169
song->setTrack(ptree.get<string>("playlist_index"));
127170
date = ptree.get<string>("release_date", "00000000");

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.5.2",
44
"description": "DJ & music organization app.",
5-
"build": 3003,
5+
"build": 3006,
66
"main": "main.js",
77
"scripts": {
88
"fe:build": "vite build",

0 commit comments

Comments
 (0)