diff --git a/DESIGN b/DESIGN index b503a520..27c703ee 100644 --- a/DESIGN +++ b/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. diff --git a/core/tags.cpp b/core/tags.cpp index b6a0357a..bcd64006 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -232,15 +232,15 @@ static T *find_or_insert(const T &tag, Database &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; } diff --git a/include/core/tags.h b/include/core/tags.h index 4f7d5137..c103064d 100644 --- a/include/core/tags.h +++ b/include/core/tags.h @@ -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); diff --git a/tests/Music/invalid_track b/tests/Music/invalid_track new file mode 100644 index 00000000..b0883f38 --- /dev/null +++ b/tests/Music/invalid_track @@ -0,0 +1 @@ +abcdefghijklmnopqrstuvwxyz diff --git a/tests/core/tags.cpp b/tests/core/tags.cpp index 4c837adb..e42d6eae 100644 --- a/tests/core/tags.cpp +++ b/tests/core/tags.cpp @@ -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";