From f7772303b0085b08f99125c0daf99e3f188926e7 Mon Sep 17 00:00:00 2001 From: Alex McGrath Date: Thu, 18 Feb 2021 11:28:59 +0000 Subject: [PATCH] Fix podcasts with / in the name --- server/db/model.go | 3 ++- server/podcasts/podcasts.go | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/db/model.go b/server/db/model.go index fd12038..3f13dc0 100644 --- a/server/db/model.go +++ b/server/db/model.go @@ -304,7 +304,8 @@ type Podcast struct { } func (p *Podcast) Fullpath(podcastPath string) string { - return filepath.Join(podcastPath, filepath.Clean(p.Title)) + sanitizedTitle := strings.ReplaceAll(p.Title, "/", "_") + return filepath.Join(podcastPath, filepath.Clean(sanitizedTitle)) } func (p *Podcast) SID() *specid.ID { diff --git a/server/podcasts/podcasts.go b/server/podcasts/podcasts.go index 37608c2..b1f92a4 100644 --- a/server/podcasts/podcasts.go +++ b/server/podcasts/podcasts.go @@ -343,7 +343,8 @@ func (p *Podcasts) findUniqueEpisodeName( if _, err := os.Stat(podcastPath); os.IsNotExist(err) { return filename } - titlePath := fmt.Sprintf("%s%s", podcastEpisode.Title, filepath.Ext(filename)) + sanitizedTitle := strings.ReplaceAll(podcastEpisode.Title, "/", "_") + titlePath := fmt.Sprintf("%s%s", sanitizedTitle, filepath.Ext(filename)) podcastPath = path.Join(podcast.Fullpath(p.PodcastBasePath), titlePath) if _, err := os.Stat(podcastPath); os.IsNotExist(err) { return titlePath @@ -353,7 +354,8 @@ func (p *Podcasts) findUniqueEpisodeName( } func findEpisode(base, filename string, count int) string { - testFile := fmt.Sprintf("%s (%d)%s", filename, count, filepath.Ext(filename)) + noExt := strings.TrimSuffix(filename, filepath.Ext(filename)) + testFile := fmt.Sprintf("%s (%d)%s", noExt, count, filepath.Ext(filename)) podcastPath := path.Join(base, testFile) if _, err := os.Stat(podcastPath); os.IsNotExist(err) { return testFile