diff --git a/DESIGN b/DESIGN index 7403e7ed..dca822f8 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/PKGBUILD b/PKGBUILD index 51af1166..0c2d6f95 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Anna Schumaker pkgname=ocarina -pkgver=6.1 +pkgver=6.1.1 pkgrel=1 pkgdesc="A simple GTK and gstreamer based music player." url="http://www.ocarinaproject.net/" @@ -13,7 +13,7 @@ conflicts=() replaces=() backup=() source=("http://ocarinaproject.net/wp-content/ocarina/${pkgname}-${pkgver}.tar.gz") -sha1sums=('af56a0d391251033ebc35406ed75c8e7d56c307e') +sha1sums=('7fa6275aeba85b86988b5a3c88bafc7c6e36ec88') build() { cd "${srcdir}/${pkgname}-${pkgver}" diff --git a/core/tags.cpp b/core/tags.cpp index b6a0357a..3cae17aa 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -165,7 +165,8 @@ Track :: Track(const std::string &f, Library *l) Track :: ~Track() { - library->count--; + if (library) + library->count--; } const std::string Track :: primary_key() const @@ -232,15 +233,16 @@ 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); + library->count++; 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(); @@ -259,7 +261,7 @@ void Track :: tag() filter :: add(artist->name, id); filter :: add(album->name, id); - library->count++; + return true; } const std::string Track :: path() const @@ -366,8 +368,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 3238a2df..03bd91b7 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/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index c5a55e71..33feba53 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -217,7 +217,7 @@ True False - Ocarina 6.1 + Ocarina 6.1.1 1024 683 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/Sconscript b/tests/Sconscript index af4070ac..b03b9a7f 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -44,7 +44,7 @@ class OTest: cmd = "%s | tee %s.out" % (path, path) if test_env.Valgrind == True: cmd = "%s %s" % (valgrind, cmd) - test = test_env.Command("%s.out" % self.Name, [], "set -x pipefail; %s" % cmd) + test = test_env.Command("%s.out" % self.Name, [], "set -x; set -o pipefail; %s" % cmd) Depends(test, prog) if (check_depends == True) and (OTest.Prev != None): diff --git a/tests/core/tags.cpp b/tests/core/tags.cpp index 4c837adb..c68cb68f 100644 --- a/tests/core/tags.cpp +++ b/tests/core/tags.cpp @@ -96,11 +96,20 @@ static void test_track(struct TagArgs *args) test_not_equal(track->last_day, args->last_day); } +static void test_invalid_track(Library *lib) +{ + unsigned int library_size = lib->count; + Track *track = tagdb :: add_track("tests/Music/invalid_track", lib); + test_equal(track, TRACK_NULL); + test_equal(lib->count, library_size); +} + static void test_all_tracks() { struct TagArgs expected; + Library *library = tagdb :: add_library("tests/Music"); - expected.library = tagdb :: add_library("tests/Music"); + expected.library = library; expected.full_path = "tests/Music/1.ogg"; expected.artist = "Artist"; expected.artist_lower = "artist"; @@ -176,6 +185,8 @@ static void test_all_tracks() expected.filepath = "666.ogg"; expected.length_str = "11:06"; run_test("Tags Track Test (666.ogg)", test_track, &expected); + + run_test("Tags Track Test (Invalid)", test_invalid_track, library); } static void test_comparison() diff --git a/tests/core/version.cpp b/tests/core/version.cpp index 45c7bcea..44db3294 100644 --- a/tests/core/version.cpp +++ b/tests/core/version.cpp @@ -5,9 +5,9 @@ #include #ifdef CONFIG_DEBUG -const std::string expected = "6.1-debug"; +const std::string expected = "6.2-debug"; #else -const std::string expected = "6.1"; +const std::string expected = "6.2"; #endif /* CONFIG_DEBUG */ static void test_version() diff --git a/tests/gen_library.sh b/tests/gen_library.sh index 9255cfc8..b203919f 100755 --- a/tests/gen_library.sh +++ b/tests/gen_library.sh @@ -18,7 +18,7 @@ function tag_file() mkdir -p /tmp/ocarina/dir{1..5} for i in $(seq 5); do - cp tests/Music/* /tmp/ocarina/dir$i/ + cp tests/Music/*.ogg /tmp/ocarina/dir$i/ for f in /tmp/ocarina/dir$i/*; do tag_file $f $i