show transcode meta info in more places

This commit is contained in:
sentriz
2023-09-14 23:56:56 +01:00
parent 1cc675b6af
commit d9d234d826
7 changed files with 75 additions and 76 deletions

View File

@@ -96,7 +96,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
Order("filename").
Find(&childTracks)
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, ch := range childTracks {
toAppend := spec.NewTCTrackByFolder(ch, folder)
@@ -105,8 +105,7 @@ func (c *Controller) ServeGetMusicDirectory(r *http.Request) *spec.Response {
toAppend.ContentType = "audio/mpeg"
toAppend.Suffix = "mp3"
}
toAppend.TranscodedContentType = transcodeMIME
toAppend.TranscodedSuffix = transcodeSuffix
toAppend.TranscodeMeta = transcodeMeta
childrenObj = append(childrenObj, toAppend)
}
// respond section
@@ -270,12 +269,11 @@ func (c *Controller) ServeSearchTwo(r *http.Request) *spec.Response {
return spec.NewError(0, "find tracks: %v", err)
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, t := range tracks {
track := spec.NewTCTrackByFolder(t, t.Album)
track.TranscodedContentType = transcodeMIME
track.TranscodedSuffix = transcodeSuffix
track.TranscodeMeta = transcodeMeta
results.Tracks = append(results.Tracks, track)
}
@@ -352,12 +350,11 @@ func (c *Controller) ServeGetStarred(r *http.Request) *spec.Response {
return spec.NewError(0, "find tracks: %v", err)
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, t := range tracks {
track := spec.NewTCTrackByFolder(t, t.Album)
track.TranscodedContentType = transcodeMIME
track.TranscodedSuffix = transcodeSuffix
track.TranscodeMeta = transcodeMeta
results.Tracks = append(results.Tracks, track)
}

View File

@@ -120,12 +120,11 @@ func (c *Controller) ServeGetAlbum(r *http.Request) *spec.Response {
sub.Album = spec.NewAlbumByTags(album, album.Artists)
sub.Album.Tracks = make([]*spec.TrackChild, len(album.Tracks))
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, track := range album.Tracks {
sub.Album.Tracks[i] = spec.NewTrackByTags(track, album)
sub.Album.Tracks[i].TranscodedContentType = transcodeMIME
sub.Album.Tracks[i].TranscodedSuffix = transcodeSuffix
sub.Album.Tracks[i].TranscodeMeta = transcodeMeta
}
return sub
}
@@ -288,12 +287,11 @@ func (c *Controller) ServeSearchThree(r *http.Request) *spec.Response {
return spec.NewError(0, "find tracks: %v", err)
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, t := range tracks {
track := spec.NewTrackByTags(t, t.Album)
track.TranscodedContentType = transcodeMIME
track.TranscodedSuffix = transcodeSuffix
track.TranscodeMeta = transcodeMeta
results.Tracks = append(results.Tracks, track)
}
@@ -430,12 +428,11 @@ func (c *Controller) ServeGetSongsByGenre(r *http.Request) *spec.Response {
List: make([]*spec.TrackChild, len(tracks)),
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, t := range tracks {
sub.TracksByGenre.List[i] = spec.NewTrackByTags(t, t.Album)
sub.TracksByGenre.List[i].TranscodedContentType = transcodeMIME
sub.TracksByGenre.List[i].TranscodedSuffix = transcodeSuffix
sub.TracksByGenre.List[i].TranscodeMeta = transcodeMeta
}
return sub
@@ -503,12 +500,11 @@ func (c *Controller) ServeGetStarredTwo(r *http.Request) *spec.Response {
return spec.NewError(0, "find tracks: %v", err)
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, t := range tracks {
track := spec.NewTrackByTags(t, t.Album)
track.TranscodedContentType = transcodeMIME
track.TranscodedSuffix = transcodeSuffix
track.TranscodeMeta = transcodeMeta
results.Tracks = append(results.Tracks, track)
}
@@ -580,12 +576,11 @@ func (c *Controller) ServeGetTopSongs(r *http.Request) *spec.Response {
return sub
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, track := range tracks {
tc := spec.NewTrackByTags(track, track.Album)
tc.TranscodedContentType = transcodeMIME
tc.TranscodedSuffix = transcodeSuffix
tc.TranscodeMeta = transcodeMeta
sub.TopSongs.Tracks = append(sub.TopSongs.Tracks, tc)
}
return sub
@@ -650,12 +645,11 @@ func (c *Controller) ServeGetSimilarSongs(r *http.Request) *spec.Response {
Tracks: make([]*spec.TrackChild, len(tracks)),
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, track := range tracks {
sub.SimilarSongs.Tracks[i] = spec.NewTrackByTags(track, track.Album)
sub.SimilarSongs.Tracks[i].TranscodedContentType = transcodeMIME
sub.SimilarSongs.Tracks[i].TranscodedSuffix = transcodeSuffix
sub.SimilarSongs.Tracks[i].TranscodeMeta = transcodeMeta
}
return sub
}
@@ -721,12 +715,10 @@ func (c *Controller) ServeGetSimilarSongsTwo(r *http.Request) *spec.Response {
Tracks: make([]*spec.TrackChild, len(tracks)),
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, track := range tracks {
sub.SimilarSongsTwo.Tracks[i] = spec.NewTrackByTags(track, track.Album)
sub.SimilarSongsTwo.Tracks[i].TranscodedContentType = transcodeMIME
sub.SimilarSongsTwo.Tracks[i].TranscodedSuffix = transcodeSuffix
sub.SimilarSongsTwo.Tracks[i].TranscodeMeta = transcodeMeta
}
return sub
}

View File

@@ -165,7 +165,7 @@ func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
trackIDs := queue.GetItems()
sub.PlayQueue.List = make([]*spec.TrackChild, len(trackIDs))
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, id := range trackIDs {
switch id.Type {
@@ -178,8 +178,7 @@ func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
Preload("TrackRating", "user_id=?", user.ID).
Find(&track)
sub.PlayQueue.List[i] = spec.NewTCTrackByFolder(&track, track.Album)
sub.PlayQueue.List[i].TranscodedContentType = transcodeMIME
sub.PlayQueue.List[i].TranscodedSuffix = transcodeSuffix
sub.PlayQueue.List[i].TranscodeMeta = transcodeMeta
case specid.PodcastEpisode:
pe := db.PodcastEpisode{}
c.DB.
@@ -190,8 +189,7 @@ func (c *Controller) ServeGetPlayQueue(r *http.Request) *spec.Response {
Where("id=?", pe.PodcastID).
Find(&p)
sub.PlayQueue.List[i] = spec.NewTCPodcastEpisode(&pe, &p)
sub.PlayQueue.List[i].TranscodedContentType = transcodeMIME
sub.PlayQueue.List[i].TranscodedSuffix = transcodeSuffix
sub.PlayQueue.List[i].TranscodeMeta = transcodeMeta
}
}
return sub
@@ -243,8 +241,14 @@ func (c *Controller) ServeGetSong(r *http.Request) *spec.Response {
if errors.Is(err, gorm.ErrRecordNotFound) {
return spec.NewError(10, "couldn't find a track with that id")
}
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
sub := spec.NewResponse()
sub.Track = spec.NewTrackByTags(&track, track.Album)
sub.Track.TranscodeMeta = transcodeMeta
return sub
}
@@ -280,12 +284,11 @@ func (c *Controller) ServeGetRandomSongs(r *http.Request) *spec.Response {
sub.RandomTracks = &spec.RandomTracks{}
sub.RandomTracks.List = make([]*spec.TrackChild, len(tracks))
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for i, track := range tracks {
sub.RandomTracks.List[i] = spec.NewTrackByTags(track, track.Album)
sub.RandomTracks.List[i].TranscodedContentType = transcodeMIME
sub.RandomTracks.List[i].TranscodedSuffix = transcodeSuffix
sub.RandomTracks.List[i].TranscodeMeta = transcodeMeta
}
return sub
}

View File

@@ -204,7 +204,7 @@ func playlistRender(c *Controller, params params.Params, playlistID string, play
return resp, nil
}
transcodeMIME, transcodeSuffix := streamGetTransPrefProfile(c.DB, user.ID, params.GetOr("c", ""))
transcodeMeta := streamGetTranscodeMeta(c.DB, user.ID, params.GetOr("c", ""))
for _, path := range playlist.Items {
file, err := specidpaths.Lookup(c.DB, PathsOf(c.MusicPaths), c.PodcastsPath, path)
@@ -236,8 +236,7 @@ func playlistRender(c *Controller, params params.Params, playlistID string, play
default:
continue
}
trch.TranscodedContentType = transcodeMIME
trch.TranscodedSuffix = transcodeSuffix
trch.TranscodeMeta = transcodeMeta
resp.List = append(resp.List, trch)
}

View File

@@ -30,7 +30,7 @@ import (
// b) return a non-nil spec.Response
// _but not both_
func streamGetTransPref(dbc *db.DB, userID int, client string) (*db.TranscodePreference, error) {
func streamGetTransodePreference(dbc *db.DB, userID int, client string) (*db.TranscodePreference, error) {
var pref db.TranscodePreference
err := dbc.
Where("user_id=?", userID).
@@ -47,16 +47,19 @@ func streamGetTransPref(dbc *db.DB, userID int, client string) (*db.TranscodePre
return &pref, nil
}
func streamGetTransPrefProfile(dbc *db.DB, userID int, client string) (mime string, suffix string) {
pref, _ := streamGetTransPref(dbc, userID, client)
func streamGetTranscodeMeta(dbc *db.DB, userID int, client string) spec.TranscodeMeta {
pref, _ := streamGetTransodePreference(dbc, userID, client)
if pref == nil {
return "", ""
return spec.TranscodeMeta{}
}
profile, ok := transcode.UserProfiles[pref.Profile]
if !ok {
return "", ""
return spec.TranscodeMeta{}
}
return spec.TranscodeMeta{
TranscodedContentType: profile.MIME(),
TranscodedSuffix: profile.Suffix(),
}
return profile.MIME(), profile.Suffix()
}
var errUnknownMediaType = fmt.Errorf("media type is unknown")
@@ -287,7 +290,7 @@ func (c *Controller) ServeStream(w http.ResponseWriter, r *http.Request) *spec.R
return nil
}
pref, err := streamGetTransPref(c.DB, user.ID, params.GetOr("c", ""))
pref, err := streamGetTransodePreference(c.DB, user.ID, params.GetOr("c", ""))
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return spec.NewError(0, "couldn't find transcode preference: %v", err)
}

View File

@@ -151,6 +151,11 @@ type TracksByGenre struct {
List []*TrackChild `xml:"song" json:"song"`
}
type TranscodeMeta struct {
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
}
type TrackChild struct {
ID *specid.ID `xml:"id,attr,omitempty" json:"id,omitempty"`
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
@@ -159,7 +164,6 @@ type TrackChild struct {
ArtistID *specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
TranscodedContentType string `xml:"transcodedContentType,attr,omitempty" json:"transcodedContentType,omitempty"`
CoverID *specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
CreatedAt time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
@@ -170,7 +174,6 @@ type TrackChild struct {
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
Size int `xml:"size,attr,omitempty" json:"size,omitempty"`
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
TranscodedSuffix string `xml:"transcodedSuffix,attr,omitempty" json:"transcodedSuffix,omitempty"`
Title string `xml:"title,attr" json:"title"`
TrackNumber int `xml:"track,attr,omitempty" json:"track,omitempty"`
DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
@@ -180,6 +183,8 @@ type TrackChild struct {
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
UserRating int `xml:"userRating,attr,omitempty" json:"userRating,omitempty"`
AverageRating string `xml:"averageRating,attr,omitempty" json:"averageRating,omitempty"`
TranscodeMeta
}
type Artists struct {