Skip to content

Commit

Permalink
v0.11.0
Browse files Browse the repository at this point in the history
- 配置文件版本号为`1.7.0`
- 支持Transmission下载器
- 修改下载器代码结构
  • Loading branch information
wetor committed Jan 13, 2024
1 parent 52329a1 commit d333097
Show file tree
Hide file tree
Showing 36 changed files with 1,183 additions and 409 deletions.
47 changes: 31 additions & 16 deletions cmd/animego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path"
"strings"
"sync"
"time"

Expand All @@ -26,7 +27,9 @@ import (
"github.com/wetor/AnimeGo/internal/api"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/logger"
"github.com/wetor/AnimeGo/internal/pkg/client"
"github.com/wetor/AnimeGo/internal/pkg/client/qbittorrent"
"github.com/wetor/AnimeGo/internal/pkg/client/transmission"
"github.com/wetor/AnimeGo/internal/pkg/request"
"github.com/wetor/AnimeGo/internal/pkg/torrent"
"github.com/wetor/AnimeGo/internal/plugin"
Expand Down Expand Up @@ -160,17 +163,32 @@ func Main() {

// ===============================================================================================================
// 初始化并连接下载器
qbittorrentSrv := qbittorrent.NewQBittorrent(&qbittorrent.Options{
Url: config.Setting.Client.QBittorrent.Url,
Username: config.Setting.Client.QBittorrent.Username,
Password: config.Setting.Client.QBittorrent.Password,
DownloadPath: config.Setting.Client.QBittorrent.DownloadPath,
client.Init(&client.Options{
DownloadPath: config.Setting.Client.DownloadPath,
SeedingTimeMinute: config.Advanced.Client.SeedingTimeMinute,
ConnectTimeoutSecond: config.Advanced.Client.ConnectTimeoutSecond,
CheckTimeSecond: config.Advanced.Client.CheckTimeSecond,
RetryConnectNum: config.Advanced.Client.RetryConnectNum,
WG: &WG,
Ctx: ctx,
})
qbittorrentSrv.Start(ctx)
// TODO: 客户端初始化方式
var clientSrv api.Client
switch strings.ToLower(config.Setting.Client.Client) {
case "qbittorrent":
clientSrv = qbittorrent.NewQBittorrent(&client.AuthOptions{
Url: config.Setting.Client.Url,
Username: config.Setting.Client.Username,
Password: config.Setting.Client.Password,
})
case "transmission":
clientSrv = transmission.NewTransmission(&client.AuthOptions{
Url: config.Setting.Client.Url,
Username: config.Setting.Client.Username,
Password: config.Setting.Client.Password,
})
}
clientSrv.Start()

// ===============================================================================================================
// 初始化anisource配置
Expand Down Expand Up @@ -214,14 +232,12 @@ func Main() {
// 初始化database配置
database.Init(&database.Options{
DownloaderConf: database.DownloaderConf{
RefreshSecond: config.RefreshSecond,
DownloadPath: xpath.P(config.DownloadPath),
SavePath: xpath.P(config.SavePath),
Category: config.Category,
Tag: config.Tag,
AllowDuplicateDownload: config.Download.AllowDuplicateDownload,
SeedingTimeMinute: config.Download.SeedingTimeMinute,
Rename: config.Advanced.Download.Rename,
RefreshSecond: config.RefreshSecond,
DownloadPath: xpath.P(config.DownloadPath),
SavePath: xpath.P(config.SavePath),
Category: config.Category,
Tag: config.Tag,
Rename: config.Advanced.Download.Rename,
},
})
downloadCallback := &database.Callback{}
Expand All @@ -237,11 +253,10 @@ func Main() {
Category: config.Category,
Tag: config.Tag,
AllowDuplicateDownload: config.Download.AllowDuplicateDownload,
SeedingTimeMinute: config.Download.SeedingTimeMinute,
WG: &WG,
})
// 初始化downloader
downloaderSrv := downloader.NewManager(qbittorrentSrv, databaseSrv, databaseSrv)
downloaderSrv := downloader.NewManager(clientSrv, databaseSrv, databaseSrv)
downloadCallback.Renamed = func(data any) error {
return downloaderSrv.Delete(data.(string))
}
Expand Down
1 change: 1 addition & 0 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (c *Config) InitDir() {
c.Setting.DataPath = xpath.Abs(c.Setting.DataPath)
c.Setting.DownloadPath = xpath.Abs(c.Setting.DownloadPath)
c.Setting.SavePath = xpath.Abs(c.Setting.SavePath)
c.Setting.Client.DownloadPath = xpath.Abs(c.Setting.Client.DownloadPath)
}

func (c *Config) Proxy() string {
Expand Down
19 changes: 14 additions & 5 deletions configs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,27 @@ func TestUpdateConfig_162(t *testing.T) {
EqualFile(t, "data/animego.yaml", test.GetDataPath(testdata, "animego_162.yaml"))
}

func TestUpdateConfig_170(t *testing.T) {
configs.ConfigVersion = "1.7.0"
file, _ := test.GetData(testdata, "animego_162.yaml")
_ = os.WriteFile("data/animego.yaml", file, 0666)
configs.UpdateConfig("data/animego.yaml", false)

EqualFile(t, "data/animego.yaml", test.GetDataPath(testdata, "animego_170.yaml"))
}

func TestInitEnvConfig(t *testing.T) {
_ = os.Setenv("ANIMEGO_QBT_URL", "http://127.0.0.1:18080")
_ = os.Setenv("ANIMEGO_QBT_DOWNLOAD_PATH", "7766/download")
_ = os.Setenv("ANIMEGO_CLIENT_URL", "http://127.0.0.1:18080")
_ = os.Setenv("ANIMEGO_CLIENT_DOWNLOAD_PATH", "7766/download")
_ = os.Setenv("ANIMEGO_DOWNLOAD_PATH", "aw8da/test/download")
_ = os.Setenv("ANIMEGO_WEB_PORT", "10086")
f := test.GetDataPath(testdata, "animego_152.yaml")
f := test.GetDataPath(testdata, "animego_170.yaml")
configs.InitEnvConfig(f, "data/animego.yaml")

conf := configs.Load("data/animego.yaml")

assert.Equal(t, conf.Setting.Client.QBittorrent.Url, "http://127.0.0.1:18080")
assert.Equal(t, conf.Setting.Client.QBittorrent.DownloadPath, "7766/download")
assert.Equal(t, conf.Setting.Client.Url, "http://127.0.0.1:18080")
assert.Equal(t, conf.Setting.Client.DownloadPath, "7766/download")
assert.Equal(t, conf.Setting.DownloadPath, "aw8da/test/download")
assert.Equal(t, conf.Setting.WebApi.Port, 10086)
}
21 changes: 13 additions & 8 deletions configs/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
)

func defaultSettingComment() {
configComment["tag_help"] = `仅qBittorrent有效,可用通配符列表:
configComment["tag_help"] = `可用通配符列表:
{year} int 番剧更新年
{quarter} int 番剧季度月号,取值为[4, 7, 10, 1]分别对应[春, 夏, 秋, 冬]季番剧
{quarter_index} int 番剧季度序号,取值为[1, 2, 3, 4]分别对应春(4月)、夏(7月)、秋(10月)、冬(1月)季番剧
Expand All @@ -24,18 +24,23 @@ func defaultSettingComment() {

configComment["themoviedb_key"] = `可以自行申请链接(需注册):https://www.themoviedb.org/settings/api?language=zh-CN
以下为wetor的个人APIkey,仅用于AnimeGo使用`

configComment["seeding_key"] = `默认为0,根据客户端不同,有不同作用:
QBittorrent: 0不做种,-1无限做种,其他值为做种分钟限制
Transmission: 0为使用客户端设置,-1无限做种,其他值为做种空闲分钟限制`

}

func defaultSetting() {

defaultConfig.Setting.Client.QBittorrent.Url = "http://localhost:8080"
defaultConfig.Setting.Client.QBittorrent.Username = "admin"
defaultConfig.Setting.Client.QBittorrent.Password = "adminadmin"
defaultConfig.Setting.Client.QBittorrent.DownloadPath = "./download/incomplete"
defaultConfig.Setting.Client.Client = "QBittorrent"
defaultConfig.Setting.Client.Url = "http://localhost:8080"
defaultConfig.Setting.Client.Username = "admin"
defaultConfig.Setting.Client.Password = "adminadmin"
defaultConfig.Setting.Client.DownloadPath = "./download/incomplete"

defaultConfig.Setting.DataPath = "./data"
defaultConfig.Setting.SavePath = "./download/anime"
defaultConfig.Setting.DownloadPath = defaultConfig.Setting.Client.QBittorrent.DownloadPath
defaultConfig.Setting.DownloadPath = defaultConfig.Setting.Client.DownloadPath

defaultConfig.Setting.Category = "AnimeGo"
defaultConfig.Setting.Tag = "{year}年{quarter}月新番"
Expand Down Expand Up @@ -115,7 +120,6 @@ func defaultAdvanced() {
defaultConfig.Advanced.Request.RetryWaitSecond = 5

defaultConfig.Advanced.Download.AllowDuplicateDownload = false
defaultConfig.Advanced.Download.SeedingTimeMinute = 0
defaultConfig.Advanced.Download.Rename = "wait_move"

defaultConfig.Advanced.Feed.DelaySecond = 5
Expand All @@ -124,6 +128,7 @@ func defaultAdvanced() {
defaultConfig.Advanced.Default.TMDBFailUseTitleSeason = true
defaultConfig.Advanced.Default.TMDBFailUseFirstSeason = true

defaultConfig.Advanced.Client.SeedingTimeMinute = 0
defaultConfig.Advanced.Client.ConnectTimeoutSecond = 5
defaultConfig.Advanced.Client.RetryConnectNum = 3
defaultConfig.Advanced.Client.CheckTimeSecond = 60
Expand Down
24 changes: 12 additions & 12 deletions configs/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ type Plugin struct {

type Setting struct {
Client struct {
QBittorrent struct {
Url string `yaml:"url" json:"url" attr:"地址" comment:"环境变量ANIMEGO_QBT_URL"`
Username string `yaml:"username" json:"username" attr:"用户名" comment:"环境变量ANIMEGO_QBT_USERNAME"`
Password string `yaml:"password" json:"password" attr:"密码" comment:"环境变量ANIMEGO_QBT_PASSWORD"`
DownloadPath string `yaml:"download_path" json:"download_path" attr:"下载文件夹" comment:"环境变量ANIMEGO_QBT_DOWNLOAD_PATH"`
} `yaml:"qbittorrent" json:"qbittorrent" attr:"qBittorrent客户端"`
Client string `yaml:"client" json:"client" attr:"客户端" comment:"环境变量ANIMEGO_CLIENT. 可选[QBittorrent, Transmission],不区分大小写"`
Url string `yaml:"url" json:"url" attr:"地址" comment:"环境变量ANIMEGO_CLIENT_URL"`
Username string `yaml:"username" json:"username" attr:"用户名" comment:"环境变量ANIMEGO_CLIENT_USERNAME"`
Password string `yaml:"password" json:"password" attr:"密码" comment:"环境变量ANIMEGO_CLIENT_PASSWORD"`
DownloadPath string `yaml:"download_path" json:"download_path" attr:"下载文件夹" comment:"环境变量ANIMEGO_CLIENT_DOWNLOAD_PATH"`
} `yaml:"client" json:"client" attr:"下载客户端设置"`
DownloadPath string `yaml:"download_path" json:"download_path" attr:"下载文件夹" comment:"环境变量ANIMEGO_DOWNLOAD_PATH. 下载器的下载文件夹"`
SavePath string `yaml:"save_path" json:"save_path" attr:"保存文件夹" comment:"环境变量ANIMEGO_SAVE_PATH. 下载完成后,重命名并移动到的文件夹"`
DataPath string `yaml:"data_path" json:"data_path" attr:"数据文件夹" comment:"环境变量ANIMEGO_DATA_PATH. 用于保存数据库、插件等数据"`
Category string `yaml:"category" json:"category" attr:"分类名" comment:"环境变量ANIMEGO_CATEGORY. 仅qBittorrent有效"`
Category string `yaml:"category" json:"category" attr:"分类名" comment:"环境变量ANIMEGO_CATEGORY"`
Tag string `yaml:"tag" json:"tag" attr:"标签表达式" comment:"环境变量ANIMEGO_TAG" comment_key:"tag_help"`
WebApi struct {
AccessKey string `yaml:"access_key" json:"access_key" attr:"请求秘钥" comment:"环境变量ANIMEGO_WEB_ACCESS_KEY. 为空则不需要验证"`
Expand Down Expand Up @@ -75,7 +74,6 @@ type Advanced struct {

Download struct {
AllowDuplicateDownload bool `yaml:"allow_duplicate_download" json:"allow_duplicate_download" attr:"允许重复下载"`
SeedingTimeMinute int `yaml:"seeding_time_minute" json:"seeding_time_minute" attr:"做种时间"`
Rename string `yaml:"rename" json:"rename" attr:"重命名方式" comment_key:"rename_help"`
} `yaml:"download" json:"download" attr:"下载设置"`

Expand All @@ -90,6 +88,7 @@ type Advanced struct {
} `yaml:"default" json:"default" attr:"解析季度默认值" comment:"使用tmdb解析季度失败时,同类型默认值按优先级执行。数值越大,优先级越高"`

Client struct {
SeedingTimeMinute int `yaml:"seeding_time_minute" json:"seeding_time_minute" attr:"做种时间" comment_key:"seeding_key"`
ConnectTimeoutSecond int `yaml:"connect_timeout_second" json:"connect_timeout_second" attr:"连接超时时间"`
RetryConnectNum int `yaml:"retry_connect_num" json:"retry_connect_num" attr:"连接失败重试次数"`
CheckTimeSecond int `yaml:"check_time_second" json:"check_time_second" attr:"检查连接状态间隔时间"`
Expand All @@ -107,10 +106,11 @@ type Advanced struct {
}

type Environment struct {
QbtUrl *string `env:"QBT_URL" val:"Setting.Client.QBittorrent.Url"`
QbtUsername *string `env:"QBT_USERNAME" val:"Setting.Client.QBittorrent.Username"`
QbtPassword *string `env:"QBT_PASSWORD" val:"Setting.Client.QBittorrent.Password"`
QbtDownloadPath *string `env:"QBT_DOWNLOAD_PATH" val:"Setting.Client.QBittorrent.DownloadPath"`
Client *string `env:"CLIENT" val:"Setting.Client.Client"`
ClientUrl *string `env:"CLIENT_URL" val:"Setting.Client.Url"`
ClientUsername *string `env:"CLIENT_USERNAME" val:"Setting.Client.Username"`
ClientPassword *string `env:"CLIENT_PASSWORD" val:"Setting.Client.Password"`
ClientDownloadPath *string `env:"CLIENT_DOWNLOAD_PATH" val:"Setting.Client.DownloadPath"`

DownloadPath *string `env:"DOWNLOAD_PATH" val:"Setting.DownloadPath"`
SavePath *string `env:"SAVE_PATH" val:"Setting.SavePath"`
Expand Down
51 changes: 49 additions & 2 deletions configs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/wetor/AnimeGo/configs/version/v_152"
"github.com/wetor/AnimeGo/configs/version/v_160"
"github.com/wetor/AnimeGo/configs/version/v_161"
"github.com/wetor/AnimeGo/configs/version/v_162"
"github.com/wetor/AnimeGo/internal/animego/database"
"github.com/wetor/AnimeGo/internal/constant"
"github.com/wetor/AnimeGo/internal/models"
Expand Down Expand Up @@ -53,6 +54,7 @@ var (
"1.6.0",
"1.6.1",
"1.6.2",
"1.7.0",
}
ConfigVersion = versions[len(versions)-1] // 当前配置文件版本

Expand Down Expand Up @@ -111,6 +113,11 @@ var (
Desc: "新增Database设置",
UpdateFunc: update_161_162,
},
{
Name: versions[11],
Desc: "更改下载器配置,新增Transmission客户端支持",
UpdateFunc: update_162_170,
},
}
)

Expand Down Expand Up @@ -625,14 +632,54 @@ func update_161_162(file string) {
log.Fatal("配置文件加载错误:", err)
}

newConfig := DefaultConfig()
newConfig := &v_162.Config{}
err = copier.Copy(newConfig, oldConfig)
if err != nil {
log.Fatal("配置文件升级失败:", err)
}
newConfig.Version = "1.6.2"

log.Println("[新增] 配置项(advanced.databse.refresh_database_cron)")
log.Println("[新增] 配置项(advanced.database.refresh_database_cron)")
newConfig.Advanced.Database.RefreshDatabaseCron = "0 0 6 * * *"

content, err := encodeConfig(newConfig)
if err != nil {
log.Fatal("配置文件升级失败:", err)
}
err = os.WriteFile(file, content, 0644)
if err != nil {
log.Fatal("配置文件升级失败:", err)
}
// 强制写入
assets.WritePlugins(assets.Dir, path.Join(newConfig.DataPath, assets.Dir), false)
}

func update_162_170(file string) {
data, err := os.ReadFile(file)
if err != nil {
log.Fatal("配置文件加载错误:", err)
}
oldConfig := &v_162.Config{}
err = yaml.Unmarshal(data, oldConfig)
if err != nil {
log.Fatal("配置文件加载错误:", err)
}

newConfig := DefaultConfig()
err = copier.Copy(newConfig, oldConfig)
if err != nil {
log.Fatal("配置文件升级失败:", err)
}
newConfig.Version = "1.7.0"

log.Println("[新增] 配置项(setting.client.client)")
log.Println("[变动] 配置项(setting.client.qbittorrent) 变更为 setting.client")
newConfig.Setting.Client.Client = "QBittorrent"
newConfig.Setting.Client.Username = oldConfig.Setting.Client.QBittorrent.Username
newConfig.Setting.Client.Password = oldConfig.Setting.Client.QBittorrent.Password
newConfig.Setting.Client.Url = oldConfig.Setting.Client.QBittorrent.Url
log.Println("[变动] 配置项(advanced.download.seeding_time_minute) 变更为 advanced.client.seeding_time_minute")
newConfig.Advanced.Client.SeedingTimeMinute = oldConfig.Advanced.Download.SeedingTimeMinute

content, err := encodeConfig(newConfig)
if err != nil {
Expand Down
Loading

0 comments on commit d333097

Please sign in to comment.