Skip to content

Commit

Permalink
Feature: Move only included tags (#34)
Browse files Browse the repository at this point in the history
* feat: move specific tags

* docs: update move flags tags
  • Loading branch information
ludviglundgren authored Feb 26, 2022
1 parent 3c4c6b4 commit 635d2ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ By using ATM (Automatic Torrent Mode) and the default behavior of categories map
Optional flags:
* `--dry-run` - Run without doing anything
* `--min-seed-time` - Only move torrents with a minimum active seedtime of X minutes
* `--include-tags` - Only move torrents with any of the tags in comma separate list (tag1,tag2)

Usable with cron as well. Run every 15 min.

Expand Down
25 changes: 24 additions & 1 deletion cmd/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func RunMove() *cobra.Command {
dry bool
fromCategories []string
targetCategory string
includeTags []string
minSeedTime int
)

Expand All @@ -30,6 +31,7 @@ func RunMove() *cobra.Command {
command.Flags().BoolVar(&dry, "dry-run", false, "Run without doing anything")
command.Flags().StringSliceVar(&fromCategories, "from", []string{}, "Move from categories")
command.Flags().StringVar(&targetCategory, "to", "", "Move to the specified category")
command.Flags().StringSliceVar(&includeTags, "include-tags", []string{}, "Move from tags")
command.Flags().IntVar(&minSeedTime, "min-seed-time", 0, "Minimum seed time in MINUTES before moving.")
command.MarkFlagRequired("from")
command.MarkFlagRequired("to")
Expand Down Expand Up @@ -65,6 +67,13 @@ func RunMove() *cobra.Command {
continue
}

if len(includeTags) > 0 {
validTag := validateTag(includeTags, torrent.Tags)
if !validTag {
continue
}
}

// check TimeActive (seconds), CompletionOn (epoch) SeenComplete
if minSeedTime > 0 {
completedTime := time.Unix(int64(torrent.CompletionOn), 0)
Expand All @@ -82,7 +91,7 @@ func RunMove() *cobra.Command {
}

if len(hashes) == 0 {
fmt.Printf("Could not find any matching torrents to move from (%v) to (%v) with min-seed-time %d minutes \n", strings.Join(fromCategories, ","), targetCategory, minSeedTime)
fmt.Printf("Could not find any matching torrents to move from (%v) to (%v) with tags (%v) and min-seed-time %d minutes \n", strings.Join(fromCategories, ","), targetCategory, strings.Join(includeTags, ","), minSeedTime)
os.Exit(0)
}

Expand All @@ -104,3 +113,17 @@ func RunMove() *cobra.Command {

return command
}

func validateTag(includeTags []string, torrentTags string) bool {
tagList := strings.Split(torrentTags, ", ")

for _, includeTag := range includeTags {
for _, tag := range tagList {
if tag == includeTag {
return true
}
}
}

return false
}

0 comments on commit 635d2ca

Please sign in to comment.