Add retain_rd_torrent_name setting

This commit is contained in:
Ben Sarmiento
2023-11-23 01:40:08 +01:00
parent 77b16791ef
commit addac3cc9f
2 changed files with 24 additions and 0 deletions

View File

@@ -404,6 +404,9 @@ func hashStringToFh(s string) (fh uint64) {
}
func (t *TorrentManager) getName(name, originalName string) string {
if t.cfg.EnableRetainRDTorrentName() {
return name
}
// drop the extension from the name
if t.cfg.EnableRetainFolderNameExtension() && strings.Contains(name, originalName) {
return name
@@ -655,6 +658,19 @@ func (t *TorrentManager) Repair(accessKey string) {
missingFiles = append(missingFiles, *file)
}
})
// if we download a single file, it will be named differently
// so we need to download 1 extra file to preserve the name
// this is only relevant if we enable retain_rd_torrent_name
if t.cfg.EnableRetainRDTorrentName() && len(missingFiles) == 1 && streamableCount > 1 {
// add the first file link encountered with a prefix of http
for _, file := range torrent.SelectedFiles.Items() {
if strings.HasPrefix(file.Link, "http") {
missingFiles = append(missingFiles, *file)
break
}
}
}
if len(missingFiles) > 0 {
t.log.Infof("Redownloading in multiple batches the %d missing files for torrent %s", len(missingFiles), torrent.AccessKey)
// if not, last resort: add only the missing files but do it in 2 batches
@@ -667,6 +683,8 @@ func (t *TorrentManager) Repair(accessKey string) {
if missingFiles2 != "" {
t.reinsertTorrent(torrent, missingFiles2)
}
} else {
t.log.Warnf("Torrent %s has no missing files to repair", torrent.AccessKey)
}
}