Access key computation without clearing data
This commit is contained in:
@@ -51,7 +51,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
|
||||
// create internal directories
|
||||
t.DirectoryMap = cmap.New[cmap.ConcurrentMap[string, *Torrent]]()
|
||||
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is AccessKey
|
||||
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is GetAccessKey()
|
||||
t.DirectoryMap.Set(INT_INFO_CACHE, cmap.New[*Torrent]()) // key is Torrent ID
|
||||
// create directory maps
|
||||
for _, directory := range cfg.GetDirectories() {
|
||||
@@ -165,7 +165,7 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||
cb(config.UNPLAYABLE_TORRENTS)
|
||||
break
|
||||
}
|
||||
if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
|
||||
if t.Config.MeetsConditions(directory, t.GetKey(tor), tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
|
||||
cb(directory)
|
||||
break
|
||||
}
|
||||
@@ -174,21 +174,24 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) computeAccessKey(name, originalName string) string {
|
||||
func (t *TorrentManager) GetKey(torrent *Torrent) string {
|
||||
if t.Config.ShouldAllowRenames() && torrent.Rename != "" {
|
||||
return torrent.Rename
|
||||
}
|
||||
if t.Config.EnableRetainRDTorrentName() {
|
||||
return name
|
||||
return torrent.Name
|
||||
}
|
||||
// drop the extension from the name
|
||||
if t.Config.EnableRetainFolderNameExtension() && strings.Contains(name, originalName) {
|
||||
return name
|
||||
if t.Config.EnableRetainFolderNameExtension() && strings.Contains(torrent.Name, torrent.OriginalName) {
|
||||
return torrent.Name
|
||||
} else {
|
||||
ret := strings.TrimSuffix(originalName, ".mp4")
|
||||
ret := strings.TrimSuffix(torrent.OriginalName, ".mp4")
|
||||
ret = strings.TrimSuffix(ret, ".mkv")
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TorrentManager) writeTorrentToFile(instanceID string, torrent *Torrent) {
|
||||
func (t *TorrentManager) writeTorrentToFile(instanceID string, torrent *Torrent, overwriteNames bool) {
|
||||
filePath := "data/" + instanceID + ".json"
|
||||
file, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
@@ -197,6 +200,13 @@ func (t *TorrentManager) writeTorrentToFile(instanceID string, torrent *Torrent)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
if !overwriteNames {
|
||||
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
|
||||
if cachedTorrent, exists := infoCache.Get(instanceID); exists {
|
||||
torrent.Name = cachedTorrent.Name
|
||||
torrent.OriginalName = cachedTorrent.OriginalName
|
||||
}
|
||||
}
|
||||
torrent.Version = t.requiredVersion
|
||||
|
||||
jsonData, err := json.Marshal(torrent)
|
||||
|
||||
Reference in New Issue
Block a user