tags: Read and Write a Track tag
Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
72cea29c61
commit
c15c5149bc
21
lib/tags.cpp
21
lib/tags.cpp
|
@ -168,10 +168,31 @@ const std::string Track :: primary_key() const
|
|||
|
||||
void Track :: read(File &f)
|
||||
{
|
||||
unsigned int library_id, artist_id, album_id, genre_id;
|
||||
|
||||
f >> library_id >> artist_id >> album_id >> genre_id;
|
||||
f >> track >> last_year >> last_month >> last_day;
|
||||
f >> play_count >> length;
|
||||
|
||||
title = f.getline();
|
||||
filepath = f.getline();
|
||||
|
||||
library = library_db.at(library_id);
|
||||
artist = artist_db.at(artist_id);
|
||||
album = album_db.at(album_id);
|
||||
genre = genre_db.at(genre_id);
|
||||
|
||||
title_lower = filter :: add(title, id);
|
||||
set_length_str();
|
||||
}
|
||||
|
||||
void Track :: write(File &f)
|
||||
{
|
||||
f << library->id << " " << artist->id << " " << album->id << " ";
|
||||
f << genre->id << " " << track << " ";
|
||||
f << last_year << " " << last_month << " " << last_day << " ";
|
||||
f << play_count << " " << length << " " << title << std::endl;
|
||||
f << filepath << std::endl;
|
||||
}
|
||||
|
||||
void Track :: set_length_str()
|
||||
|
|
|
@ -120,11 +120,12 @@ void library_test()
|
|||
}
|
||||
|
||||
|
||||
void track_test_tags(Track &track)
|
||||
void track_test_tags(Track &track, Library *library)
|
||||
{
|
||||
test_results(track.filepath == "1.ogg", __LINE__);
|
||||
test_results(track.path() == "Music/1.ogg", __LINE__);
|
||||
test_results(track.primary_key() == "Music/1.ogg", __LINE__);
|
||||
test_results(track.library == library, __LINE__);
|
||||
test_results(track.play_count == 0, __LINE__);
|
||||
test_results(track.last_year == 0, __LINE__);
|
||||
test_results(track.last_month == 0, __LINE__);
|
||||
|
@ -141,18 +142,15 @@ void track_test_search(const std::string &term, unsigned int expected,
|
|||
|
||||
void track_test_basics(Library *library)
|
||||
{
|
||||
Track track("Music/1.ogg", library);
|
||||
|
||||
track_test_tags(track);
|
||||
test_results(track.library == library, __LINE__);
|
||||
Track track("Music/1.ogg", library), track2;
|
||||
track_test_tags(track, library);
|
||||
test_results(track.artist == NULL, __LINE__);
|
||||
test_results(track.album == NULL, __LINE__);
|
||||
test_results(track.genre == NULL, __LINE__);
|
||||
|
||||
track.tag();
|
||||
|
||||
track_test_tags(track);
|
||||
test_results(track.library == library, __LINE__);
|
||||
track_test_tags(track, library);
|
||||
test_results(track.artist->name == "Artist", __LINE__);
|
||||
test_results(track.album->name == "Album", __LINE__);
|
||||
test_results(track.album->year == 2014, __LINE__);
|
||||
|
@ -165,6 +163,18 @@ void track_test_basics(Library *library)
|
|||
track_test_search("One", track.id, __LINE__);
|
||||
track_test_search("Artist", track.id, __LINE__);
|
||||
track_test_search("Album", track.id, __LINE__);
|
||||
|
||||
save_tag("track.txt", track);
|
||||
load_tag("track.txt", track2);
|
||||
track_test_tags(track2, library);
|
||||
test_results(track.artist == track2.artist, __LINE__);
|
||||
test_results(track.album == track2.album, __LINE__);
|
||||
test_results(track.genre == track2.genre, __LINE__);
|
||||
test_results(track.track == track2.track, __LINE__);
|
||||
test_results(track.length == track2.length, __LINE__);
|
||||
test_results(track.length_str == track2.length_str, __LINE__);
|
||||
test_results(track.title == track2.title, __LINE__);
|
||||
test_results(track.title_lower == track2.title_lower, __LINE__);
|
||||
}
|
||||
|
||||
void track_test_lenstrs(const std::string &file, const std::string &expected,
|
||||
|
|
Loading…
Reference in New Issue