diff --git a/app/services/playlists/playlists.go b/app/services/playlists/playlists.go index 5c65a96..e8d2b80 100644 --- a/app/services/playlists/playlists.go +++ b/app/services/playlists/playlists.go @@ -11,6 +11,8 @@ import ( "fmt" "io" "os" + "path/filepath" + "strings" "time" ) @@ -314,10 +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, ) - io.Copy(newShit, ogFile) + if err != nil { + _ = ogFile.Close() + return nil, err + } + _, err = io.Copy(newShit, ogFile) + if err != nil { + _ = ogFile.Close() + return nil, err + } fileNames[i] = newShit.Name() _ = newShit.Close() _ = ogFile.Close() diff --git a/app/static/js/player.js b/app/static/js/player.js index 2ec13fb..bf11835 100644 --- a/app/static/js/player.js +++ b/app/static/js/player.js @@ -217,8 +217,10 @@ function playPauser(audioEl) { */ function stopper(audioEl) { return () => { - audioEl.pause(); - audioEl.currentTime = 0; + if (!audioEl.paused) { + audioEl.pause(); + audioEl.currentTime = 0; + } const songEl = document.getElementById( "song-" + playerState.playlist.songs[playerState.currentSongIdx].yt_id, ); @@ -613,11 +615,18 @@ async function playSong(song) { setLoading(true); show(); - await downloadSong(song.yt_id).then(() => { - stopMuzikk(); - audioPlayerEl.src = `/muzikkx/${song.yt_id}.mp3`; - audioPlayerEl.load(); - }); + const resp = await downloadSong(song.yt_id); + if (!resp.ok) { + alert("Something went wrong when downloading the song..."); + return; + } + stopMuzikk(); + if (audioPlayerEl.childNodes.length > 0) { + audioPlayerEl.removeChild(audioPlayerEl.childNodes.item(0)); + } + const src = document.createElement("source"); + src.src = `${location.protocol}//${location.host}/muzikkx/${song.yt_id}.mp3`; + audioPlayerEl.appendChild(src); // song's details setting, yada yada { @@ -659,6 +668,12 @@ async function playSong(song) { songImageExpandedEl.innerHTML = ""; } } + { + setTimeout(75); + audioPlayerEl.load(); + setTimeout(75); + audioPlayerEl.load(); + } setMediaSessionMetadata(song); playMuzikk(); await updateSongPlays(); diff --git a/app/static/js/utils.js b/app/static/js/utils.js index ce384e7..a987ab2 100644 --- a/app/static/js/utils.js +++ b/app/static/js/utils.js @@ -116,7 +116,7 @@ function menuer() { e.clientX < rect.left || e.clientX > rect.right || e.clientY + parentRect.height + 5 < rect.top || - e.clientY > rect.bottom + e.clientY > rect.bottom + parentRect.height + 5 ) { lastEl.style.display = "none"; lastEl = null; diff --git a/app/views/components/menus/popover_up.templ b/app/views/components/menus/popover_up.templ index fc06b92..7c98125 100644 --- a/app/views/components/menus/popover_up.templ +++ b/app/views/components/menus/popover_up.templ @@ -35,6 +35,7 @@ css top(topVal string) { script toggleTheThingUp(id string) { id = `popover-${id}`; + Utils.registerPopover(id); const popover = document.getElementById(id); if (popover.style.display !== "block") { popover.style.display = "block"; diff --git a/app/views/components/player/player.templ b/app/views/components/player/player.templ index fcef289..cf4c0d1 100644 --- a/app/views/components/player/player.templ +++ b/app/views/components/player/player.templ @@ -31,13 +31,12 @@ templ PlayerSticky() { - + ///