Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
gek64 committed Dec 12, 2023
1 parent d3d3cba commit 2cf8b61
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 157 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Support GitHub(rope mode) and Sourceforge(rss mode)

## Usage

```
Usage:
redl {-r rope | -rss rss_link} [Options] -p [part1, part2, par3, ...]
Expand All @@ -29,17 +30,23 @@ Example:
```

## Compile

### How to compile if prebuilt binaries are not found

```sh
git clone https://github.com/gek64/redl.git
cd redl
go build -v -trimpath -ldflags "-s -w"
```

## QA

### Q: Windows Security detect `.exe` as `Trojan:Win32/Wacatac.B!ml`
A: This application does not contain any malware, backdoors, and advertisements, all released files are build by GitHub actions. For more information, see https://go.dev/doc/faq#virus

A: This application does not contain any malware, backdoors, and advertisements, all released files are build by GitHub
actions. For more information, see https://go.dev/doc/faq#virus

## License

- **GPL-3.0 License**
- See `LICENSE` for details
22 changes: 0 additions & 22 deletions download.go

This file was deleted.

18 changes: 0 additions & 18 deletions example.json

This file was deleted.

13 changes: 11 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
module redl

go 1.20
go 1.21.4

require github.com/gek64/gek v1.0.5
require (
github.com/gek64/gek v1.1.1-0.20231212032609-10e9e40c7bf4
github.com/urfave/cli/v2 v2.26.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
)
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
github.com/gek64/gek v1.0.5 h1:NlmhTxDhuwuGzBJCfOpRh1OuVZpBWebFRSE55d9fMiA=
github.com/gek64/gek v1.0.5/go.mod h1:oR4ILS9vCBpS/Fmo+Oj5qwxX8i7uWUOUq30IN4HAaJU=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/gek64/gek v1.1.1-0.20231212032609-10e9e40c7bf4 h1:T7k9JVMhW2tt3VHBkfIX+T1HAC3emXok3OiX27anssE=
github.com/gek64/gek v1.1.1-0.20231212032609-10e9e40c7bf4/go.mod h1:84OKdazk9Mi94sDNt70r7Bc1pjRm5BQtN4mPTaLZU8w=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI=
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
35 changes: 35 additions & 0 deletions internal/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package internal

import (
"fmt"
"github.com/gek64/gek/gGithub"
"github.com/gek64/gek/gSourceForge"
)

func GetSourceForgeDownloadLink(rssUrl string, includes []string, excludes []string) (downloadLink string, err error) {
api, err := gSourceForge.NewAPI(rssUrl)
if err != nil {
return "", err
}

release := api.SearchRelease(includes, excludes)

if len(release) <= 0 {
return "", fmt.Errorf("can not find the release\n")
}
return release[0].Link, nil
}

func GetGithubDownloadLink(repo string, includes []string, excludes []string) (downloadLink string, err error) {
api, err := gGithub.NewAPI(repo)
if err != nil {
return "", err
}

release := api.SearchRelease(includes, excludes)

if len(release) <= 0 {
return "", fmt.Errorf("can not find the release\n")
}
return release[0].BrowserDownloadURL, nil
}
188 changes: 76 additions & 112 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,129 +1,93 @@
package main

import (
"flag"
"fmt"
"github.com/gek64/gek/gDownloader"
"github.com/urfave/cli/v2"
"log"
"os"
"redl/internal"
)

var (
cliRepo string
cliPart string
cliRss string
cliOutput string
cliHelp bool
cliVersion bool
)

