diff --git a/client/djplay/djplay.go b/client/djplay/djplay.go index 1567fdcd32abcec818c7b6e0b845ea347bb43eab..7b7a3e019db373491906e71b86eff67e339520f7 100644 --- a/client/djplay/djplay.go +++ b/client/djplay/djplay.go @@ -27,6 +27,7 @@ var ( player = config.String("player", "avplay -vn -nodisp -", "Audio player program") doPlaylist = flag.Bool("playlist", false, "Output a playlist (m3u)") doDownload = flag.Bool("download", false, "Download the results of the search") + withDAV = flag.Bool("with-dav", false, "Use the WebDAV API (deprecated)") trackSort = flag.Bool("sort", false, "Sort output by album/track") fill = flag.Int("fill", -1, "Fill the playlist with pseudo-random results up to the specified number of total songs") ) @@ -43,22 +44,35 @@ func escape(s string) string { return strings.Replace(s, " ", "%20", -1) } +func songURL(song *api.Song) string { + af := song.GetBestAudioFile() + if af == nil { + return "" + } + + url := addAuthToUrl(*serverUrl) + if *withDAV { + return fmt.Sprintf("%s/dav/%s/%s/%s%s", + url, + escape(song.Meta.Artist), + escape(song.Meta.Album), + escape(song.Meta.Title), + api.GetExtensionForMimeType(af.MimeType)) + } + return fmt.Sprintf("%s/dl/%s", url, af.MD5) +} + func outputSongs(songs []*api.Song) { fmt.Printf("#EXTM3U\n\n") for _, song := range songs { if len(song.Files) == 0 { continue } - af := song.GetBestAudioFile() - fmt.Printf("#EXTINF:-1,%s - %s - %s\n%s/dav/%s/%s/%s%s\n\n", + fmt.Printf("#EXTINF:-1,%s - %s - %s\n%s\n\n", song.Meta.Artist, song.Meta.Album, song.Meta.Title, - addAuthToUrl(*serverUrl), - escape(song.Meta.Artist), - escape(song.Meta.Album), - escape(song.Meta.Title), - api.GetExtensionForMimeType(af.MimeType)) + songURL(song)) } } @@ -67,7 +81,8 @@ func play(client *util.HttpClient, song *api.Song) { return } - resp, err := client.GetRaw("/dl/" + song.Files[0].MD5) + af := song.GetBestAudioFile() + resp, err := client.GetRaw("/dl/" + af.MD5) if err != nil { log.Fatal(err) }