download tracks
This commit is contained in:
parent
2fdd33e064
commit
a273070144
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"sessionId" : "insert"
|
||||
"sessionId" : "insert"
|
||||
"ffmpeg" : "ffmpeg"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// +build !windows
|
||||
|
||||
package platform
|
||||
|
||||
func SanitiseFilename(filename string) (newName string, e error) {
|
||||
newName = filename
|
||||
return
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
// +build windows
|
||||
// currently untested as I don't have a windows machine to test on
|
||||
|
||||
package platform
|
||||
|
||||
import(
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func SanitiseFilename(filename string) (newName string, e error) {
|
||||
r, e := regexp.Compile("[\\?<>:\"/\\\\|\\*]")
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
|
||||
newName = r.ReplaceAllString(filename, "")
|
||||
return
|
||||
}
|
82
wimp-get.go
82
wimp-get.go
|
@ -6,8 +6,12 @@ import (
|
|||
"regexp"
|
||||
"encoding/json"
|
||||
"path"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"wimp-get/wimp"
|
||||
"wimp-get/platform"
|
||||
"os/exec"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -45,4 +49,82 @@ func main() {
|
|||
}
|
||||
|
||||
fmt.Printf("[ %s - %s (%d) ]\n", album.Artist, album.Title, album.Year)
|
||||
|
||||
// Determine whether we have more than one disc
|
||||
multidisc := false
|
||||
for _, track := range album.Tracks {
|
||||
if track.Volume > 1 {
|
||||
multidisc = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
dirName := album.Artist+" - "+album.Title+" ("+fmt.Sprintf("%d", album.Year)+") [WEB FLAC]"
|
||||
|
||||
e = os.Mkdir(dirName, os.FileMode(0755))
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
// Time to do the ripping!
|
||||
for _, track := range album.Tracks {
|
||||
num := fmt.Sprintf("%d", track.Number)
|
||||
if len(num) < 2 {
|
||||
num = "0"+num
|
||||
}
|
||||
|
||||
fmt.Printf("[%d/%s] %s...", track.Volume, num, track.Title)
|
||||
|
||||
var filename string
|
||||
if (multidisc) {
|
||||
filename = fmt.Sprintf("%s/Disc %d/%s - %s.flac", dirName, track.Volume, num, track.Title)
|
||||
} else {
|
||||
filename = fmt.Sprintf("%s/%s - %s.flac", dirName, num, track.Title)
|
||||
}
|
||||
|
||||
filename, e = platform.SanitiseFilename(filename)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
// create disc dir if necessary
|
||||
if _, e = os.Stat(path.Dir(filename)); e != nil {
|
||||
if os.IsNotExist(e) {
|
||||
e = os.Mkdir(path.Dir(filename), os.FileMode(0755))
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
} else {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
resp, e := http.Get(track.Url)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
ffmpeg := exec.Command(magic["ffmpeg"].(string), "-i", "-", "-metadata", "title="+track.Title, "-metadata", "artist="+track.Artist,
|
||||
"-metadata", "album="+album.Title, "-metadata", "year="+fmt.Sprintf("%d", album.Year), "-metadata", "track="+fmt.Sprintf("%d", track.Number),
|
||||
"-metadata", "albumartist="+album.Artist, "-metadata", "discnumber="+fmt.Sprintf("%d", track.Volume), filename)
|
||||
|
||||
stdin, e := ffmpeg.StdinPipe()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
e = ffmpeg.Start()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
_, e = io.Copy(stdin, resp.Body)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
|
||||
resp.Body.Close()
|
||||
|
||||
println(" Done!")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue