Skip to content

Commit

Permalink
Fix multiple id3v2.4 genres appearing as one big concatenated genre
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 20, 2021
1 parent 69f71be commit 2742977
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion persistence/genre_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewGenreRepository(ctx context.Context, o orm.Ormer) model.GenreRepository
}

func (r *genreRepository) GetAll() (model.Genres, error) {
sq := Select("*",
sq := Select("genre.*",
"count(distinct a.album_id) as album_count",
"count(distinct f.media_file_id) as song_count").
From(r.tableName).
Expand Down
7 changes: 1 addition & 6 deletions persistence/sql_genres.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ func (r sqlRepository) withGenres(sql SelectBuilder) SelectBuilder {
}

func (r *sqlRepository) updateGenres(id string, tableName string, genres model.Genres) error {
var ids []string
for _, g := range genres {
ids = append(ids, g.ID)
}
del := Delete(tableName + "_genres").Where(
And{Eq{tableName + "_id": id}, Eq{"genre_id": ids}})
del := Delete(tableName + "_genres").Where(Eq{tableName + "_id": id})
_, err := r.executeSQL(del)
if err != nil {
return err
Expand Down
12 changes: 5 additions & 7 deletions scanner/metadata/taglib.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func (e *taglibExtractor) extractMetadata(filePath string) (*Tags, error) {
}

tags := NewTags(filePath, parsedTags, map[string][]string{
"title": {"_track", "titlesort"},
"album": {"_album", "albumsort"},
"artist": {"_artist", "artistsort"},
"genre": {"_genre"},
"date": {"_year"},
"track": {"_track"},
"duration": {"length"},
"title": {"_track", "titlesort"},
"album": {"_album", "albumsort"},
"artist": {"_artist", "artistsort"},
"date": {"_year"},
"track": {"_track"},
})

return tags, nil
Expand Down
6 changes: 1 addition & 5 deletions scanner/metadata/taglib/taglib_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int taglib_read(const char *filename, unsigned long id) {

// Add audio properties to the tags
const TagLib::AudioProperties *props(f.audioProperties());
go_map_put_int(id, (char *)"length", props->length());
go_map_put_int(id, (char *)"duration", props->length());
go_map_put_int(id, (char *)"bitrate", props->bitrate());

TagLib::PropertyMap tags = f.file()->properties();
Expand All @@ -40,9 +40,6 @@ int taglib_read(const char *filename, unsigned long id) {
if (!basic->album().isEmpty()) {
tags.insert("_album", basic->album());
}
if (!basic->genre().isEmpty()) {
tags.insert("_genre", basic->genre());
}
if (basic->year() > 0) {
tags.insert("_year", TagLib::String::number(basic->year()));
}
Expand All @@ -64,7 +61,6 @@ int taglib_read(const char *filename, unsigned long id) {
}
}

// Get only the first occurrence of each tag (for now)
for (TagLib::PropertyMap::ConstIterator i = tags.begin(); i != tags.end();
++i) {
for (TagLib::StringList::ConstIterator j = i->second.begin();
Expand Down
2 changes: 1 addition & 1 deletion scanner/metadata/taglib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ = Describe("taglibExtractor", func() {
Expect(m.Artist()).To(Equal("Artist"))
Expect(m.AlbumArtist()).To(Equal("Album Artist"))
Expect(m.Compilation()).To(BeTrue())
Expect(m.Genres()).To(ConsistOf("Rock", "Rock"))
Expect(m.Genres()).To(ConsistOf("Rock"))
Expect(m.Year()).To(Equal(2014))
n, t := m.TrackNumber()
Expect(n).To(Equal(2))
Expand Down

0 comments on commit 2742977

Please sign in to comment.