New Criteria API
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package criteria
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var fieldMap = map[string]string{
|
||||
"title": "media_file.title",
|
||||
"album": "media_file.album",
|
||||
"artist": "media_file.artist",
|
||||
"albumartist": "media_file.album_artist",
|
||||
"albumartwork": "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",
|
||||
"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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user