Skip to content

Commit

Permalink
fix some bad style codes
Browse files Browse the repository at this point in the history
  • Loading branch information
sagan committed Aug 17, 2023
1 parent db9f503 commit fe2933d
Show file tree
Hide file tree
Showing 54 changed files with 440 additions and 449 deletions.
16 changes: 8 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Torrent struct {
SizeCompleted int64
Seeders int64
Leechers int64
Meta map[string](int64)
Meta map[string]int64
}

type TorrentContentFile struct {
Expand Down Expand Up @@ -90,8 +90,8 @@ type Client interface {
GetTorrent(infoHash string) (*Torrent, error)
// stateFilter: _all|_active|_done|_undone, or any state value (possibly with a _ prefix)
GetTorrents(stateFilter string, category string, showAll bool) ([]Torrent, error)
AddTorrent(torrentContent []byte, option *TorrentOption, meta map[string](int64)) error
ModifyTorrent(infoHash string, option *TorrentOption, meta map[string](int64)) error
AddTorrent(torrentContent []byte, option *TorrentOption, meta map[string]int64) error
ModifyTorrent(infoHash string, option *TorrentOption, meta map[string]int64) error
DeleteTorrents(infoHashes []string, deleteFiles bool) error
PauseTorrents(infoHashes []string) error
ResumeTorrents(infoHashes []string) error
Expand Down Expand Up @@ -147,7 +147,7 @@ var (
Registry = []*RegInfo{}
substituteTagRegex = regexp.MustCompile(`^(category|meta\..+):.+$`)
// all clientInstances created during this ptool program session
clients = map[string](Client){}
clients = map[string]Client{}
)

func Register(regInfo *RegInfo) {
Expand Down Expand Up @@ -187,7 +187,7 @@ func CreateClient(name string) (Client, error) {
return clientInstance, err
}

func GenerateNameWithMeta(name string, meta map[string](int64)) string {
func GenerateNameWithMeta(name string, meta map[string]int64) string {
str := name
first := true
for key, value := range meta {
Expand All @@ -205,7 +205,7 @@ func GenerateNameWithMeta(name string, meta map[string](int64)) string {
return str
}

func ParseMetaFromName(fullname string) (name string, meta map[string](int64)) {
func ParseMetaFromName(fullname string) (name string, meta map[string]int64) {
metaStrReg := regexp.MustCompile(`^(?P<name>.*?)__meta.(?P<meta>[._a-zA-Z0-9]+)$`)
metaStrMatch := metaStrReg.FindStringSubmatch(fullname)
if metaStrMatch != nil {
Expand Down Expand Up @@ -279,8 +279,8 @@ func (torrent *Torrent) GetMetaFromTag(meta string) string {
return ""
}

func (torrent *Torrent) GetMetadataFromTags() map[string](int64) {
metas := map[string](int64){}
func (torrent *Torrent) GetMetadataFromTags() map[string]int64 {
metas := map[string]int64{}
metaTagRegex := regexp.MustCompile(`^meta\.(?P<name>.+):(?P<value>.+)$`)
for _, tag := range torrent.Tags {
metaStrMatch := metaTagRegex.FindStringSubmatch(tag)
Expand Down
300 changes: 150 additions & 150 deletions client/qbittorrent/api.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions client/qbittorrent/qbittorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (qbclient *Client) GetClientConfig() *config.ClientConfigStruct {
return qbclient.ClientConfig
}

func (qbclient *Client) AddTorrent(torrentContent []byte, option *client.TorrentOption, meta map[string](int64)) error {
func (qbclient *Client) AddTorrent(torrentContent []byte, option *client.TorrentOption, meta map[string]int64) error {
err := qbclient.login()
if err != nil {
return fmt.Errorf("login error: %v", err)
Expand Down Expand Up @@ -421,7 +421,7 @@ func (qbclient *Client) GetCategories() ([]client.TorrentCategory, error) {
if err != nil {
return nil, fmt.Errorf("login error: %v", err)
}
var categories map[string](client.TorrentCategory)
var categories map[string]client.TorrentCategory
err = qbclient.apiRequest("api/v2/torrents/categories", &categories)
if err != nil {
return nil, err
Expand Down Expand Up @@ -480,7 +480,7 @@ func (qbclient *Client) DeleteTorrents(infoHashes []string, deleteFiles bool) er
}

func (qbclient *Client) ModifyTorrent(infoHash string,
option *client.TorrentOption, meta map[string](int64)) error {
option *client.TorrentOption, meta map[string]int64) error {
if option == nil {
option = &client.TorrentOption{}
}
Expand Down Expand Up @@ -691,7 +691,7 @@ func (qbclient *Client) GetStatus() (*client.Status, error) {
return &status, nil
}

func (qbclient *Client) setPreferences(preferences map[string](any)) error {
func (qbclient *Client) setPreferences(preferences map[string]any) error {
err := qbclient.login()
if err != nil {
return fmt.Errorf("login error: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions client/transmission/transmission.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Client struct {
client *transmissionrpc.Client
datatime int64
datatimeMeta int64
torrents map[string](*transmissionrpc.Torrent)
torrents map[string]*transmissionrpc.Torrent
sessionStats *transmissionrpc.SessionStats
sessionArgs *transmissionrpc.SessionArguments
freeSpace int64
Expand Down Expand Up @@ -98,7 +98,7 @@ func (trclient *Client) sync() error {
if err != nil {
return err
}
torrentsMap := map[string](*transmissionrpc.Torrent){}
torrentsMap := map[string]*transmissionrpc.Torrent{}
unfinishedSize := int64(0)
unfinishedDownloadingSize := int64(0)
for i := range torrents {
Expand Down Expand Up @@ -173,7 +173,7 @@ func (trclient *Client) GetTorrents(stateFilter string, category string, showAll
return torrents, nil
}

func (trclient *Client) AddTorrent(torrentContent []byte, option *client.TorrentOption, meta map[string](int64)) error {
func (trclient *Client) AddTorrent(torrentContent []byte, option *client.TorrentOption, meta map[string]int64) error {
transmissionbt := trclient.client
torrentContentB64 := base64.StdEncoding.EncodeToString(torrentContent)
var downloadDir *string
Expand Down Expand Up @@ -238,7 +238,7 @@ func (trclient *Client) AddTorrent(torrentContent []byte, option *client.Torrent
return nil
}

func (trclient *Client) ModifyTorrent(infoHash string, option *client.TorrentOption, meta map[string](int64)) error {
func (trclient *Client) ModifyTorrent(infoHash string, option *client.TorrentOption, meta map[string]int64) error {
transmissionbt := trclient.client
trtorrent, err := trclient.getTorrent(infoHash, false)
if err != nil {
Expand Down Expand Up @@ -438,7 +438,7 @@ func (trclient *Client) GetTags() ([]string, error) {
return nil, err
}
tags := []string{}
tagsFlag := map[string](bool){}
tagsFlag := map[string]bool{}
for _, trtorrent := range trclient.torrents {
for _, label := range trtorrent.Labels {
if label != "" && !tagsFlag[label] && !client.IsSubstituteTag(label) {
Expand Down Expand Up @@ -471,7 +471,7 @@ func (trclient *Client) GetCategories() ([]client.TorrentCategory, error) {
return nil, err
}
cats := []client.TorrentCategory{}
catsFlag := map[string](bool){}
catsFlag := map[string]bool{}
for _, trtorrent := range trclient.torrents {
torrent := tr2Torrent(trtorrent)
cat := torrent.GetCategoryFromTag()
Expand Down
6 changes: 3 additions & 3 deletions cmd/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var command = &cobra.Command{
Use: "add {client} {torrentId | torrentUrl}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "add"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "add"},
Short: "Add site torrents to client.",
Long: `Add site torrents to client.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Expand Down Expand Up @@ -52,8 +52,8 @@ func add(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("failed to create client: %v", err)
}
domainSiteMap := map[string](string){}
siteInstanceMap := map[string](site.Site){}
domainSiteMap := map[string]string{}
siteInstanceMap := map[string]site.Site{}
errorCnt := int64(0)
option := &client.TorrentOption{
Pause: addPaused,
Expand Down
2 changes: 1 addition & 1 deletion cmd/addlocal/addlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var command = &cobra.Command{
Use: "addlocal {client} {file.torrent}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "addlocal"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "addlocal"},
Short: "Add local torrents to client.",
Long: `Add local torrents to client.
It's possible to use "*" wildcard in filename to match multiple torrents. eg. "*.torrent".
Expand Down
2 changes: 1 addition & 1 deletion cmd/addtags/addtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var command = &cobra.Command{
Use: "addtags {client} {tags} [--category category] [--tag tag] [--filter filter] [infoHash]...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "addtags"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "addtags"},
Short: "Add tags to torrents in client.",
Long: `Add tags to torrents in client.
{tags} : comma-seperated tags list.
Expand Down
2 changes: 1 addition & 1 deletion cmd/addtrackers/addtrackers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var command = &cobra.Command{
Use: "addtrackers {client} [--category category] [--tag tag] [--filter filter] [infoHash]...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "addtrackers"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "addtrackers"},
Short: "Add new trackers to torrents of client.",
Long: `Add new trackers to torrents of client.
[infoHash]...: infoHash list of torrents. It's possible to use state filter to target multiple torrents:
Expand Down
2 changes: 1 addition & 1 deletion cmd/batchdl/batchdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var command = &cobra.Command{
Use: "batchdl {site} [--action add|download|...] [--base-url torrents_page_url]",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "batchdl"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "batchdl"},
Aliases: []string{"ebookgod"},
Short: "Batch download the smallest (or by any other order) torrents from a site.",
Long: `Batch download the smallest (or by any other order) torrents from a site.`,
Expand Down
18 changes: 9 additions & 9 deletions cmd/brush/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
SLOW_TORRENTS_CHECK_TIMESPAN = int64(15 * 60)
STALL_TORRENT_DELETEION_TIMESPAN = int64(30 * 60) // stalled torrent will be deleted after this time passed
BANDWIDTH_FULL_PERCENT = float64(0.8)
DELETE_TORRENT_IMMEDIATELY_STORE = float64(99999)
DELETE_TORRENT_IMMEDIATELY_SCORE = float64(99999)
RESUME_TORRENTS_FREE_DISK_SPACE_TIER = int64(5 * 1024 * 1024 * 1024) // 5GB
DELETE_TORRENTS_FREE_DISK_SPACE_TIER = int64(10 * 1024 * 1024 * 1024) // 10GB
)
Expand All @@ -48,14 +48,14 @@ type BrushOptionStruct struct {
type AlgorithmAddTorrent struct {
DownloadUrl string
Name string
Meta map[string](int64)
Meta map[string]int64
Msg string
}

type AlgorithmModifyTorrent struct {
InfoHash string
Name string
Meta map[string](int64)
Meta map[string]int64
Msg string
}

Expand All @@ -82,7 +82,7 @@ type candidateTorrentStruct struct {
Size int64
PredictionUploadSpeed int64
Score float64
Meta map[string](int64)
Meta map[string]int64
}

type candidateClientTorrentStruct struct {
Expand Down Expand Up @@ -145,8 +145,8 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
var stallTorrents []AlgorithmModifyTorrent
var resumeTorrents []AlgorithmOperationTorrent
var deleteCandidateTorrents []candidateClientTorrentStruct
clientTorrentsMap := map[string](*clientTorrentInfoStruct){}
siteTorrentsMap := map[string](*site.Torrent){}
clientTorrentsMap := map[string]*clientTorrentInfoStruct{}
siteTorrentsMap := map[string]*site.Torrent{}

targetUploadSpeed := clientStatus.UploadSpeedLimit
if targetUploadSpeed <= 0 {
Expand Down Expand Up @@ -214,7 +214,7 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
len(candidateTorrents) > 0 {
deleteCandidateTorrents = append(deleteCandidateTorrents, candidateClientTorrentStruct{
InfoHash: torrent.InfoHash,
Score: DELETE_TORRENT_IMMEDIATELY_STORE,
Score: DELETE_TORRENT_IMMEDIATELY_SCORE,
FutureValue: 0,
Msg: "torrent in error state",
})
Expand All @@ -223,7 +223,7 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
if option.Now-torrent.Atime > NO_PROCESS_TORRENT_DELETEION_TIMESPAN {
deleteCandidateTorrents = append(deleteCandidateTorrents, candidateClientTorrentStruct{
InfoHash: torrent.InfoHash,
Score: DELETE_TORRENT_IMMEDIATELY_STORE,
Score: DELETE_TORRENT_IMMEDIATELY_SCORE,
FutureValue: 0,
Msg: "torrent has no download proccess",
})
Expand Down Expand Up @@ -310,7 +310,7 @@ func Decide(clientStatus *client.Status, clientTorrents []client.Torrent, siteTo
for _, deleteTorrent := range deleteCandidateTorrents {
torrent := clientTorrentsMap[deleteTorrent.InfoHash].Torrent
shouldDelete := false
if deleteTorrent.Score >= DELETE_TORRENT_IMMEDIATELY_STORE ||
if deleteTorrent.Score >= DELETE_TORRENT_IMMEDIATELY_SCORE ||
(freespace >= 0 && freespace <= option.MinDiskSpace && freespace+freespaceChange <= freespaceTarget) {
shouldDelete = true
} else if torrent.Ctime <= 0 &&
Expand Down
4 changes: 2 additions & 2 deletions cmd/brush/brush.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

var command = &cobra.Command{
Use: "brush {client} {site | group}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "brush"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "brush"},
Short: "Brush sites using client.",
Long: `Brush sites using client.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Expand Down Expand Up @@ -61,7 +61,7 @@ func brush(cmd *cobra.Command, args []string) error {
cntSkipSite := int64(0)
cntAddTorrents := int64(0)
cntDeleteTorrents := int64(0)
doneSiteFlag := map[string](bool){}
doneSiteFlag := map[string]bool{}
tmpdir, _ := os.MkdirTemp(os.TempDir(), "ptool")
var statDb *stats.StatDb
if config.Get().BrushEnableStats {
Expand Down
2 changes: 1 addition & 1 deletion cmd/clientctl/clientctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Option struct {

var command = &cobra.Command{
Use: "clientctl {client} [<variable>[=value] ...]",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "clientctl"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "clientctl"},
Short: "Get or set client config.",
Long: `Get or set client config.`,
RunE: clientctl,
Expand Down
2 changes: 1 addition & 1 deletion cmd/createcategory/createcategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var command = &cobra.Command{
Use: "createcategory {client} {category} [--save-path path]",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "createcategory"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "createcategory"},
Short: "Create or edit category in client.",
Long: `Create category in client. If category already exists, edit it.
Use --save-path to set (or modify) the save path of the category.`,
Expand Down
2 changes: 1 addition & 1 deletion cmd/createtags/createtags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var command = &cobra.Command{
Use: "createtags {client} {tags}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "createtags"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "createtags"},
Short: "Create tags in client.",
Long: `Create tags in client.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var command = &cobra.Command{
Use: "delete {client} {infoHash}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "delete"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "delete"},
Aliases: []string{"rm"},
Short: "Delete torrents from client.",
Long: `Delete torrents from client.
Expand Down
2 changes: 1 addition & 1 deletion cmd/deletetags/deletetags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var command = &cobra.Command{
Use: "deletetags {client} {tags}...",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "deletetags"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "deletetags"},
Short: "Delete tags from client.",
Long: `Delete tags from client.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs),
Expand Down
6 changes: 3 additions & 3 deletions cmd/dltorrent/dltorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var command = &cobra.Command{
Use: "dltorrent {torrentId | torrentUrl}... [--download-dir dir]",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "dltorrent"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "dltorrent"},
Short: "Download site torrents to local.",
Long: `Download site torrents to local.`,
Args: cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs),
Expand All @@ -37,8 +37,8 @@ func init() {
func dltorrent(cmd *cobra.Command, args []string) error {
errorCnt := int64(0)
torrentIds := args
siteInstanceMap := map[string](site.Site){}
domainSiteMap := map[string](string){}
siteInstanceMap := map[string]site.Site{}
domainSiteMap := map[string]string{}

for _, torrentId := range torrentIds {
siteName := defaultSite
Expand Down
2 changes: 1 addition & 1 deletion cmd/edittracker/edittracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var command = &cobra.Command{
Use: "edittracker <client> [--category category] [--tag tag] [--filter filter] [infoHash]... --old-tracker {url} --new-tracker {url} [--replace-host]",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "edittracker"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "edittracker"},
Short: "Edit tracker of torrents in client.",
Long: `Edit tracker of torrents in client, replace the old tracker url with the new one.
[infoHash]...: infoHash list of torrents. It's possible to use state filter to target multiple torrents:
Expand Down
2 changes: 1 addition & 1 deletion cmd/getcategories/getcategories.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var command = &cobra.Command{
Use: "getcategories {client}",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "getcategories"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "getcategories"},
Short: "Get all categories of client.",
Long: `Get all categories of client.`,
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Expand Down
2 changes: 1 addition & 1 deletion cmd/gettags/gettags.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var command = &cobra.Command{
Use: "gettags {client}",
Annotations: map[string](string){"cobra-prompt-dynamic-suggestions": "gettags"},
Annotations: map[string]string{"cobra-prompt-dynamic-suggestions": "gettags"},
Short: "Get all tags of client.",
Long: `Get all tags of client.`,
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Expand Down

0 comments on commit fe2933d

Please sign in to comment.