Skip to content

Commit

Permalink
fix(playlist): file name in downloaded playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed Jul 1, 2024
1 parent 980f9ee commit 22ab024
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/services/playlists/playlists.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"
)

Expand Down Expand Up @@ -314,13 +316,22 @@ func (p *Service) Download(playlistPubId string, ownerId uint) (io.Reader, error
return nil, err
}
newShit, err := os.OpenFile(
fmt.Sprintf("%s/%d-%s.mp3", config.Env().YouTube.MusicDir, i+1, song.Title),
filepath.Clean(
fmt.Sprintf("%s/%d-%s.mp3", config.Env().YouTube.MusicDir, i+1,
strings.ReplaceAll(song.Title, "/", "|"),
),
),
os.O_WRONLY|os.O_CREATE, 0644,
)
if err != nil {
_ = ogFile.Close()
return nil, err
}
_, err = io.Copy(newShit, ogFile)
if err != nil {
_ = ogFile.Close()
return nil, err
}
_, _ = io.Copy(newShit, ogFile)
fileNames[i] = newShit.Name()
_ = newShit.Close()
_ = ogFile.Close()
Expand Down

0 comments on commit 22ab024

Please sign in to comment.