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
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ var ( ...@@ -27,6 +27,7 @@ var (
player = config.String("player", "avplay -vn -nodisp -", "Audio player program") player = config.String("player", "avplay -vn -nodisp -", "Audio player program")
doPlaylist = flag.Bool("playlist", false, "Output a playlist (m3u)") doPlaylist = flag.Bool("playlist", false, "Output a playlist (m3u)")
doDownload = flag.Bool("download", false, "Download the results of the search") 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") 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") 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 { ...@@ -43,22 +44,35 @@ func escape(s string) string {
return strings.Replace(s, " ", "%20", -1) 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) { func outputSongs(songs []*api.Song) {
fmt.Printf("#EXTM3U\n\n") fmt.Printf("#EXTM3U\n\n")
for _, song := range songs { for _, song := range songs {
if len(song.Files) == 0 { if len(song.Files) == 0 {
continue continue
} }
af := song.GetBestAudioFile() fmt.Printf("#EXTINF:-1,%s - %s - %s\n%s\n\n",
fmt.Printf("#EXTINF:-1,%s - %s - %s\n%s/dav/%s/%s/%s%s\n\n",
song.Meta.Artist, song.Meta.Artist,
song.Meta.Album, song.Meta.Album,
song.Meta.Title, song.Meta.Title,
addAuthToUrl(*serverUrl), songURL(song))
escape(song.Meta.Artist),
escape(song.Meta.Album),
escape(song.Meta.Title),
api.GetExtensionForMimeType(af.MimeType))
} }
} }
...@@ -67,7 +81,8 @@ func play(client *util.HttpClient, song *api.Song) { ...@@ -67,7 +81,8 @@ func play(client *util.HttpClient, song *api.Song) {
return return
} }
resp, err := client.GetRaw("/dl/" + song.Files[0].MD5) af := song.GetBestAudioFile()
resp, err := client.GetRaw("/dl/" + af.MD5)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment