get art, spectrals
This commit is contained in:
parent
a273070144
commit
861b114968
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
"sessionId" : "insert"
|
"sessionId" : "insert",
|
||||||
"ffmpeg" : "ffmpeg"
|
"ffmpeg" : "ffmpeg",
|
||||||
|
"sox" : "sox"
|
||||||
}
|
}
|
||||||
|
|
86
wimp-get.go
86
wimp-get.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"wimp-get/platform"
|
"wimp-get/platform"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -51,23 +52,32 @@ func main() {
|
||||||
fmt.Printf("[ %s - %s (%d) ]\n", album.Artist, album.Title, album.Year)
|
fmt.Printf("[ %s - %s (%d) ]\n", album.Artist, album.Title, album.Year)
|
||||||
|
|
||||||
// Determine whether we have more than one disc
|
// Determine whether we have more than one disc
|
||||||
multidisc := false
|
maxdisc := 0
|
||||||
for _, track := range album.Tracks {
|
for _, track := range album.Tracks {
|
||||||
if track.Volume > 1 {
|
if track.Volume > maxdisc {
|
||||||
multidisc = true
|
maxdisc = track.Volume
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var multidisc bool
|
||||||
|
if maxdisc > 1 {
|
||||||
|
multidisc = true
|
||||||
|
}
|
||||||
|
|
||||||
dirName := album.Artist+" - "+album.Title+" ("+fmt.Sprintf("%d", album.Year)+") [WEB FLAC]"
|
dirName := album.Artist+" - "+album.Title+" ("+fmt.Sprintf("%d", album.Year)+") [WEB FLAC]"
|
||||||
|
dirName, e = platform.SanitiseFilename(dirName)
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
|
||||||
e = os.Mkdir(dirName, os.FileMode(0755))
|
e = os.Mkdir(dirName, os.FileMode(0755))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firstFile string // we use this later to generate spectrals
|
||||||
|
|
||||||
// Time to do the ripping!
|
// Time to do the ripping!
|
||||||
for _, track := range album.Tracks {
|
for i, track := range album.Tracks {
|
||||||
num := fmt.Sprintf("%d", track.Number)
|
num := fmt.Sprintf("%d", track.Number)
|
||||||
if len(num) < 2 {
|
if len(num) < 2 {
|
||||||
num = "0"+num
|
num = "0"+num
|
||||||
|
@ -87,6 +97,10 @@ func main() {
|
||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if i == 0 {
|
||||||
|
firstFile = filename
|
||||||
|
}
|
||||||
|
|
||||||
// create disc dir if necessary
|
// create disc dir if necessary
|
||||||
if _, e = os.Stat(path.Dir(filename)); e != nil {
|
if _, e = os.Stat(path.Dir(filename)); e != nil {
|
||||||
if os.IsNotExist(e) {
|
if os.IsNotExist(e) {
|
||||||
|
@ -127,4 +141,66 @@ func main() {
|
||||||
|
|
||||||
println(" Done!")
|
println(" Done!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get art
|
||||||
|
print("Getting album art...")
|
||||||
|
|
||||||
|
resp, e := http.Get(album.CoverUrl)
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var out io.Writer
|
||||||
|
if multidisc {
|
||||||
|
var outs []io.Writer
|
||||||
|
for i := 1; i <= maxdisc; i++ {
|
||||||
|
o, e := os.Create(fmt.Sprintf("%s/Disc %d/cover.jpg", dirName, i))
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
outs = append(outs, o)
|
||||||
|
}
|
||||||
|
out = io.MultiWriter(outs...)
|
||||||
|
e = nil
|
||||||
|
} else {
|
||||||
|
out, e = os.Create(dirName+"/cover.jpg")
|
||||||
|
}
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, e = io.Copy(out, resp.Body)
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
println(" Done!")
|
||||||
|
|
||||||
|
// Generate Spectrals
|
||||||
|
var choice string
|
||||||
|
for !(choice == "y" || choice == "n") {
|
||||||
|
print("Generate spectrals? [y/n] ")
|
||||||
|
fmt.Scanln(&choice)
|
||||||
|
choice = strings.TrimRight(choice, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if choice == "y" {
|
||||||
|
full := exec.Command(magic["sox"].(string), firstFile, "-n", "remix", "1", "spectrogram",
|
||||||
|
"-x", "3000", "-y", "513", "-z", "120", "-w", "Kaiser", "-o", "SpecFull.png")
|
||||||
|
zoom := exec.Command(magic["sox"].(string), firstFile, "-n", "remix", "1", "spectrogram",
|
||||||
|
"-X", "500", "-y", "1025", "-z", "120", "-w", "Kaiser", "-S", "0:30", "-d", "0:04", "-o", "SpecZoom.png")
|
||||||
|
e = full.Run()
|
||||||
|
if e != nil {
|
||||||
|
println("Error generating full spectral!")
|
||||||
|
} else {
|
||||||
|
println("SpecFull.png written")
|
||||||
|
}
|
||||||
|
e = zoom.Run()
|
||||||
|
if e != nil {
|
||||||
|
println("Error generating zoomed spectral!")
|
||||||
|
} else {
|
||||||
|
println("SpecZoom.png written")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue