Clean up grouping logic

This commit is contained in:
Ben Sarmiento
2023-10-18 21:47:57 +02:00
parent 0fa7b407b0
commit ce0b2445b2
4 changed files with 14 additions and 21 deletions

View File

@@ -2,7 +2,6 @@ package torrent
import (
"encoding/gob"
"fmt"
"log"
"os"
"strings"
@@ -58,9 +57,9 @@ func (t *TorrentManager) getAll() []Torrent {
}
torrentsV2 = append(torrentsV2, torrentV2)
}
log.Printf("Fetched %d torrents", len(torrentsV2))
version := t.config.GetVersion()
fmt.Println("config version", version)
if version == "v1" {
configV1 := t.config.(*config.ZurgConfigV1)
groupMap := configV1.GetGroupMap()
@@ -70,23 +69,23 @@ func (t *TorrentManager) getAll() []Torrent {
for _, directory := range directories {
if configV1.MeetsConditions(directory, torrentsV2[i].ID, torrentsV2[i].Name) {
torrentsV2[i].Directories = append(torrentsV2[i].Directories, directory)
fmt.Println(torrentsV2[i].Name, torrentsV2[i].Directories)
break
}
}
}
}
}
log.Printf("Fetched %d torrents", len(torrentsV2))
log.Println("Finished mapping to groups")
return torrentsV2
}
func (t *TorrentManager) GetByDirectory(directory string) []Torrent {
var torrents []Torrent
for _, torrent := range t.torrents {
for _, dir := range torrent.Directories {
for i := range t.torrents {
for _, dir := range t.torrents[i].Directories {
if dir == directory {
torrents = append(torrents, torrent)
torrents = append(torrents, t.torrents[i])
}
}
}
@@ -174,17 +173,17 @@ func (t *TorrentManager) getInfo(torrentID string) *Torrent {
}
func (t *TorrentManager) GetInfo(torrentID string) *Torrent {
for _, torrent := range t.torrents {
if torrent.ID == torrentID {
return &torrent
for i := range t.torrents {
if t.torrents[i].ID == torrentID {
return &t.torrents[i]
}
}
return t.getInfo(torrentID)
}
func (t *TorrentManager) getByID(torrentID string) *Torrent {
for i, torrent := range t.torrents {
if torrent.ID == torrentID {
for i := range t.torrents {
if t.torrents[i].ID == torrentID {
return &t.torrents[i]
}
}