akhilrex / podgrab

A self-hosted podcast manager/downloader/archiver tool to download podcast episodes as soon as they become live with an integrated player.
GNU General Public License v3.0
1.55k stars 88 forks source link

Add option to replace invalid filename characters #239

Open RevenantOne opened 1 year ago

RevenantOne commented 1 year ago

Please complete the following information

Describe the bug PodGrab uses invalid characters in filenames.

To Reproduce Steps to reproduce the behavior:

  1. Add a podcast that has an episode name containing invalid characters.

Expected behavior An option to sanitise filenames to ensure no invalid characters can be used, regardless of operating system.

Screenshots N/A

Additional context I'm running PodGrab on a Ubuntu server and trying to sync to a Windows machine but it fails as episode names contain asterisks (*). Renaming files to remove invalid characters is redundant as PodGrab will rename them back to their original name.

benbou8231 commented 1 year ago

I have the same issue.

To reproduce the issue, the podcast "Dumb-Dumbs - Dragons- A Dungeons - Dragons Podcast" can be used, it have 13 episodes with asterisks in their name (the first one is: 2017-10-17-2-08-F***-Harness.mp3)

benbou8231 commented 1 year ago

I'm not a go programmer, but a solution could be to add some regex replace inside cleanFileName() (line #401 of podgrab/service/fileService.go)

Something like:

newString := sanitize.Name(original)

re, err := regexp.Compile(`[<>:"/\\|?*]`)
if err != nil {
    log.Fatal(err)
}
newString := re.ReplaceAllString(newString, "_")

I tested it on https://go.dev/play/ https://go.dev/play/p/QMbwRn8xJ_g

package main

import (
    "fmt"
    "log"
    "regexp"
)

func main() {
    str1 := "The / is illegal in Linux, and the following are illegal in Windows: * . \" / \\ [ ] : ; | ,"

    re, err := regexp.Compile(`[<>:"/\\|?*]`)
    if err != nil {
        log.Fatal(err)
    }
    str1 = re.ReplaceAllString(str1, "_")
    fmt.Println(str1)
}

of course, adding it in an if statement, that match a setting tick box, would be better.