func init() {
flag.StringVar(&cliRepo, "r", "", "set repo")
flag.StringVar(&cliPart, "p", "", "set the search part of the file name to be downloaded")
flag.StringVar(&cliRss, "rss", "", "set rss link")
flag.StringVar(&cliOutput, "o", "", "set output file")
flag.BoolVar(&cliHelp, "h", false, "show help")
flag.BoolVar(&cliVersion, "v", false, "show version")
flag.Parse()

// 重写显示用法函数
flag.Usage = func() {
var helpInfo = `Usage:
redl {-r rope | -rss rss_link} [Options] -p [part1, part2, par3, ...]
Args:
-r <repo> : set repo
-p <part> : set the search part of the file name to be downloaded
-rss <rss> : set rss link
Options:
-o <output> : set output file
Other:
-h : show help
-v : show version
Example:
1) redl -r "gek64/redl" -p "windows-amd64"
2) redl -r "gek64/redl" -p "windows" "amd64"
3) redl -r "gek64/redl" -o "./release-downloader-windows-amd64.exe" -p "windows-amd64" ".exe"
4) redl -rss "https://sourceforge.net/projects/mpv-player-windows/rss?path=/64bit" -p "x86_64" ".7z"
5) redl -h
6) redl -v`
fmt.Println(helpInfo)
}

// 如果无 args 或者 指定 h 参数,打印用法后退出
if len(os.Args) == 1 || cliHelp {
flag.Usage()
os.Exit(0)
}

// 打印版本信息
if cliVersion {
showVersion()
os.Exit(0)
}

// 未传递repo或rss参数和part参数则退出
if (cliRepo == "" && cliRss == "") || cliPart == "" {
fmt.Println("Missing Repo or Rss or Part")
os.Exit(0)
func main() {
var github_repository string
var sourceforge_rss string
var included_parts cli.StringSlice
var excluded_parts cli.StringSlice
var output string

flags := []cli.Flag{
&cli.StringFlag{
Name: "github_repository",
Aliases: []string{"gr"},
Usage: "set github repository",
Destination: &github_repository,
},
&cli.StringFlag{
Name: "sourceforge_rss",
Aliases: []string{"sr"},
Usage: "set sourceforge rss",
Destination: &sourceforge_rss,
},
&cli.StringSliceFlag{
Name: "included_parts",
Aliases: []string{"p"},
Usage: "set release file name included parts",
Destination: &included_parts,
},
&cli.StringSliceFlag{
Name: "excluded_parts",
Aliases: []string{"ep"},
Usage: "set release file name excluded parts",
Destination: &excluded_parts,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Usage: "set output file",
Destination: &output,
},
}

// 同时传递repo和rss参数,则退出
if cliRepo != "" && cliRss != "" {
fmt.Println("Rope and Rss methods can only choose one")
os.Exit(0)
// 打印版本函数
cli.VersionPrinter = func(cCtx *cli.Context) {
fmt.Printf("%s", cCtx.App.Version)
}
}

func showVersion() {
var versionInfo = `v1.06`
fmt.Println(versionInfo)
}

func showChangelog() {
var versionInfo = `Changelog:
1.00:
- First release
1.01:
- Optimized error handling
1.02:
- Add aria2, wget and build-in downloader support
1.03:
- Add multi-parts support
1.04:
- Rewrite download function
1.05:
- Change the description of help, parameters such as -p "windows" ".exe" -o "./bin.exe" are not supported
1.10:
- Add SourceForge rss support`
fmt.Println(versionInfo)
}

func main() {
var downloadLink string
var err error

// 获取下载链接
if cliRepo != "" {
downloadLink, err = getGithubDownloadLink(cliRepo, append(flag.Args(), cliPart))
if err != nil {
log.Fatalln(err)
}
} else if cliRss != "" {
downloadLink, err = getSourceForgeDownloadLink(cliRss, append(flag.Args(), cliPart))
if err != nil {
log.Fatalln(err)
}
app := &cli.App{
Usage: "Release Download Tool",
Version: "v2.00",
Flags: flags,
Action: func(ctx *cli.Context) error {
var downloadLink string
var err error

// 获取下载链接
if github_repository != "" {
downloadLink, err = internal.GetGithubDownloadLink(github_repository, included_parts.Value(), excluded_parts.Value())
if err != nil {
log.Fatalln(err)
}
} else if sourceforge_rss != "" {
downloadLink, err = internal.GetSourceForgeDownloadLink(sourceforge_rss, included_parts.Value(), excluded_parts.Value())
if err != nil {
log.Fatalln(err)
}
}

// 下载
if downloadLink != "" {
err = gDownloader.Downloader(downloadLink, "", output)
if err != nil {
log.Fatalln(err)
}
}
return nil
},
}

// 下载
if downloadLink != "" {
err = gDownloader.Downloader(downloadLink, "", cliOutput)
if err != nil {
log.Fatalln(err)
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 2cf8b61

Please sign in to comment.