Skip to content

Commit

Permalink
Merge pull request #88 from mbaraa/dev
Browse files Browse the repository at this point in the history
release v0.1.51
  • Loading branch information
mbaraa authored Jul 2, 2024
2 parents 7e1d1b4 + bbb86d6 commit 1d9b329
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
18 changes: 16 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,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()
Expand Down
29 changes: 22 additions & 7 deletions app/static/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -659,6 +668,12 @@ async function playSong(song) {
songImageExpandedEl.innerHTML = "";
}
}
{
setTimeout(75);
audioPlayerEl.load();
setTimeout(75);
audioPlayerEl.load();
}
setMediaSessionMetadata(song);
playMuzikk();
await updateSongPlays();
Expand Down
2 changes: 1 addition & 1 deletion app/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/views/components/menus/popover_up.templ
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 6 additions & 7 deletions app/views/components/player/player.templ
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ templ PlayerSticky() {
</div>
</div>
</div>
<div class="hidden">
<audio
id="audio-player"
controls
preload="none"
></audio>
</div>
<audio
class="hidden"
id="audio-player"
controls
preload="none"
></audio>
///
<style>
.collapsed {
Expand Down

0 comments on commit 1d9b329

Please sign in to comment.