Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gek64 committed Oct 22, 2024
1 parent 0000d73 commit 0a71912
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 62 deletions.
6 changes: 5 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
* text eol=lf
* text=auto
*.bat text eol=crlf
*.ps1 text eol=crlf
*.sh text eol=lf
*.go text eol=lf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
go-version: 'stable'

- name: Remove old Releases
uses: dev-drprasad/[email protected].2
uses: dev-drprasad/[email protected].4
with:
keep_latest: 0
delete_tags: true
Expand Down
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
# Release Downloader

- Download Release from GitHub and Sourceforge
- Download release file with a specified name from GitHub, Gitlab, and Sourceforge
- Automatically select the latest version or select by tag name
- Get the release file download link and use it with other download tools, such as curl, wget, aria2, etc.

## Usage

### Github

```sh
# download latest release
redl -gh "obsproject/obs-studio" -p "OBS-Studio" -p ".zip" -ep "PDBs.zip"

# download release by tag
redl -gh "obsproject/obs-studio" -t "30.2.2" -p "OBS-Studio" -p ".zip" -ep "PDBs.zip"
```

### Gitlab

```sh
# download latest release
redl -gl "36189" -p ".apk" -ep ".asc"

# download release by tag
redl -gl "36189" -t "1.18.0" -p ".apk" -ep ".asc"
```
# download MPV windows from sourceforge

### SourceForge

```sh
# download release by rss url
redl -sf "https://sourceforge.net/projects/mpv-player-windows/rss?path=/64bit" -p "x86_64" -p ".7z"
```

### Use with other download tools

```sh
# output download link to stdout without download file
redl -gl "36189" -p ".asc" -nd

# download OBS windows from github
redl -gh "obsproject/obs-studio" -p "OBS-Studio" -p ".zip" -ep "pdbs"
# downlaod use other download tool(aria2 curl wget etc)
aria2c "$(redl -gl "36189" -p ".asc" -nd)"
curl -LOJ "$(redl -gl "36189" -p ".asc" -nd)"
wget --content-disposition "$(redl -gl "36189" -p ".asc" -nd)"
```

## Install
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module redl

go 1.21.4
go 1.23.2

require (
github.com/gek64/gek v1.1.3-0.20240627090940-b552e88adf02
github.com/urfave/cli/v2 v2.27.2
github.com/gek64/gek v1.1.4
github.com/urfave/cli/v2 v2.27.5
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
)
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/gek64/gek v1.1.2 h1:ogLhQNbQAXkdNQ5wLTvW+Zgbn30fjqSwy2x+8jDap+E=
github.com/gek64/gek v1.1.2/go.mod h1:yPhb4t8/dTQ57T+5XJ1vUlf0MEsSev2oaIYrBos+GsQ=
github.com/gek64/gek v1.1.3-0.20240627090940-b552e88adf02 h1:UT+46z6eFtGzN7imveZ0zHe39en/mXBkOLe+J1ra9Z0=
github.com/gek64/gek v1.1.3-0.20240627090940-b552e88adf02/go.mod h1:yPhb4t8/dTQ57T+5XJ1vUlf0MEsSev2oaIYrBos+GsQ=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/gek64/gek v1.1.4 h1:GMBPBGoJmfcNcou2THqy7p9FeXH0StAN+tFsczhxJw4=
github.com/gek64/gek v1.1.4/go.mod h1:1y6E5g/LqY/WYPFsP8cSTFWYbcUzlx4qCS7XPgQO63c=
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.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
35 changes: 0 additions & 35 deletions internal/download.go

This file was deleted.

28 changes: 28 additions & 0 deletions internal/github.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package internal

import (
"fmt"
"github.com/gek64/gek/gRelease/github"
)

type GithubAPI struct {
r *github.Release
}

func GetGithubApiLatest(repo string) (api *GithubAPI, err error) {
r, err := github.GetReleaseLatest(repo)
return &GithubAPI{r}, err
}

func GetGithubApiByTagName(repo string, tagName string) (api *GithubAPI, err error) {
r, err := github.GetReleaseByTagName(repo, tagName)
return &GithubAPI{r}, err
}

func (a *GithubAPI) GetDownloadLink(includes []string, excludes []string) (downloadLink string, err error) {
release := a.r.GetAssets(includes, excludes)
if len(release) <= 0 {
return "", fmt.Errorf("can not find the release")
}
return release[0].BrowserDownloadURL, nil
}
28 changes: 28 additions & 0 deletions internal/gitlab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package internal

import (
"fmt"
"github.com/gek64/gek/gRelease/gitlab"
)

type GitlabAPI struct {
r *gitlab.Release
}

