From 56baf82a4d7315faecec71fc58283eebd1b7d585 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sat, 8 Feb 2025 20:00:10 +0000 Subject: [PATCH] Fixing playlist tracks, we also don't need the tracks on the end of the regex because they will link to /s/trackid instead --- dlna/contenddirectoryservice.go | 57 +++++++++------------------------ 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/dlna/contenddirectoryservice.go b/dlna/contenddirectoryservice.go index 7057f9a6b..82b6980fc 100644 --- a/dlna/contenddirectoryservice.go +++ b/dlna/contenddirectoryservice.go @@ -39,11 +39,11 @@ var playlistRegex *regroup.ReGroup func init() { filesRegex = regroup.MustCompile("\\/Music\\/Files[\\/]?((?P.+))?") - artistRegex = regroup.MustCompile("\\/Music\\/Artists[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?[\\/]?(?[^\\/]+)?") - albumRegex = regroup.MustCompile("\\/Music\\/Albums[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?") - genresRegex = regroup.MustCompile("\\/Music\\/Genres[\\/]?(?P[^\\/]+)?[\\/]?(?P[^/]+)?[\\/]?(?P[^\\/]+)?") + artistRegex = regroup.MustCompile("\\/Music\\/Artists[\\/]?(?P[^\\/]+)?[\\/]?(?[^\\/]+)?[\\/]?") + albumRegex = regroup.MustCompile("\\/Music\\/Albums[\\/]?(?P[^\\/]+)?[\\/]?") + genresRegex = regroup.MustCompile("\\/Music\\/Genres[\\/]?(?P[^\\/]+)?[\\/]?(?P[^/]+)?[\\/]?") recentRegex = regroup.MustCompile("\\/Music\\/Recently Added[\\/]?(?P[^\\/]+)?") - playlistRegex = regroup.MustCompile("\\/Music\\/Playlist[\\/]?(?P[^\\/]+)?[\\/]?(?P[^\\/]+)?") + playlistRegex = regroup.MustCompile("\\/Music\\/Playlists[\\/]?(?P[^\\/]+)?[\\/]?") } func (cds *contentDirectoryService) updateIDString() string { @@ -136,10 +136,7 @@ func handleDefault(ret []interface{}, cds *contentDirectoryService, o object, ho } func handleArtist(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o object, host string) ([]interface{}, error) { - if matchResults["ArtistAlbumTrack"] != "" { - //This is never hit as the URL is direct to the resourcePath - log.Debug("Artist Get a track ") - } else if matchResults["ArtistAlbum"] != "" { + if matchResults["ArtistAlbum"] != "" { tracks, _ := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"album_id": matchResults["ArtistAlbum"]}}) return cds.doMediaFiles(tracks, o.Path, ret, host) } else if matchResults["Artist"] != "" { @@ -167,9 +164,7 @@ func handleArtist(matchResults map[string]string, ret []interface{}, cds *conten } func handleAlbum(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o object, host string) ([]interface{}, error) { - if matchResults["AlbumTrack"] != "" { - //This is never hit as the URL is direct to the streamPath - } else if matchResults["AlbumTitle"] != "" { + if matchResults["AlbumTitle"] != "" { tracks, _ := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"album_id": matchResults["AlbumTitle"]}}) return cds.doMediaFiles(tracks, o.Path, ret, host) } else { @@ -191,9 +186,7 @@ func handleAlbum(matchResults map[string]string, ret []interface{}, cds *content } func handleGenre(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o object, host string) ([]interface{}, error) { - if matchResults["GenreTrack"] != "" { - //This is never hit as the URL is direct to the streamPath - } else if matchResults["GenreArtist"] != "" { + if matchResults["GenreArtist"] != "" { tracks, err := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.And{ squirrel.Eq{"genre.id": matchResults["Genre"]}, squirrel.Eq{"artist_id": matchResults["GenreArtist"]}, @@ -259,15 +252,15 @@ func handleRecent(matchResults map[string]string, ret []interface{}, cds *conten } func handlePlaylists(matchResults map[string]string, ret []interface{}, cds *contentDirectoryService, o object, host string) ([]interface{}, error) { - if matchResults["PlaylistTrack"] != "" { - //This is never hit as the URL is direct to the streamPath - } else if matchResults["Playlist"] != "" { - log.Debug("Playlist only MATCH") - //x, xerr := cds.ds.Playlist(cds.ctx).Get(matchResults["Playlist"]) - return ret, nil - } else { - log.Debug("Playlist else MATCH") - indexes, err := cds.ds.Playlist(cds.ctx).GetAll() + if matchResults["Playlist"] != "" { + x, err := cds.ds.Playlist(cds.ctx).GetWithTracks(matchResults["Playlist"], false) + if err != nil { + log.Error("Error fetching playlist", "playlist", matchResults["Playlist"], err) + return ret, nil + } + return cds.doMediaFiles(x.MediaFiles(), o.Path, ret, host) + } + indexes, err := cds.ds.Playlist(cds.ctx).GetAll() if err != nil { fmt.Printf("Error retrieving Indexes: %+v", err) return nil, err @@ -280,27 +273,9 @@ func handlePlaylists(matchResults map[string]string, ret []interface{}, cds *con ret = append(ret, cds.cdsObjectToUpnpavObject(child, true, host)) } return ret, nil - } - return ret, nil } func (cds *contentDirectoryService) doMediaFiles(tracks model.MediaFiles, basePath string, ret []interface{}, host string) ([]interface{}, error) { - //TODO flesh object out with actually useful metadata about the track - /* - - Love Takes Time - - Mariah Carey - 2000-01-01 - object.item.audioItem.musicTrack - Mariah Carey - #1's - Pop - 2 - http://172.30.0.4:8200/AlbumArt/24179-17759.jpg - http://172.30.0.4:8200/MediaItems/17759.mp3 - - */ for _, track := range tracks { trackDateAsTimeObject, _ := time.Parse(time.DateOnly, track.Date)