Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/config
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@
##
#use_console_editor = yes
#
## Note: This requires use_console_editor to be set to yes
##
#sync_lyrics_to_tags = no
#
##### colors definitions #####
##
## It is possible to set a background color by setting a color value
Expand Down
3 changes: 3 additions & 0 deletions doc/ncmpcpp.1
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ Path to external editor used to edit lyrics.
.B use_console_editor = yes/no
If your external editor is console application, you need to enable it.
.TP
.B sync_lyrics_to_tags = yes/no
Automatically writes saved lyrics using tags to the song file
.TP
.B colors_enabled = yes/no
No need to describe it, huh?
.TP
Expand Down
2 changes: 1 addition & 1 deletion src/lyrics_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ LyricsFetcher::Result TagsLyricsFetcher::fetch([[maybe_unused]] const std::strin

TagLib::PropertyMap properties = f.file()->properties();

if (properties.contains("LYRICS"))
if (properties.contains("LYRICS"))
{
result.first = true;
result.second = properties["LYRICS"].toString("\n\n").to8Bit(true);
Expand Down
46 changes: 46 additions & 0 deletions src/screens/lyrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@
#include <fstream>
#include <thread>

#include "tags.h"
#ifdef HAVE_TAGLIB_H
// #include <fileref.h>
// #include <tag.h>
#include <taglib/fileref.h>
#include <taglib/tag.h>
#include <taglib/mpegfile.h>
#include <taglib/id3v2tag.h>
#include <taglib/unsynchronizedlyricsframe.h>
#endif // HAVE_TAGLIB_H

#include "curses/scrollpad.h"
#include "screens/browser.h"
#include "charset.h"
Expand Down Expand Up @@ -329,6 +340,41 @@ void Lyrics::edit()
if (Config.use_console_editor)
{
runExternalConsoleCommand(Config.external_editor + " '" + filename + "'");
#ifdef HAVE_TAGLIB_H
if (Config.sync_lyrics_to_tags) {
std::string song_file;
if (m_song.isFromDatabase())
song_file += Config.mpd_music_dir;
song_file += m_song.getURI();

TagLib::MPEG::File file(song_file.c_str());
std::fstream lyrics_file(filename);
std::ostringstream ss;
ss << lyrics_file.rdbuf();

TagLib::ID3v2::Tag *id3v2Tag = file.ID3v2Tag(true);
if (!id3v2Tag) {
std::cerr << "Error: No ID3v2 tag found." << std::endl;
return;
}

TagLib::ID3v2::FrameList frames = id3v2Tag->frameList("USLT");
for (auto &frame : frames) {
id3v2Tag->removeFrame(frame, true);
}

TagLib::ID3v2::UnsynchronizedLyricsFrame *lyricsFrame = new TagLib::ID3v2::UnsynchronizedLyricsFrame();
lyricsFrame->setText(TagLib::String(ss.str(), TagLib::String::UTF8));

id3v2Tag->addFrame(lyricsFrame);

if (file.save()) {
std::cout << "Lyrics written successfully!" << std::endl;
} else {
std::cerr << "Error: Failed to save lyrics." << std::endl;
}
}
#endif // HAVE_TAGLIB_H
fetch(m_song);
}
else
Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
return --mode;
});
p.add("external_editor", &external_editor, "nano", adjust_path);
p.add("sync_lyrics_to_tags", &sync_lyrics_to_tags, "no", yes_no);
p.add("use_console_editor", &use_console_editor, "yes", yes_no);
p.add("colors_enabled", &colors_enabled, "yes", yes_no);
p.add("empty_tag_color", &empty_tags_color, "cyan");
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct Configuration
Format::AST<wchar_t> new_header_second_line;

std::string external_editor;
bool sync_lyrics_to_tags;
std::string system_encoding;
std::string execute_on_song_change;
std::string execute_on_player_state_change;
Expand Down