Add retain_rd_torrent_name setting
This commit is contained in:
@@ -16,6 +16,7 @@ type ConfigInterface interface {
|
||||
GetNetworkBufferSize() int
|
||||
GetMountPoint() string
|
||||
EnableRetainFolderNameExtension() bool
|
||||
EnableRetainRDTorrentName() bool
|
||||
GetRandomPreferredHost() string
|
||||
}
|
||||
|
||||
@@ -31,6 +32,7 @@ type ZurgConfig struct {
|
||||
NetworkBufferSize int `yaml:"network_buffer_size"`
|
||||
MountPoint string `yaml:"mount_point"`
|
||||
RetainFolderNameExtension bool `yaml:"retain_folder_name_extension"`
|
||||
RetainRDTorrentName bool `yaml:"retain_rd_torrent_name"`
|
||||
PreferredHosts []string `yaml:"preferred_hosts"`
|
||||
}
|
||||
|
||||
@@ -92,6 +94,10 @@ func (z *ZurgConfig) EnableRetainFolderNameExtension() bool {
|
||||
return z.RetainFolderNameExtension
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) EnableRetainRDTorrentName() bool {
|
||||
return z.RetainRDTorrentName
|
||||
}
|
||||
|
||||
func (z *ZurgConfig) GetRandomPreferredHost() string {
|
||||
if len(z.PreferredHosts) == 0 {
|
||||
return ""
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user