From a44efeefee821d1bd71e6312afade7552c0d1a98 Mon Sep 17 00:00:00 2001 From: Marcus Crane Date: Wed, 27 Jan 2021 20:37:33 +1300 Subject: [PATCH] [v1.11.0] The Arbitrary Release * Adds a version number to the CLI help * Removes any unicode characters from file names that are invalid * Updates to v2 of urfave/cli --- .gitignore | 1 + go.mod | 2 +- go.sum | 6 +++--- main.go | 28 ++++++++++++++++++++++------ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index e43b0f9..22b85c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +main diff --git a/go.mod b/go.mod index 5bc7a1b..188ec18 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/mattn/go-colorable v0.1.8 // indirect - github.com/urfave/cli v1.22.5 + github.com/urfave/cli/v2 v2.3.0 github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945 golang.org/x/net v0.0.0-20201224014010-6772e930b67b gopkg.in/VividCortex/ewma.v1 v1.1.1 // indirect diff --git a/go.sum b/go.sum index fe5f61c..b584660 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= -github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945 h1:6Ju8pZBYFTN9FaV/JvNBiIHcsgEmP4z4laciqjfjY8E= github.com/yhat/scrape v0.0.0-20161128144610-24b7890b0945/go.mod h1:4vRFPPNYllgCacoj+0FoKOjTW68rUhEfqPLiEJaK2w8= golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw= @@ -37,4 +37,4 @@ gopkg.in/mattn/go-isatty.v0 v0.0.4 h1:NtS1rQGQr4IaFWBGz4Cz4BhB///gyys4gDVtKA7hIs gopkg.in/mattn/go-isatty.v0 v0.0.4/go.mod h1:wt691ab7g0X4ilKZNmMII3egK0bTxl37fEn/Fwbd8gc= gopkg.in/mattn/go-runewidth.v0 v0.0.4 h1:r0P71TnzQDlNIcizCqvPSSANoFa3WVGtcNJf3TWurcY= gopkg.in/mattn/go-runewidth.v0 v0.0.4/go.mod h1:BmXejnxvhwdaATwiJbB1vZ2dtXkQKZGu9yLFCZb4msQ= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index dbcdb13..17ef6c8 100644 --- a/main.go +++ b/main.go @@ -8,8 +8,9 @@ import ( "os" "os/user" "strings" + "unicode/utf8" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "github.com/yhat/scrape" "golang.org/x/net/html" "golang.org/x/net/html/atom" @@ -105,11 +106,12 @@ func downloadFile(filepath string, url string) (err error) { } func main() { - app := cli.NewApp() - app.Name = "khinsider" - app.Usage = "Fetch albums from download.khinsider.com" - app.Action = func(c *cli.Context) error { - album := c.Args().Get(0) + app := cli.NewApp() + app.Name = "khinsider" + app.Usage = "Fetch albums from download.khinsider.com" + app.Version = "1.11.0" // damn, versioning for this sucks huh + app.Action = func(c *cli.Context) error { + album := c.Args().Get(0) if album != "" { queryResults := scrapeAlbum(album) if queryResults == nil { @@ -126,6 +128,20 @@ func main() { track := queryResults.Tracks[i] track.Link = pullAudioStream(track.Link) fmt.Printf("Downloading %02d %s\n", track.Number, track.Title) + // this should hold for now until i do a proper rewrite + if !utf8.ValidString(track.Title) { + validString := make([]rune, 0, len(track.Title)) + for i, r := range track.Title { + if r == utf8.RuneError { + _, size := utf8.DecodeRuneInString(track.Title[i:]) + if size == 1 { + continue + } + } + validString = append(validString, r) + } + track.Title = string(validString) + } filePath := fmt.Sprintf(usr.HomeDir+"/Downloads/%s/%02d %s.mp3", album, track.Number, track.Title) downloadFile(filePath, track.Link) }