Add retain_folder_name_extension option

This commit is contained in:
Ben Sarmiento
2023-11-07 17:20:54 +01:00
parent d5746fcf5a
commit c2bf627413
10 changed files with 41 additions and 74 deletions

View File

@@ -35,7 +35,7 @@ type TorrentManager struct {
// and store them in-memory; it is called only once at startup
func NewTorrentManager(config config.ConfigInterface, cache *expirable.LRU[string, string]) *TorrentManager {
t := &TorrentManager{
requiredVersion: "4.11.2023",
requiredVersion: fmt.Sprintf("4.11.2023 - retain:%v", config.EnableRetainFolderNameExtension()),
config: config,
cache: cache,
workerPool: make(chan bool, config.GetNumOfWorkers()),
@@ -256,7 +256,7 @@ func (t *TorrentManager) addMoreInfo(torrent *Torrent) {
// see if api data and file data still match
// then it means data is still usable
if len(torrentFromFile.Links) == len(torrent.Links) {
torrent.Name = getName(torrentFromFile)
torrent.Name = t.getName(torrentFromFile)
torrent.ForRepair = torrentFromFile.ForRepair
torrent.SelectedFiles = torrentFromFile.SelectedFiles[:]
return
@@ -323,7 +323,7 @@ func (t *TorrentManager) addMoreInfo(torrent *Torrent) {
}
// update file cache
torrent.OriginalName = info.OriginalName
torrent.Name = getName(torrent)
torrent.Name = t.getName(torrent)
if len(selectedFiles) > 0 {
// update the torrent with more data!
torrent.SelectedFiles = selectedFiles
@@ -332,16 +332,17 @@ func (t *TorrentManager) addMoreInfo(torrent *Torrent) {
}
}
func getName(torrent *Torrent) string {
ret := ""
if torrent.OriginalName != "" {
ret = torrent.OriginalName
func (t *TorrentManager) getName(torrent *Torrent) string {
// drop the extension from the name
t.log.Debugf("Original name: %s", torrent.OriginalName)
t.log.Debugf("Name: %s", torrent.Name)
if t.config.EnableRetainFolderNameExtension() && strings.Contains(torrent.Name, torrent.OriginalName) {
return torrent.Name
} else {
ret = torrent.Name
ret := strings.TrimSuffix(torrent.OriginalName, ".mp4")
ret = strings.TrimSuffix(ret, ".mkv")
return ret
}
ret = strings.TrimSuffix(ret, ".mkv")
ret = strings.TrimSuffix(ret, ".mp4")
return ret
}
// mapToDirectories maps torrents to directories