diff --git a/internal/utils/regex.go b/internal/utils/regex.go index 9b7d03a..e9cce5e 100644 --- a/internal/utils/regex.go +++ b/internal/utils/regex.go @@ -37,6 +37,7 @@ func RemoveInvalidChars(value string) string { } func RemoveExtension(value string) string { + value = RemoveInvalidChars(value) re := regexp.MustCompile(VIDEOMATCH + "|" + SAMPLEMATCH + "|" + MUSICMATCH) // Find the last index of the matched extension diff --git a/pkg/debrid/realdebrid/realdebrid.go b/pkg/debrid/realdebrid/realdebrid.go index adea14b..c018ca6 100644 --- a/pkg/debrid/realdebrid/realdebrid.go +++ b/pkg/debrid/realdebrid/realdebrid.go @@ -173,7 +173,7 @@ func (r *RealDebrid) UpdateTorrent(t *torrent.Torrent) error { if err != nil { return err } - name := utils.RemoveInvalidChars(data.OriginalFilename) + name := utils.RemoveExtension(data.OriginalFilename) t.Name = name t.Bytes = data.Bytes t.Folder = name @@ -379,7 +379,7 @@ func (r *RealDebrid) getTorrents(offset int, limit int) (int, []*torrent.Torrent } torrents = append(torrents, &torrent.Torrent{ Id: t.Id, - Name: t.Filename, + Name: utils.RemoveInvalidChars(t.Filename), Bytes: t.Bytes, Progress: t.Progress, Status: t.Status, diff --git a/pkg/webdav/cache.go b/pkg/webdav/cache.go index 43a300b..035637b 100644 --- a/pkg/webdav/cache.go +++ b/pkg/webdav/cache.go @@ -8,6 +8,7 @@ import ( "github.com/goccy/go-json" "github.com/rs/zerolog" "github.com/sirrobot01/debrid-blackhole/internal/logger" + "github.com/sirrobot01/debrid-blackhole/internal/utils" "github.com/sirrobot01/debrid-blackhole/pkg/debrid/debrid" "os" "path/filepath" @@ -108,7 +109,10 @@ func (c *Cache) refreshListings() { } func (c *Cache) GetListing() []os.FileInfo { - return c.listings.Load().([]os.FileInfo) + if v, ok := c.listings.Load().([]os.FileInfo); ok { + return v + } + return nil } func (c *Cache) setTorrents(torrents map[string]*CachedTorrent) { @@ -249,6 +253,7 @@ func (c *Cache) load() (map[string]*CachedTorrent, error) { if len(ct.Files) != 0 { // We can assume the torrent is complete ct.IsComplete = true + ct.Torrent.Name = utils.RemoveExtension(ct.Torrent.Filename) // Update the name torrents[ct.Id] = &ct } }