Skip to content

Commit

Permalink
feat, fix: use three digits for episode number in filenames; strip sl…
Browse files Browse the repository at this point in the history
…ashes from filenames
  • Loading branch information
julijane committed Dec 8, 2024
1 parent d97430a commit 1d54916
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions audiobooks.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"fmt"
"log"
"os"
"path"
"strconv"
"strings"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func (l *Leecher) fetchAudiobook(audiobookID string) {

dirPath := path.Join(
"audiobooks",
strings.ReplaceAll(audiobook.Title, " ", "_"),
sanitizeFileOrPathName(audiobook.Title),
)

if err = os.MkdirAll(dirPath, 0o0755); err != nil {
Expand All @@ -61,8 +61,8 @@ func (l *Leecher) fetchAudiobook(audiobookID string) {
log.Fatal(err)
}

episodeFilename := strconv.Itoa(episode.SerialNumber) + "_" +
strings.ReplaceAll(episode.Title, " ", "_") + ".mp4"
episodeFilename := fmt.Sprintf("%03d", episode.SerialNumber) + "_" +
sanitizeFileOrPathName(episode.Title) + ".mp4"

err = l.saveTo(
"https://iceportal.de"+file.Path,
Expand Down
5 changes: 2 additions & 3 deletions magazines.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ func (l *Leecher) fetchMagazine(magazineID string) {
log.Fatal("Not free, skipping. Paymethod: ", magazine.Paymethod)
}

titleEncoded := strings.ReplaceAll(magazine.Title, " ", "_")
dirPath := path.Join("magazines", titleEncoded)
dirPath := path.Join("magazines", sanitizeFileOrPathName(magazine.Title))

resp, err := http.Get("https://iceportal.de/" + magazine.Navigation.Href)
if err != nil {
Expand All @@ -59,7 +58,7 @@ func (l *Leecher) fetchMagazine(magazineID string) {
"https://iceportal.de/"+magazine.Navigation.Href,
path.Join(
dirPath,
strings.ReplaceAll(magazine.Title, " ", "_")+"_"+magazine.Date+".pdf",
sanitizeFileOrPathName(magazine.Title)+"_"+magazine.Date+".pdf",
),
)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ func (l *Leecher) saveTo(url string, filePath string) error {
log.Print("Saved to ", filePath)
return nil
}

func sanitizeFileOrPathName(input string) string {
input = strings.ReplaceAll(input, " ", "_")
return strings.ReplaceAll(input, "/", "_")
}

0 comments on commit 1d54916

Please sign in to comment.