func GetGitlabApiLatest(repo string) (api *GitlabAPI, err error) {
r, err := gitlab.GetReleaseLatest(repo)
return &GitlabAPI{r}, err
}

func GetGitlabApiByTagName(repo string, tagName string) (api *GitlabAPI, err error) {
r, err := gitlab.GetReleaseByTagName(repo, tagName)
return &GitlabAPI{r}, err
}

func (a *GitlabAPI) GetDownloadLink(includes []string, excludes []string) (downloadLink string, err error) {
release := a.r.GetAssets(includes, excludes)
if len(release) <= 0 {
return "", fmt.Errorf("can not find the release")
}
return release[0].URL, nil
}
23 changes: 23 additions & 0 deletions internal/sourceForge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package internal

import (
"fmt"
"github.com/gek64/gek/gRelease/sourceForge"
)

type SourceForgeAPI struct {
r *sourceForge.Release
}

func GetSourceForgeByRss(rssUrl string) (api *SourceForgeAPI, err error) {
r, err := sourceForge.GetReleaseByRss(rssUrl)
return &SourceForgeAPI{r}, err
}

func (a *SourceForgeAPI) GetDownloadLink(includes []string, excludes []string) (downloadLink string, err error) {
release := a.r.GetAssets(includes, excludes)
if len(release) <= 0 {
return "", fmt.Errorf("can not find the release")
}
return release[0].Link, nil
}
80 changes: 71 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"github.com/gek64/gek/gDownloader"
"github.com/gek64/gek/gToolbox"
Expand All @@ -14,8 +15,10 @@ func main() {
var github string
var gitlab string
var sourceforge string
var tagName string
var included_parts cli.StringSlice
var excluded_parts cli.StringSlice
var no_download bool
var output string

flags := []cli.Flag{
Expand All @@ -37,6 +40,12 @@ func main() {
Usage: "set sourceforge repo url",
Destination: &sourceforge,
},
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "set tag name",
Destination: &tagName,
},
&cli.StringSliceFlag{
Name: "included_parts",
Aliases: []string{"p"},
Expand All @@ -49,6 +58,12 @@ func main() {
Usage: "set release file name excluded parts",
Destination: &excluded_parts,
},
&cli.BoolFlag{
Name: "no_download",
Aliases: []string{"nd"},
Usage: "output the download link without starting to download the file",
Destination: &no_download,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Expand All @@ -64,29 +79,76 @@ func main() {

app := &cli.App{
Usage: "Release Download Tool",
Version: "v2.00",
Version: "v2.01",
Flags: flags,
Action: func(ctx *cli.Context) (err error) {
var downloadLink string

// 获取下载链接
// 获取下载地址
if github != "" {
downloadLink, err = internal.GetGithubDownloadLink(github, included_parts.Value(), excluded_parts.Value())
var a *internal.GithubAPI
if tagName != "" {
a, err = internal.GetGithubApiByTagName(github, tagName)
if err != nil {
return err
}
} else {
a, err = internal.GetGithubApiLatest(github)
if err != nil {
return err
}
}

downloadLink, err = a.GetDownloadLink(included_parts.Value(), excluded_parts.Value())
if err != nil {
return err
}
}
if gitlab != "" {
var a *internal.GitlabAPI
if tagName != "" {
a, err = internal.GetGitlabApiByTagName(gitlab, tagName)
if err != nil {
return err
}
} else {
a, err = internal.GetGitlabApiLatest(gitlab)
if err != nil {
return err
}
}

downloadLink, err = a.GetDownloadLink(included_parts.Value(), excluded_parts.Value())
if err != nil {
return err
}
} else if gitlab != "" {
fmt.Println("download release from gitlab is under development")
} else if sourceforge != "" {
downloadLink, err = internal.GetSourceForgeDownloadLink(sourceforge, included_parts.Value(), excluded_parts.Value())
}
if sourceforge != "" {
var a *internal.SourceForgeAPI
if tagName != "" {
return errors.New("sourceforge does not support searching by tag name")
} else {
a, err = internal.GetSourceForgeByRss(sourceforge)
if err != nil {
return err
}
}

downloadLink, err = a.GetDownloadLink(included_parts.Value(), excluded_parts.Value())
if err != nil {
return err
}
}

// 下载
// 不进行下载文件的情况
if no_download {
fmt.Print(downloadLink)
return nil
}

// 进行下载文件的情况
if downloadLink != "" {
err = gToolbox.CheckToolbox([]string{"curl"})
_, err = gToolbox.CheckToolbox([]string{"curl"})
if err != nil {
err := gDownloader.Download(downloadLink, output, "")
if err != nil {
Expand Down

0 comments on commit 0a71912

Please sign in to comment.