Skip to content

Commit 22ab024

Browse files
committed
fix(playlist): file name in downloaded playlists
1 parent 980f9ee commit 22ab024

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/services/playlists/playlists.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"fmt"
1212
"io"
1313
"os"
14+
"path/filepath"
15+
"strings"
1416
"time"
1517
)
1618

@@ -314,13 +316,22 @@ func (p *Service) Download(playlistPubId string, ownerId uint) (io.Reader, error
314316
return nil, err
315317
}
316318
newShit, err := os.OpenFile(
317-
fmt.Sprintf("%s/%d-%s.mp3", config.Env().YouTube.MusicDir, i+1, song.Title),
319+
filepath.Clean(
320+
fmt.Sprintf("%s/%d-%s.mp3", config.Env().YouTube.MusicDir, i+1,
321+
strings.ReplaceAll(song.Title, "/", "|"),
322+
),
323+
),
318324
os.O_WRONLY|os.O_CREATE, 0644,
319325
)
320326
if err != nil {
327+
_ = ogFile.Close()
328+
return nil, err
329+
}
330+
_, err = io.Copy(newShit, ogFile)
331+
if err != nil {
332+
_ = ogFile.Close()
321333
return nil, err
322334
}
323-
_, _ = io.Copy(newShit, ogFile)
324335
fileNames[i] = newShit.Name()
325336
_ = newShit.Close()
326337
_ = ogFile.Close()

0 commit comments

Comments
 (0)