Add support for title attribute and some code cleanups.
This commit is contained in:
parent
6a2dfd208e
commit
547a736346
1 changed files with 34 additions and 29 deletions
|
@ -44,7 +44,7 @@ music_track::music_track() :
|
|||
music_track::music_track(const config& node) :
|
||||
id_(node["name"]),
|
||||
file_path_(),
|
||||
title_(),
|
||||
title_(node["title"]),
|
||||
ms_before_(node["ms_before"]),
|
||||
ms_after_(node["ms_after"]),
|
||||
once_(node["play_once"].to_bool()),
|
||||
|
@ -81,36 +81,41 @@ void music_track::resolve()
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(_WIN32) && !defined(__APPLE__)
|
||||
FILE* f;
|
||||
f = fopen(file_path_.c_str(), "r");
|
||||
if (f == NULL) {
|
||||
LOG_AUDIO << "Error opening file '" << file_path_ << "' for track identification\n";
|
||||
return;
|
||||
}
|
||||
|
||||
OggVorbis_File vf;
|
||||
if(ov_open(f, &vf, NULL, 0) < 0) {
|
||||
LOG_AUDIO << "track does not appear to be an Ogg file '" << id_ << "', cannot be identified\n";
|
||||
ov_clear(&vf);
|
||||
return;
|
||||
}
|
||||
|
||||
vorbis_comment* comments = ov_comment(&vf, -1);
|
||||
char** user_comments = comments->user_comments;
|
||||
|
||||
bool found = false;
|
||||
for (int i=0; i< comments->comments; i++) {
|
||||
const std::string comment_string(user_comments[i]);
|
||||
const std::vector<std::string> sowas = utils::split(comment_string, '=');
|
||||
|
||||
if (sowas[0] == "TITLE" || sowas[0] == "title") {
|
||||
title_ = sowas[1];
|
||||
found = true;
|
||||
if (title_.empty()) {
|
||||
FILE* f;
|
||||
f = fopen(file_path_.c_str(), "r");
|
||||
if (f == NULL) {
|
||||
LOG_AUDIO << "Error opening file '" << file_path_
|
||||
<< "' for track identification\n";
|
||||
return;
|
||||
}
|
||||
|
||||
OggVorbis_File vf;
|
||||
if(ov_open(f, &vf, NULL, 0) < 0) {
|
||||
LOG_AUDIO << "track does not appear to be an Ogg file '"
|
||||
<< id_ << "', cannot be identified\n";
|
||||
ov_clear(&vf);
|
||||
return;
|
||||
}
|
||||
|
||||
vorbis_comment* comments = ov_comment(&vf, -1);
|
||||
char** user_comments = comments->user_comments;
|
||||
|
||||
bool found = false;
|
||||
for (int i=0; i< comments->comments; i++) {
|
||||
const std::string comment_string(user_comments[i]);
|
||||
const std::vector<std::string> comment_list = utils::split(comment_string, '=');
|
||||
|
||||
if (comment_list[0] == "TITLE" || comment_list[0] == "title") {
|
||||
title_ = comment_list[1];
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
LOG_AUDIO << "No title for music track '" << id_ << "'\n";
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
LOG_AUDIO << "No title for music track '" << id_ << "'\n";
|
||||
}
|
||||
|
||||
ov_clear(&vf);
|
||||
|
|
Loading…
Add table
Reference in a new issue