library: Find album and genre tags

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-11-10 16:45:52 -05:00 committed by Anna Schumaker
parent 10fd3292fd
commit 3f943aa1d6
4 changed files with 133 additions and 5 deletions

View File

@ -34,6 +34,38 @@ namespace library
};
class Album : public DatabaseEntry {
public:
std:: string name;
unsigned int year;
unsigned int artist_id;
Album();
Album(const std :: string &, unsigned int, unsigned int);
void read(File &);
void write(File &);
#ifdef CONFIG_DEBUG
void print();
#endif /* CONFIG_DEBUG */
bool operator==(const Album &);
};
class Genre : public DatabaseEntry {
public:
std:: string name;
Genre();
Genre(const std :: string &);
void read(File &);
void write(File &);
#ifdef CONFIG_DEBUG
void print();
#endif /* CONFIG_DEBUG */
bool operator==(const Genre &);
};
class Library : public DatabaseEntry {
public:
std::string root_path;

View File

@ -8,6 +8,8 @@
#include <taglib/fileref.h>
static Database<library :: Artist> artist_db("artist.db", DB_UNIQUE);
static Database<library :: Album> album_db("album.db", DB_UNIQUE);
static Database<library :: Genre> genre_db("genre.db", DB_UNIQUE);
static Database<library :: Library> library_db("library.db", DB_NORMAL);
@ -15,6 +17,7 @@ static Database<library :: Library> library_db("library.db", DB_NORMAL);
/*
* library :: Artist: Artist tag information
*/
library :: Artist :: Artist()
: name("")
{
@ -48,6 +51,87 @@ bool library :: Artist :: operator==(const library :: Artist &rhs)
}
/*
* library :: Album: Album tag information
*/
library :: Album :: Album()
: name(""), year(0), artist_id(0)
{
}
library :: Album :: Album(const std :: string &album_name, unsigned int album_year,
unsigned int artist)
: name(album_name), year(album_year), artist_id(artist)
{
}
void library :: Album :: read(File &f)
{
f >> artist_id >> year;
name = f.getline();
}
void library :: Album :: write(File &f)
{
f << artist_id << " " << year << " " << name;
}
#ifdef CONFIG_DEBUG
void library :: Album :: print()
{
:: print("Album: %s (%u) by %s", name.c_str(), year, artist_db[artist_id].name.c_str());
}
#endif /* CONFIG_DEBUG */
bool library :: Album :: operator==(const library :: Album &rhs)
{
if (artist_id == rhs.artist_id) {
if (name == rhs.name)
return year == rhs.year;
}
return false;
}
/*
* library :: Genre: Genre tag information
*/
library :: Genre :: Genre()
: name("")
{
}
library :: Genre :: Genre(const std::string &artist_name)
: name(artist_name)
{
}
void library :: Genre :: read(File &f)
{
name = f.getline();
}
void library :: Genre :: write(File &f)
{
f << name;
}
#ifdef CONFIG_DEBUG
void library :: Genre :: print()
{
:: print("Genre: %s", name.c_str());
}
#endif /* CONFIG_DEBUG */
bool library :: Genre :: operator==(const library :: Genre &rhs)
{
return name == rhs.name;
}
/*
* library :: Library: Basic information about each directory in the library
@ -101,6 +185,7 @@ static void read_tags(unsigned int lib_id, const std :: string &path)
{
TagLib :: Tag *tag;
TagLib :: FileRef ref(path.c_str());
unsigned int artist_id;
if (ref.isNull()) {
print("ERROR: Could not read tags for file %s", path.c_str());
@ -108,7 +193,9 @@ static void read_tags(unsigned int lib_id, const std :: string &path)
}
tag = ref.tag();
artist_db.insert(tag->artist().to8Bit(true));
artist_id = artist_db.insert(library :: Artist(tag->artist().to8Bit(true)));
album_db.insert(library :: Album(tag->album().to8Bit(true), tag->year(), artist_id));
genre_db.insert(library :: Genre(tag->genre().to8Bit(true)));
}
static void process_path(unsigned int lib_id, const std :: string &dir,
@ -180,9 +267,15 @@ void library :: update_path(unsigned int id)
void library :: print_db(DB_Type type)
{
switch (type) {
case DB_ALBUM:
album_db.print();
break;
case DB_ARTIST:
artist_db.print();
break;
case DB_GENRE:
genre_db.print();
break;
case DB_LIBRARY:
library_db.print();
break;
@ -193,7 +286,9 @@ void library :: print_db(DB_Type type)
void library :: reset()
{
album_db.clear();
artist_db.clear();
genre_db.clear();
library_db.clear();
}
#endif /* CONFIG_DEBUG */

View File

@ -54,10 +54,7 @@ function gen_tracks()
#
function gen_albums()
{
let begin=$2*3
let end=$begin+3
for i in $(seq $begin $end); do
for i in $(seq 0 2); do
gen_tracks $1 $2 $i
done
}

View File

@ -91,6 +91,10 @@ void test_4()
test_add_dir("4a", "/tmp/library/0", true);
library :: print_db(library :: DB_ARTIST);
print("\n");
library :: print_db(library :: DB_ALBUM);
print("\n");
library :: print_db(library :: DB_GENRE);
}
int main(int argc, char **argv)