Add some more metadata options
This commit is contained in:
parent
a55a86d00e
commit
e6a371bf57
|
@ -49,13 +49,14 @@ void help() {
|
|||
"@t Title\n" <<
|
||||
"@n Track number\n" <<
|
||||
"@y Year\n" <<
|
||||
"@g Genre\n";
|
||||
"@g Genre\n" <<
|
||||
"@e File extension\n";
|
||||
|
||||
std::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
TagLib::FileRef get_file(const std::string& str) {
|
||||
return TagLib::FileRef(TagLib::FileName(str.c_str()));
|
||||
TagLib::FileRef get_file(const std::string& f) {
|
||||
return TagLib::FileRef(TagLib::FileName(f.c_str()));
|
||||
}
|
||||
|
||||
void get_metadata_from_file(const Settings& settings, const std::string& format, const std::string& file) {
|
||||
|
@ -69,7 +70,6 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
}
|
||||
|
||||
TagLib::FileRef _file = get_file(file);
|
||||
TagLib::Tag* tag = _file.tag();
|
||||
|
||||
if (_file.isNull() || !_file.audioProperties()) {
|
||||
std::cerr << "mcopy: invalid file '" << file << "' is skipped.\n";
|
||||
|
@ -80,6 +80,8 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
return;
|
||||
}
|
||||
|
||||
TagLib::Tag* tag = _file.tag();
|
||||
|
||||
struct FileData {
|
||||
std::string title{};
|
||||
std::string album{};
|
||||
|
@ -87,6 +89,8 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
std::string track{};
|
||||
std::string year{};
|
||||
std::string genre{};
|
||||
std::string comment{};
|
||||
std::string extension{};
|
||||
};
|
||||
|
||||
const auto get_title = [&tag]() -> std::string { return tag->title().to8Bit(true); };
|
||||
|
@ -95,6 +99,8 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
const auto get_track = [&tag]() -> std::string { return std::to_string(tag->track()); };
|
||||
const auto get_year = [&tag]() -> std::string { return std::to_string(tag->year()); };
|
||||
const auto get_genre = [&tag]() -> std::string { return tag->genre().to8Bit(true); };
|
||||
const auto get_comment = [&tag]() -> std::string { return tag->comment().to8Bit(true); };
|
||||
const auto get_extension = [&file]() -> std::string { return file.find_last_of(".") + 1 != file.npos ? file.substr(file.find_last_of(".") + 1) : ""; };
|
||||
|
||||
FileData data{
|
||||
get_title(),
|
||||
|
@ -103,6 +109,8 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
get_track(),
|
||||
get_year(),
|
||||
get_genre(),
|
||||
get_comment(),
|
||||
get_extension(),
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -110,7 +118,7 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
#else
|
||||
std::vector<char> the_forbidden_characters{'/'};
|
||||
#endif
|
||||
for (const auto& it : {&data.title, &data.album, &data.artist, &data.track, &data.year, &data.genre}) {
|
||||
for (const auto& it : {&data.title, &data.album, &data.artist, &data.track, &data.year, &data.genre, &data.comment, &data.extension}) {
|
||||
for (const auto& c : the_forbidden_characters)
|
||||
static_cast<void>(std::remove_if(it->begin(), it->end(), [&c](char _c) { return c == _c; }));
|
||||
}
|
||||
|
@ -122,6 +130,8 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
{"@n", data.track},
|
||||
{"@y", data.year},
|
||||
{"@g", data.genre},
|
||||
{"@c", data.comment},
|
||||
{"@e", data.extension},
|
||||
};
|
||||
|
||||
std::string output_filename = format;
|
||||
|
@ -131,7 +141,7 @@ void get_metadata_from_file(const Settings& settings, const std::string& format,
|
|||
it.second = "Unknown";
|
||||
|
||||
if (settings.ask) {
|
||||
std::cerr << "mcopy: failed to retrieve data for " << it.first << ", enter an appropriate replacement: ";
|
||||
std::cerr << "mcopy: failed to retrieve data to represent " << it.first << ", enter an appropriate replacement: ";
|
||||
std::getline(std::cin, it.second);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue