Skip to content

Commit

Permalink
feat: aixifan version
Browse files Browse the repository at this point in the history
yzqzss committed Dec 13, 2024
1 parent ec49d07 commit 2b4f823
Showing 5 changed files with 52 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
- [ ] Uploader
- [ ] mapping IA S3 protocol
- [ ] modify metadata
- [ ] Version check
- [ ] CLI
- [X] `aixifan_config.json` Config
- [x] "downloads_home_dir"
34 changes: 19 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
@@ -3,19 +3,23 @@ package main
import (
"flag"
"fmt"
"log/slog"
"os"

"github.com/saveweb/aixifan/pkg/config"
"github.com/saveweb/aixifan/pkg/downloader"
"github.com/saveweb/aixifan/pkg/utils"
)

func help() {
fmt.Println("aixifan - " + utils.GetVersion().Version + " (" + utils.GetVersion().GoVersion + ")")
fmt.Println(
`Usage: aixifan action dougaId
`Usage: aixifan action [dougaId]
Action:
down Download
up Upload to IA
version Show version
dougaId:
int-string, NOT contain 'ac' or '_'
@@ -26,30 +30,30 @@ e.g. aixifan down 32749`)
func main() {
flag.Usage = help
flag.Parse()
if flag.NArg() < 2 {
help()
os.Exit(1)
}

action := flag.Arg(0)
dougaId := flag.Arg(1)

config, err := config.LoadOrNewConfig()
if err != nil {
panic(err)
}
if err := config.MakeDownloadsHomeDir(); err != nil {
panic(err)
}

switch action {
case "down":
dougaId := flag.Arg(1)
config, err := config.LoadOrNewConfig()
if err != nil {
panic(err)
}
if err := config.MakeDownloadsHomeDir(); err != nil {
panic(err)
}

if err := downloader.Download(config.DownloadsHomeDir, dougaId); err != nil {
panic(err)
}
case "up":
panic("not implemented")
case "version":
fmt.Println(utils.GetVersion().Version)
default:
panic("unknown action")
slog.Error("Invalid action")
help()
os.Exit(2)
}
}
3 changes: 2 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"strings"

"github.com/saveweb/aixifan/pkg/extractor"
"github.com/saveweb/aixifan/pkg/utils"
"github.com/tidwall/gjson"
)

@@ -19,7 +20,7 @@ func requestDouga(client *http.Client, acId string) ([]byte, error) {
}
url := "https://www.acfun.cn/v/ac" + acId + "?quickViewId=videoInfo_new&ajaxpipe=1"
req, err := http.NewRequest("GET", url, nil)
req.Header.Set("User-Agent", "aixifanfan/0.0.1")
req.Header.Set("User-Agent", "aixifanfan/"+utils.GetVersion().Version)

resp, err := client.Do(req)
if err != nil {
3 changes: 2 additions & 1 deletion pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
@@ -12,10 +12,11 @@ import (
"github.com/saveweb/aixifan/pkg/api"
"github.com/saveweb/aixifan/pkg/extractor"
"github.com/saveweb/aixifan/pkg/ffmpeg"
"github.com/saveweb/aixifan/pkg/utils"
)

var headers = map[string]string{
"User-Agent": "aixifanfan/0.0.1",
"User-Agent": "aixifanfan/" + utils.GetVersion().Version,
}

func validateDougaId(dougaId string) bool {
28 changes: 28 additions & 0 deletions pkg/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package utils

import "runtime/debug"

type Version struct {
Version string
GoVersion string
}

// copy from github.com/internetarchive/Zeno (AGPLv3)
func GetVersion() (version Version) {
version.Version = "unknown_version"
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
version.Version = setting.Value
}

if setting.Key == "vcs.modified" {
if setting.Value == "true" {
version.Version += " (modified)"
}
}
}
version.GoVersion = info.GoVersion
}
return
}

0 comments on commit 2b4f823

Please sign in to comment.