Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Move only included tags #34

Merged
merged 3 commits into from
Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}