handle file resets
This commit is contained in:
@@ -147,7 +147,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
if torrentFromCache, exists := infoCache.Get(rdTorrent.ID); exists &&
|
if torrentFromCache, exists := infoCache.Get(rdTorrent.ID); exists &&
|
||||||
!torrentFromCache.AnyInProgress() &&
|
!torrentFromCache.AnyInProgress() &&
|
||||||
torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) {
|
torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) {
|
||||||
|
t.ResetSelectedFiles(torrentFromCache)
|
||||||
return torrentFromCache
|
return torrentFromCache
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,9 +210,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
}
|
}
|
||||||
torrent.SelectedFiles = cmap.New[*File]()
|
torrent.SelectedFiles = cmap.New[*File]()
|
||||||
for _, file := range selectedFiles {
|
for _, file := range selectedFiles {
|
||||||
// remove forward slash in the beginning
|
filename := t.GetPath(file)
|
||||||
filename := strings.TrimPrefix(file.Path, "/")
|
|
||||||
filename = strings.ReplaceAll(filename, "/", " - ")
|
|
||||||
// todo better handling of duplicate filenames
|
// todo better handling of duplicate filenames
|
||||||
if torrent.SelectedFiles.Has(filename) {
|
if torrent.SelectedFiles.Has(filename) {
|
||||||
oldName := filename
|
oldName := filename
|
||||||
@@ -238,6 +236,24 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
return &torrent
|
return &torrent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TorrentManager) ResetSelectedFiles(torrent *Torrent) {
|
||||||
|
// reset selected files
|
||||||
|
newSelectedFiles := cmap.New[*File]()
|
||||||
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
|
filename := t.GetPath(file)
|
||||||
|
if newSelectedFiles.Has(filename) {
|
||||||
|
oldName := filename
|
||||||
|
ext := filepath.Ext(oldName)
|
||||||
|
noExtension := strings.TrimSuffix(oldName, ext)
|
||||||
|
newName := fmt.Sprintf("%s (%d)%s", noExtension, file.ID, ext)
|
||||||
|
newSelectedFiles.Set(newName, file)
|
||||||
|
} else {
|
||||||
|
newSelectedFiles.Set(filename, file)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
torrent.SelectedFiles = newSelectedFiles
|
||||||
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||||
var newer, older *Torrent
|
var newer, older *Torrent
|
||||||
if existing.Added < toMerge.Added {
|
if existing.Added < toMerge.Added {
|
||||||
|
|||||||
Reference in New Issue
Block a user