support for editing tag of local files (outside mpd music dir)
This commit is contained in:
@@ -1128,10 +1128,16 @@ int main(int argc, char *argv[])
|
|||||||
if (WriteTags(s))
|
if (WriteTags(s))
|
||||||
{
|
{
|
||||||
ShowMessage("Tags updated!");
|
ShowMessage("Tags updated!");
|
||||||
Mpd->UpdateDirectory(s.GetDirectory());
|
if (s.IsFromDB())
|
||||||
if (prev_screen == csSearcher)
|
{
|
||||||
mSearcher->Current().second = s;
|
Mpd->UpdateDirectory(s.GetDirectory());
|
||||||
|
if (prev_screen == csSearcher)
|
||||||
|
mSearcher->Current().second = s;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mPlaylist->Current() = s;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
ShowMessage("Error writing tags!");
|
ShowMessage("Error writing tags!");
|
||||||
}
|
}
|
||||||
case 15:
|
case 15:
|
||||||
@@ -2590,7 +2596,14 @@ int main(int argc, char *argv[])
|
|||||||
redraw_header = 1;
|
redraw_header = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ShowMessage("Cannot read file '" + Config.mpd_music_dir + edited_song.GetFile() + "'!");
|
{
|
||||||
|
string message = "Cannot read file '";
|
||||||
|
if (edited_song.IsFromDB())
|
||||||
|
message += Config.mpd_music_dir;
|
||||||
|
message += edited_song.GetFile();
|
||||||
|
message += "'!";
|
||||||
|
ShowMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (wCurrent == mEditorDirs)
|
else if (wCurrent == mEditorDirs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,6 +110,12 @@ bool Song::Empty() const
|
|||||||
return !itsSong || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment);
|
return !itsSong || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Song::IsFromDB() const
|
||||||
|
{
|
||||||
|
const string &dir = GetDirectory();
|
||||||
|
return dir[0] != '/' || dir == "/";
|
||||||
|
}
|
||||||
|
|
||||||
string Song::GetFile() const
|
string Song::GetFile() const
|
||||||
{
|
{
|
||||||
return !itsSong->file ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->file;
|
return !itsSong->file ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->file;
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class Song
|
|||||||
void GetEmptyFields(bool get) { itsGetEmptyFields = get; }
|
void GetEmptyFields(bool get) { itsGetEmptyFields = get; }
|
||||||
void Clear();
|
void Clear();
|
||||||
bool Empty() const;
|
bool Empty() const;
|
||||||
|
bool IsFromDB() const;
|
||||||
bool IsStream() const { return isStream; }
|
bool IsStream() const { return isStream; }
|
||||||
|
|
||||||
Song & operator=(const Song &);
|
Song & operator=(const Song &);
|
||||||
|
|||||||
@@ -34,6 +34,9 @@
|
|||||||
extern ncmpcpp_config Config;
|
extern ncmpcpp_config Config;
|
||||||
extern ncmpcpp_keys Key;
|
extern ncmpcpp_keys Key;
|
||||||
|
|
||||||
|
extern MPDConnection *Mpd;
|
||||||
|
extern Menu<Song> *mPlaylist;
|
||||||
|
|
||||||
extern Menu<string> *mTagEditor;
|
extern Menu<string> *mTagEditor;
|
||||||
extern Window *wFooter;
|
extern Window *wFooter;
|
||||||
|
|
||||||
@@ -128,7 +131,10 @@ string DisplayTag(const Song &s, void *data, const Menu<Song> *)
|
|||||||
|
|
||||||
bool GetSongTags(Song &s)
|
bool GetSongTags(Song &s)
|
||||||
{
|
{
|
||||||
string path_to_file = Config.mpd_music_dir + s.GetFile();
|
string path_to_file;
|
||||||
|
if (s.IsFromDB())
|
||||||
|
path_to_file += Config.mpd_music_dir;
|
||||||
|
path_to_file += s.GetFile();
|
||||||
|
|
||||||
TagLib::FileRef f(path_to_file.c_str());
|
TagLib::FileRef f(path_to_file.c_str());
|
||||||
if (f.isNull())
|
if (f.isNull())
|
||||||
@@ -172,7 +178,11 @@ bool GetSongTags(Song &s)
|
|||||||
bool WriteTags(Song &s)
|
bool WriteTags(Song &s)
|
||||||
{
|
{
|
||||||
using namespace TagLib;
|
using namespace TagLib;
|
||||||
string path_to_file = Config.mpd_music_dir + s.GetFile();
|
string path_to_file;
|
||||||
|
bool file_is_from_db = s.IsFromDB();
|
||||||
|
if (file_is_from_db)
|
||||||
|
path_to_file += Config.mpd_music_dir;
|
||||||
|
path_to_file += s.GetFile();
|
||||||
FileRef f(path_to_file.c_str());
|
FileRef f(path_to_file.c_str());
|
||||||
if (!f.isNull())
|
if (!f.isNull())
|
||||||
{
|
{
|
||||||
@@ -213,9 +223,28 @@ bool WriteTags(Song &s)
|
|||||||
s.GetEmptyFields(0);
|
s.GetEmptyFields(0);
|
||||||
if (!s.GetNewName().empty())
|
if (!s.GetNewName().empty())
|
||||||
{
|
{
|
||||||
string old_name = Config.mpd_music_dir + s.GetFile();
|
string old_name;
|
||||||
string new_name = Config.mpd_music_dir + s.GetDirectory() + "/" + s.GetNewName();
|
if (file_is_from_db)
|
||||||
rename(old_name.c_str(), new_name.c_str());
|
old_name += Config.mpd_music_dir;
|
||||||
|
old_name += s.GetFile();
|
||||||
|
string new_name;
|
||||||
|
if (file_is_from_db)
|
||||||
|
new_name += Config.mpd_music_dir;
|
||||||
|
new_name += s.GetDirectory() + "/" + s.GetNewName();
|
||||||
|
if (rename(old_name.c_str(), new_name.c_str()) == 0 && !file_is_from_db)
|
||||||
|
{
|
||||||
|
// if we rename local file, it won't get updated
|
||||||
|
// so just remove it from playlist and add again
|
||||||
|
int pos = mPlaylist->GetChoice();
|
||||||
|
Mpd->QueueDeleteSong(pos);
|
||||||
|
Mpd->CommitQueue();
|
||||||
|
int id = Mpd->AddSong("file://" + new_name);
|
||||||
|
if (id >= 0)
|
||||||
|
{
|
||||||
|
s = mPlaylist->Back();
|
||||||
|
Mpd->Move(s.GetPosition(), pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user