@@ -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
5884future<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" );
0 commit comments