Use 'safe' filenames on all operating systems
This commit is contained in:
parent
c89e0cd4c0
commit
f1fc0cef54
|
@ -6,11 +6,6 @@ import(
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SanitiseFilename(filename string) (newName string, e error) {
|
|
||||||
newName = filename
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func DirOf(filename string) (dirname string, e error) {
|
func DirOf(filename string) (dirname string, e error) {
|
||||||
dirname = path.Dir(filename)
|
dirname = path.Dir(filename)
|
||||||
return
|
return
|
||||||
|
|
|
@ -6,16 +6,6 @@ import(
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SanitiseFilename(filename string) (newName string, e error) {
|
|
||||||
r, e := regexp.Compile("[\\?<>:/\"\\\\|\\*]")
|
|
||||||
if e != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
newName = r.ReplaceAllString(filename, "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func DirOf(filename string) (dirname string, e error) {
|
func DirOf(filename string) (dirname string, e error) {
|
||||||
r, e := regexp.Compile(`\\[^\\]+$`)
|
r, e := regexp.Compile(`\\[^\\]+$`)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
|
14
wimp-get.go
14
wimp-get.go
|
@ -15,6 +15,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func SanitiseFilename(filename string) (newName string, e error) {
|
||||||
|
r, e := regexp.Compile("[\\?<>:/\"\\\\|\\*]")
|
||||||
|
if e != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
newName = r.ReplaceAllString(filename, "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) != 2 {
|
if len(os.Args) != 2 {
|
||||||
fmt.Printf("Usage: %s <wimp id or url>\n", os.Args[0])
|
fmt.Printf("Usage: %s <wimp id or url>\n", os.Args[0])
|
||||||
|
@ -68,7 +78,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
dirName, e = SanitiseFilename(dirName)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +100,7 @@ func main() {
|
||||||
fmt.Printf("[%d/%s] %s...", track.Volume, num, track.Title)
|
fmt.Printf("[%d/%s] %s...", track.Volume, num, track.Title)
|
||||||
|
|
||||||
var filename = fmt.Sprintf("%s - %s.flac", num, track.Title)
|
var filename = fmt.Sprintf("%s - %s.flac", num, track.Title)
|
||||||
filename, e = platform.SanitiseFilename(filename)
|
filename, e = SanitiseFilename(filename)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue