mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-07 13:51:10 +03:00
Re-implementing the genre artists/tracks, as it looks like we can
push enough restrictions into the repo to get this out. I would prefer to be able to do some sort of group-by for the "get artists by genre" path though
This commit is contained in:
parent
441439fb67
commit
5a41fb13b8
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/navidrome/navidrome/dlna/upnpav"
|
"github.com/navidrome/navidrome/dlna/upnpav"
|
||||||
"github.com/navidrome/navidrome/log"
|
"github.com/navidrome/navidrome/log"
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
|
"github.com/navidrome/navidrome/persistence"
|
||||||
"github.com/oriser/regroup"
|
"github.com/oriser/regroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -183,21 +184,30 @@ func handleAlbum(matchResults map[string]string, ret []interface{}, cds *content
|
|||||||
func handleGenre(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o contentDirectoryObject, host string) ([]interface{}, error) {
|
func handleGenre(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o contentDirectoryObject, host string) ([]interface{}, error) {
|
||||||
if matchResults["GenreArtist"] != "" {
|
if matchResults["GenreArtist"] != "" {
|
||||||
/*
|
/*
|
||||||
SELECT
|
SELECT * FROM media_file WHERE
|
||||||
media_file.*,
|
EXISTS (
|
||||||
json_extract(artist.value, '$.id') AS artist_id,
|
SELECT 1 FROM json_each(tags, '$.genre')
|
||||||
json_extract(genre.value, '$.id') AS genre_id
|
WHERE json_extract(value, '$.id') == '7bLYq0Np81m1Wgy5N31nuG'
|
||||||
FROM
|
)
|
||||||
media_file,
|
AND EXISTS (
|
||||||
json_each(media_file.tags, '$.genre') AS genre,
|
SELECT 1 FROM json_each(participants, '$.artist')
|
||||||
json_each(media_file.participants, '$.artist') AS artist
|
WHERE json_extract(value, '$.id') == '4CBFO1ymQXgsbXQgV2aPMI'
|
||||||
WHERE genre_id = $0 AND artist_id = $1
|
)
|
||||||
|
LIMIT 100
|
||||||
*/
|
*/
|
||||||
tracks, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.And{
|
|
||||||
squirrel.Eq{"genre.id": matchResults["Genre"]},
|
thisFilter := squirrel.And{
|
||||||
squirrel.Eq{"artist_id": matchResults["GenreArtist"]},
|
persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
||||||
},
|
squirrel.Eq{"key": "id"},
|
||||||
})
|
squirrel.Eq{"value": matchResults["Genre"]},
|
||||||
|
}),
|
||||||
|
persistence.Exists("json_tree(participants, '$.artist')", squirrel.And{
|
||||||
|
squirrel.Eq{"key": "id"},
|
||||||
|
squirrel.Eq{"value": matchResults["GenreArtist"]},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
tracks, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: thisFilter})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error retrieving tracks for artist and genre: %+v", err)
|
fmt.Printf("Error retrieving tracks for artist and genre: %+v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -206,31 +216,48 @@ func handleGenre(matchResults map[string]string, ret []interface{}, cds *content
|
|||||||
} else if matchResults["Genre"] != "" {
|
} else if matchResults["Genre"] != "" {
|
||||||
if matchResults["GenreArtist"] == "" {
|
if matchResults["GenreArtist"] == "" {
|
||||||
/*
|
/*
|
||||||
|
// slightly cleaner query:
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
json_extract(artist.value, '$.name') AS artist_name,
|
json_extract(a.value, '$.name') artist_name,
|
||||||
json_extract(artist.value, '$.id') AS artist_id,
|
json_extract(a.value, '$.id') artist_id,
|
||||||
json_extract(genre.value, '$.value') AS genre_name,
|
COUNT(*)
|
||||||
json_extract(genre.value, '$.id') AS genre_id
|
|
||||||
FROM
|
FROM
|
||||||
media_file,
|
media_file f,
|
||||||
json_each(media_file.tags, '$.genre') AS genre,
|
json_each(f.tags, '$.genre') as g,
|
||||||
json_each(fmedia_file.participants, '$.artist') AS artist
|
json_each(f.participants, '$.artist') as a
|
||||||
WHERE genre_id = $0
|
WHERE
|
||||||
GROUP BY artist_id
|
json_extract(g.value, '$.id') = '7bLYq0Np81m1Wgy5N31nuG'
|
||||||
|
GROUP BY artist_id;
|
||||||
*/
|
*/
|
||||||
cds.ds.Artist(cds.ctx).GetAll(model.QueryOptions{})
|
|
||||||
artists, err := cds.ds.Artist(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"genre.id": matchResults["Genre"]}})
|
thisFilter := persistence.Exists("json_tree(tags, '$.genre')", squirrel.And{
|
||||||
|
squirrel.Eq{"key": "id"},
|
||||||
|
squirrel.Eq{"value": matchResults["Genre"]},
|
||||||
|
})
|
||||||
|
mediaFiles, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: thisFilter })
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error retrieving artists for genre: %+v", err)
|
fmt.Printf("Error retrieving artists for genre: %+v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for artistIndex := range artists {
|
|
||||||
child := contentDirectoryObject{
|
artistsFound := make(map[string]string)
|
||||||
Path: path.Join(o.Path, artists[artistIndex].Name),
|
for fileIndex := range mediaFiles {
|
||||||
Id: path.Join(o.Path, artists[artistIndex].ID),
|
artists := mediaFiles[fileIndex].Participants.AllArtists()
|
||||||
|
for index := range artists {
|
||||||
|
artistsFound[artists[index].ID] = artists[index].Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for artistId := range artistsFound {
|
||||||
|
child := contentDirectoryObject {
|
||||||
|
Path: path.Join(o.Path, artistsFound[artistId]),
|
||||||
|
Id: path.Join(o.Path, artistId),
|
||||||
}
|
}
|
||||||
ret = append(ret, cds.cdsObjectToUpnpavObject(child, true, host, -1))
|
ret = append(ret, cds.cdsObjectToUpnpavObject(child, true, host, -1))
|
||||||
}
|
}
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indexes, err := cds.ds.Genre(cds.ctx).GetAll()
|
indexes, err := cds.ds.Genre(cds.ctx).GetAll()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user