Skip to content
Snippets Groups Projects
Commit 501e6d69 authored by ale's avatar ale
Browse files

use a flag to control if DAV urls are generated or not

parent 7d214247
Branches
No related tags found
No related merge requests found
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment