Skip to content

Commit

Permalink
[v1.11.0] The Arbitrary Release
Browse files Browse the repository at this point in the history
* Adds a version number to the CLI help
* Removes any unicode characters from file names that are invalid
* Updates to v2 of urfave/cli
  • Loading branch information
marcus-crane committed Jan 27, 2021
1 parent 1edcf6b commit a44efee
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
main
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
28 changes: 22 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit a44efee

Please sign in to comment.