tags: Check that a Track was tagged correctly
Without this check we could end up creating a Track for a .ini file or some other non-audio file. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
d74d1ea634
commit
a74eaaffa6
9
DESIGN
9
DESIGN
|
@ -529,7 +529,8 @@ Tag Database:
|
|||
|
||||
Track *tagdb :: add_track(const std::string &filepath, Library *library);
|
||||
Add a new track to the track_db and return a pointer to it.
|
||||
Return NULL if this track is already in the database.
|
||||
Return NULL if this track is already in the database or if
|
||||
there is an error when tagging.
|
||||
|
||||
Library *tagdb :: add_library(const std::string &filepath);
|
||||
Add a new path to library_db. Return a pointer to the new path
|
||||
|
@ -758,7 +759,7 @@ Track Tag:
|
|||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
void tag();
|
||||
bool tag();
|
||||
const std::string path();
|
||||
void played();
|
||||
bool less_than(Track *, sort_t);
|
||||
|
@ -793,7 +794,7 @@ Track Tag:
|
|||
void write(File &f);
|
||||
Write track information to file.
|
||||
|
||||
void Track :: tag();
|
||||
bool Track :: tag();
|
||||
Use TagLib to find tags and audio properties for this file.
|
||||
|
||||
- Insert Artist, Album, and Genre into their databases and
|
||||
|
@ -802,6 +803,8 @@ Track Tag:
|
|||
- Set play_count, last_year, last_month and last_day = 0.
|
||||
- Set lowercase title and find the string form of length.
|
||||
|
||||
Return true if the track could be tagged and false otherwise.
|
||||
|
||||
const std::string Track :: path();
|
||||
Combine library->path and filepath to find the full path to
|
||||
the audio file.
|
||||
|
|
|
@ -232,15 +232,15 @@ static T *find_or_insert(const T &tag, Database<T> &db)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void Track :: tag()
|
||||
bool Track :: tag()
|
||||
{
|
||||
TagLib :: Tag *tag;
|
||||
TagLib :: AudioProperties *audio;
|
||||
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
|
||||
|
||||
if (ref.isNull()) {
|
||||
print("ERROR: Could not read tags for file %s\n", path().c_str());
|
||||
return;
|
||||
print("WARNING: Could not read tags for file %s\n", path().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
tag = ref.tag();
|
||||
|
@ -260,6 +260,7 @@ void Track :: tag()
|
|||
filter :: add(album->name, id);
|
||||
|
||||
library->count++;
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::string Track :: path() const
|
||||
|
@ -366,8 +367,10 @@ void tagdb :: commit_library()
|
|||
Track *tagdb :: add_track(const std::string &filepath, Library *library)
|
||||
{
|
||||
Track *track = track_db.insert(Track(filepath, library));
|
||||
if (track)
|
||||
track->tag();
|
||||
if (track && !track->tag()) {
|
||||
remove_track(track->id);
|
||||
track = NULL;
|
||||
}
|
||||
return track;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ public:
|
|||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
void tag();
|
||||
bool tag();
|
||||
const std::string path() const;
|
||||
void played();
|
||||
int less_than(Track *, sort_t);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
abcdefghijklmnopqrstuvwxyz
|
|
@ -51,6 +51,12 @@ static void test_library()
|
|||
test_equal(tagdb :: get_library_db().size(), (unsigned)0);
|
||||
}
|
||||
|
||||
static void test_invalid_track(Library *lib)
|
||||
{
|
||||
Track *track = tagdb :: add_track("tests/Music/invalid_track", lib);
|
||||
test_equal(track, TRACK_NULL);
|
||||
}
|
||||
|
||||
static void test_track(struct TagArgs *args)
|
||||
{
|
||||
Track *track = tagdb :: add_track(args->full_path, args->library);
|
||||
|
@ -99,8 +105,11 @@ static void test_track(struct TagArgs *args)
|
|||
static void test_all_tracks()
|
||||
{
|
||||
struct TagArgs expected;
|
||||
Library *library = tagdb :: add_library("tests/Music");
|
||||
|
||||
expected.library = tagdb :: add_library("tests/Music");
|
||||
run_test("Tags Track Test (Invalid)", test_invalid_track, library);
|
||||
|
||||
expected.library = library;
|
||||
expected.full_path = "tests/Music/1.ogg";
|
||||
expected.artist = "Artist";
|
||||
expected.artist_lower = "artist";
|
||||
|
|
Loading…
Reference in New Issue