mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package criteria
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/navidrome/navidrome/log"
|
|
)
|
|
|
|
var fieldMap = map[string]string{
|
|
"title": "media_file.title",
|
|
"album": "media_file.album",
|
|
"artist": "media_file.artist",
|
|
"albumartist": "media_file.album_artist",
|
|
"hascoverart": "media_file.has_cover_art",
|
|
"tracknumber": "media_file.track_number",
|
|
"discnumber": "media_file.disc_number",
|
|
"year": "media_file.year",
|
|
"size": "media_file.size",
|
|
"compilation": "media_file.compilation",
|
|
"dateadded": "media_file.created_at",
|
|
"datemodified": "media_file.updated_at",
|
|
"discsubtitle": "media_file.disc_subtitle",
|
|
"comment": "media_file.comment",
|
|
"lyrics": "media_file.lyrics",
|
|
"sorttitle": "media_file.sort_title",
|
|
"sortalbum": "media_file.sort_album_name",
|
|
"sortartist": "media_file.sort_artist_name",
|
|
"sortalbumartist": "media_file.sort_album_artist_name",
|
|
"albumtype": "media_file.mbz_album_type",
|
|
"albumcomment": "media_file.mbz_album_comment",
|
|
"catalognumber": "media_file.catalog_num",
|
|
"filepath": "media_file.path",
|
|
"filetype": "media_file.suffix",
|
|
"duration": "media_file.duration",
|
|
"bitrate": "media_file.bit_rate",
|
|
"bpm": "media_file.bpm",
|
|
"channels": "media_file.channels",
|
|
"genre": "genre.name",
|
|
"loved": "annotation.starred",
|
|
"dateloved": "annotation.starred_at",
|
|
"lastplayed": "annotation.play_date",
|
|
"playcount": "annotation.play_count",
|
|
"rating": "annotation.rating",
|
|
}
|
|
|
|
func mapFields(expr map[string]interface{}) map[string]interface{} {
|
|
m := make(map[string]interface{})
|
|
for f, v := range expr {
|
|
if dbf, found := fieldMap[strings.ToLower(f)]; found {
|
|
m[dbf] = v
|
|
} else {
|
|
log.Error("Invalid field in criteria", "field", f)
|
|
}
|
|
}
|
|
return m
|
|
}
|
|
|
|
type Time time.Time
|
|
|
|
func (t Time) MarshalJSON() ([]byte, error) {
|
|
//do your serializing here
|
|
stamp := fmt.Sprintf("\"%s\"", time.Time(t).Format("2006-01-02"))
|
|
return []byte(stamp), nil
|
|
}
|