restructure for rewrite

This commit is contained in:
2024-05-29 08:15:45 +02:00
parent eae13bd107
commit cc09bb87f8
56 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 24.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Artwork" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="361px" height="361px" viewBox="0 0 361 361" style="enable-background:new 0 0 361 361;" xml:space="preserve">
<style type="text/css">
.st0{fill-rule:evenodd;clip-rule:evenodd;fill:url(#SVGID_1_);}
.st1{fill-rule:evenodd;clip-rule:evenodd;fill:#FFFFFF;}
</style>
<g id="Layer_5">
</g>
<g>
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="180" y1="358.6047" x2="180" y2="7.7586">
<stop offset="0" style="stop-color:#FA233B"/>
<stop offset="1" style="stop-color:#FB5C74"/>
</linearGradient>
<path class="st0" d="M360,112.61c0-4.3,0-8.6-0.02-12.9c-0.02-3.62-0.06-7.24-0.16-10.86c-0.21-7.89-0.68-15.84-2.08-23.64
c-1.42-7.92-3.75-15.29-7.41-22.49c-3.6-7.07-8.3-13.53-13.91-19.14c-5.61-5.61-12.08-10.31-19.15-13.91
c-7.19-3.66-14.56-5.98-22.47-7.41c-7.8-1.4-15.76-1.87-23.65-2.08c-3.62-0.1-7.24-0.14-10.86-0.16C255.99,0,251.69,0,247.39,0
H112.61c-4.3,0-8.6,0-12.9,0.02c-3.62,0.02-7.24,0.06-10.86,0.16C80.96,0.4,73,0.86,65.2,2.27c-7.92,1.42-15.28,3.75-22.47,7.41
c-7.07,3.6-13.54,8.3-19.15,13.91c-5.61,5.61-10.31,12.07-13.91,19.14c-3.66,7.2-5.99,14.57-7.41,22.49
c-1.4,7.8-1.87,15.76-2.08,23.64c-0.1,3.62-0.14,7.24-0.16,10.86C0,104.01,0,108.31,0,112.61v134.77c0,4.3,0,8.6,0.02,12.9
c0.02,3.62,0.06,7.24,0.16,10.86c0.21,7.89,0.68,15.84,2.08,23.64c1.42,7.92,3.75,15.29,7.41,22.49c3.6,7.07,8.3,13.53,13.91,19.14
c5.61,5.61,12.08,10.31,19.15,13.91c7.19,3.66,14.56,5.98,22.47,7.41c7.8,1.4,15.76,1.87,23.65,2.08c3.62,0.1,7.24,0.14,10.86,0.16
c4.3,0.03,8.6,0.02,12.9,0.02h134.77c4.3,0,8.6,0,12.9-0.02c3.62-0.02,7.24-0.06,10.86-0.16c7.89-0.21,15.85-0.68,23.65-2.08
c7.92-1.42,15.28-3.75,22.47-7.41c7.07-3.6,13.54-8.3,19.15-13.91c5.61-5.61,10.31-12.07,13.91-19.14
c3.66-7.2,5.99-14.57,7.41-22.49c1.4-7.8,1.87-15.76,2.08-23.64c0.1-3.62,0.14-7.24,0.16-10.86c0.03-4.3,0.02-8.6,0.02-12.9V112.61
z"/>
</g>
<g id="Glyph_2_">
<g>
<path class="st1" d="M254.5,55c-0.87,0.08-8.6,1.45-9.53,1.64l-107,21.59l-0.04,0.01c-2.79,0.59-4.98,1.58-6.67,3
c-2.04,1.71-3.17,4.13-3.6,6.95c-0.09,0.6-0.24,1.82-0.24,3.62c0,0,0,109.32,0,133.92c0,3.13-0.25,6.17-2.37,8.76
c-2.12,2.59-4.74,3.37-7.81,3.99c-2.33,0.47-4.66,0.94-6.99,1.41c-8.84,1.78-14.59,2.99-19.8,5.01
c-4.98,1.93-8.71,4.39-11.68,7.51c-5.89,6.17-8.28,14.54-7.46,22.38c0.7,6.69,3.71,13.09,8.88,17.82
c3.49,3.2,7.85,5.63,12.99,6.66c5.33,1.07,11.01,0.7,19.31-0.98c4.42-0.89,8.56-2.28,12.5-4.61c3.9-2.3,7.24-5.37,9.85-9.11
c2.62-3.75,4.31-7.92,5.24-12.35c0.96-4.57,1.19-8.7,1.19-13.26l0-116.15c0-6.22,1.76-7.86,6.78-9.08c0,0,88.94-17.94,93.09-18.75
c5.79-1.11,8.52,0.54,8.52,6.61l0,79.29c0,3.14-0.03,6.32-2.17,8.92c-2.12,2.59-4.74,3.37-7.81,3.99
c-2.33,0.47-4.66,0.94-6.99,1.41c-8.84,1.78-14.59,2.99-19.8,5.01c-4.98,1.93-8.71,4.39-11.68,7.51
c-5.89,6.17-8.49,14.54-7.67,22.38c0.7,6.69,3.92,13.09,9.09,17.82c3.49,3.2,7.85,5.56,12.99,6.6c5.33,1.07,11.01,0.69,19.31-0.98
c4.42-0.89,8.56-2.22,12.5-4.55c3.9-2.3,7.24-5.37,9.85-9.11c2.62-3.75,4.31-7.92,5.24-12.35c0.96-4.57,1-8.7,1-13.26V64.46
C263.54,58.3,260.29,54.5,254.5,55z"/>
</g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MusicPlayerV2</title>
<script src="/apple-music/helpers/musickit.js"></script>
<link rel="stylesheet" href="/icon-font.css">
<link rel="stylesheet" href="/apple-music/helpers/playerStyle.css">
<link rel="stylesheet" href="/apple-music/helpers/style.css">
</head>
<body>
<div id="app">
<div v-if="isShowingWarning" class="warning">
<h3>WARNING!</h3>
<p>A client display is being tampered with!</p>
<p>A desktop notification with a warning has already been dispatched.</p>
<button @click="dismissNotification()">Ok</button>
<div class="flash"></div>
</div>
<div v-if="isPreparingToPlay" class="preparingToPlay">
<span class="material-symbols-outlined loading-spinner">autorenew</span>
<h1>Loading player...</h1>
</div>
<div v-if="!isLoggedIn" class="start-page">
<div class="image-wrapper">
<img src="/logo.png" alt="Music player icon" id="logo-main">
<img src="/apple-music/helpers/appleMusicIcon.svg" alt="Apple Music Icon" id="apple-music-logo">
</div>
<h1>Apple Music integration</h1>
<button @click="logInto()" class="button">Log in</button>
</div>
<div v-else class="home">
<div v-if="!hasSelectedPlaylist" class="song-list-wrapper">
<h1>Your playlists</h1>
<button class="button" @click="selectPlaylistFromDisk()">Load playlist file from disk</button>
<div v-if="!hasLoadedPlaylists" style="display: flex; justify-content: center; align-items: center; flex-direction: column;">
<span class="material-symbols-outlined loading-spinner">autorenew</span>
<h3>Loading playlists...</h3>
</div>
<div v-for="playlist in playlists" class="song-list" @click="selectPlaylist( playlist.id )" style="cursor: pointer;">
<h3>{{ playlist.title }}</h3>
</div>
</div>
<div v-else class="home">
<div class="top-bar">
<img src="/logo.png" alt="logo" class="logo">
<audio :src="'/getSongFile?filename=' + basePath + '/' + playingSong.filename" preload="metadata" id="audio-player"></audio>
<div class="player-wrapper">
<div class="player">
<div class="controls">
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" @click="control( 'previous' )">skip_previous</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" @click="control( 'replay10' )">replay_10</span>
<span class="material-symbols-outlined control-icon play-pause" v-if="!isPlaying && hasSelectedPlaylist" @click="control( 'play' )">play_arrow</span>
<span class="material-symbols-outlined control-icon play-pause" v-else-if="isPlaying && hasSelectedPlaylist" @click="control( 'pause' )">pause</span>
<span class="material-symbols-outlined control-icon play-pause" style="cursor: default;" v-else>play_disabled</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" @click="control( 'forward10' )">forward_10</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" @click="control( 'next' )" style="margin-right: 1vw;">skip_next</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" v-if="!isShuffleEnabled" @click="control( 'shuffleOn' )">shuffle</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" v-else @click="control( 'shuffleOff' )">shuffle_on</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" v-if="repeatMode === 'off'" @click="control( 'repeatOne' )">repeat</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" v-else-if="repeatMode === 'one'" @click="control( 'repeatAll' )">repeat_one_on</span>
<span class="material-symbols-outlined control-icon" :class="hasFinishedInit ? 'active': 'inactive'" v-else-if="repeatMode === 'all'" @click="control( 'repeatOff' )">repeat_on</span>
<span class="material-symbols-outlined control-icon" :class="hasSelectedPlaylist ? 'active': 'inactive'" @click="getAdditionalSongInfo()" title="Load additional song information" style="margin-left: 1vw;">upload</span>
<span class="material-symbols-outlined control-icon" :class="hasSelectedPlaylist ? 'active': 'inactive'" @click="exportCurrentPlaylist()" title="Export current playlist" style="margin-right: 1vw;">ios_share</span>
<div class="control-icon" id="settings">
<span class="material-symbols-outlined">info</span>
<div id="showIP">
<h4>IP to connect to:</h4><br>
<p>{{ localIP }}:8081</p>
</div>
</div>
<button @click="search()">S</button>
</div>
<div class="song-info">
<div class="song-info-wrapper">
<img v-if="hasFinishedInit" :src="playingSong.coverArtURL" class="image">
<span class="material-symbols-outlined image" v-else>music_note</span>
<div class="name">
<h3>{{ playingSong.title ?? 'No song selected' }}</h3>
<p>{{ playingSong.artist }}</p>
</div>
<div class="image"></div>
</div>
<div class="playback-pos-info">
<div style="margin-right: auto;">{{ playbackPosBeautified }}</div>
<div @click="toggleShowMode()" style="cursor: pointer;">{{ durationBeautified }}</div>
</div>
<div class="slider">
<progress id="progress-slider" class="progress-slider" :value="sliderProgress" max="1000" @mousedown="( e ) => { setPos( e ) }"
:class="hasFinishedInit ? '' : 'slider-inactive'"></progress>
<div v-if="hasFinishedInit" id="slider-knob" @mousedown="( e ) => { startMove( e ) }"
:style="'left: ' + ( parseInt( originalPos ) + parseInt( sliderPos ) ) + 'px;'">
<div id="slider-knob-style"></div>
</div>
<div v-else id="slider-knob" class="slider-inactive" style="left: 0;">
<div id="slider-knob-style"></div>
</div>
<div id="drag-support" @mousemove="e => { handleDrag( e ) }" @mouseup="() => { stopMove(); }"></div>
</div>
</div>
</div>
</div>
</div>
<div class="pool-wrapper">
<div style="width: 100%;" class="song-list-wrapper">
<div v-for="song in songQueue" class="song-list" :class="[ isPlaying ? ( playingSong.queuePos == song.queuePos ? 'playing': 'not-playing' ) : 'not-playing', !isPlaying && playingSong.filename === song.filename ? 'active-song': undefined ]">
<img :src="song.coverArtURL" class="song-image">
<div v-if="playingSong.queuePos == song.queuePos && isPlaying" class="playing-symbols">
<div class="playing-symbols-wrapper">
<div class="playing-bar" id="bar-1"></div>
<div class="playing-bar" id="bar-2"></div>
<div class="playing-bar" id="bar-3"></div>
</div>
</div>
<span class="material-symbols-outlined play-icon" @click="play( song )">play_arrow</span>
<span class="material-symbols-outlined pause-icon" @click="control( 'pause' )">pause</span>
<h3>{{ song.title }}</h3>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="/apple-music/helpers/index.js"></script>
</body>
</html>

View File

@@ -0,0 +1,720 @@
/*
* MusicPlayerV2 - index.js
*
* Created by Janis Hutz 11/20/2023, Licensed under the GPL V3 License
* https://janishutz.com, development@janishutz.com
*
*
*/
/*
Quick side note here: This is terribly ugly code, but I was in a hurry to finish it,
so I had no time to clean it up. I will do that at some point -jh
*/
const app = Vue.createApp( {
data() {
return {
musicKit: null,
isLoggedIn: false,
config: {
'devToken': '',
'userToken': ''
},
playlists: {},
hasSelectedPlaylist: false,
songQueue: {},
queuePos: 0,
pos: 0,
playingSong: {},
isPlaying: false,
isShuffleEnabled: false,
repeatMode: 'off',
playbackPosBeautified: '',
durationBeautified: '',
isShowingRemainingTime: false,
localIP: '',
hasLoadedPlaylists: false,
isPreparingToPlay: false,
additionalSongInfo: {},
hasFinishedInit: false,
isShowingWarning: false,
// For use with playlists that are partially from apple music and
// local drive
isUsingCustomPlaylist: false,
rawLoadedPlaylistData: {},
basePath: '',
audioPlayer: null,
isReconnecting: false,
// slider
offset: 0,
isDragging: false,
sliderPos: 0,
originalPos: 0,
sliderProgress: 0,
active: false,
}
},
methods: {
logInto() {
if ( !this.musicKit.isAuthorized ) {
this.musicKit.authorize().then( () => {
this.isLoggedIn = true;
this.initMusicKit();
} );
} else {
this.musicKit.authorize().then( () => {
this.isLoggedIn = true;
this.initMusicKit();
} );
}
},
initMusicKit () {
fetch( '/getAppleMusicDevToken' ).then( res => {
if ( res.status === 200 ) {
res.text().then( token => {
// MusicKit global is now defined
MusicKit.configure( {
developerToken: token,
app: {
name: 'MusicPlayer',
build: '2'
},
storefrontId: 'CH',
} ).then( () => {
this.config.devToken = token;
this.musicKit = MusicKit.getInstance();
if ( this.musicKit.isAuthorized ) {
this.isLoggedIn = true;
this.config.userToken = this.musicKit.musicUserToken;
}
this.musicKit.shuffleMode = MusicKit.PlayerShuffleMode.off;
this.apiGetRequest( 'https://api.music.apple.com/v1/me/library/playlists', this.playlistHandler );
} );
} );
}
} );
},
playlistHandler ( data ) {
if ( data.status === 'ok' ) {
const d = data.data.data;
this.playlist = {};
for ( let el in d ) {
this.playlists[ d[ el ].id ] = {
title: d[ el ].attributes.name,
id: d[ el ].id,
playParams: d[ el ].attributes.playParams,
}
}
this.hasLoadedPlaylists = true;
}
},
apiGetRequest( url, callback ) {
if ( this.config.devToken != '' && this.config.userToken != '' ) {
fetch( url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${ this.config.devToken }`,
'Music-User-Token': this.config.userToken
}
} ).then( res => {
if ( res.status === 200 ) {
res.json().then( json => {
try {
callback( { 'status': 'ok', 'data': json } );
} catch( err ) {}
} );
} else {
try {
callback( { 'status': 'error', 'error': res.status } );
} catch( err ) {}
}
} );
} else return false;
},
getAdditionalSongInfo() {
if ( Object.keys( this.additionalSongInfo ).length < 1 ) {
fetch( '/apple-music/getAdditionalData' ).then( res => {
if ( res.status === 200 ) {
res.json().then( json => {
this.additionalSongInfo = json;
this.handleAdditionalData();
} );
}
} );
}
},
handleAdditionalData () {
if ( Object.keys( this.additionalSongInfo ).length > 0 ) {
for ( let item in this.songQueue ) {
if ( this.additionalSongInfo[ item ] ) {
for ( let d in this.additionalSongInfo[ item ] ) {
if ( !this.songQueue[ item ][ d ] ) {
this.songQueue[ item ][ d ] = this.additionalSongInfo[ item ][ d ];
}
}
}
}
this.playingSong = this.songQueue[ this.queuePos ];
this.sendUpdate( 'songQueue' );
this.sendUpdate( 'playingSong' );
}
},
selectPlaylist( id ) {
this.isPreparingToPlay = true;
this.musicKit.setQueue( { playlist: id } ).then( () => {
try {
this.loadPlaylist();
this.hasSelectedPlaylist = true;
this.isPreparingToPlay = false;
} catch( err ) {
this.hasSelectedPlaylist = false;
console.error( err );
alert( 'We were unable to play. Please ensure that DRM (yeah sorry it is Apple Music, we cannot do anything about that) is enabled and working' );
}
} ).catch( err => {
console.error( 'ERROR whilst settings Queue', err );
} );
},
handleDrag( e ) {
if ( this.isDragging ) {
if ( 0 < this.originalPos + e.screenX - this.offset && this.originalPos + e.screenX - this.offset < document.getElementById( 'progress-slider' ).clientWidth - 5 ) {
this.sliderPos = e.screenX - this.offset;
this.calcProgressPos();
}
}
},
startMove( e ) {
this.offset = e.screenX;
this.isDragging = true;
document.getElementById( 'drag-support' ).classList.add( 'drag-support-active' );
},
stopMove() {
this.originalPos += parseInt( this.sliderPos );
this.isDragging = false;
this.offset = 0;
this.sliderPos = 0;
document.getElementById( 'drag-support' ).classList.remove( 'drag-support-active' );
this.calcPlaybackPos();
},
setPos ( e ) {
if ( this.hasSelectedPlaylist ) {
this.originalPos = e.offsetX;
this.calcProgressPos();
this.calcPlaybackPos();
if ( this.playingSong.origin === 'apple-music' ) {
this.musicKit.seekToTime( this.pos );
} else {
this.audioPlayer.currentTime = this.pos;
}
this.sendUpdate( 'pos' );
}
},
calcProgressPos() {
this.sliderProgress = Math.ceil( ( this.originalPos + parseInt( this.sliderPos ) ) / ( document.getElementById( 'progress-slider' ).clientWidth - 5 ) * 1000 );
},
calcPlaybackPos() {
this.pos = Math.round( ( this.originalPos + parseInt( this.sliderPos ) ) / ( document.getElementById( 'progress-slider' ).clientWidth - 5 ) * this.playingSong.duration );
},
sendUpdate( update ) {
let data = {};
let up = update;
if ( update === 'pos' ) {
data = this.pos;
} else if ( update === 'playingSong' ) {
data = this.playingSong;
} else if ( update === 'isPlaying' ) {
data = this.isPlaying;
} else if ( update === 'songQueue' ) {
data = this.songQueue;
} else if ( update === 'queuePos' ) {
data = this.queuePos;
} else if ( update === 'posReset' ) {
data = 0;
up = 'pos';
}
let fetchOptions = {
method: 'post',
body: JSON.stringify( { 'type': up, 'data': data } ),
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
},
};
fetch( 'http://localhost:8081/statusUpdate', fetchOptions ).catch( err => {
console.error( err );
} );
},
loadPlaylist() {
const songQueue = this.musicKit.queue.items;
for ( let item in songQueue ) {
this.songQueue[ item ] = {
'artist': songQueue[ item ].attributes.artistName,
'title': songQueue[ item ].attributes.name,
'year': songQueue[ item ].attributes.releaseDate,
'genre': songQueue[ item ].attributes.genreNames,
'duration': Math.round( songQueue[ item ].attributes.durationInMillis / 1000 ),
'filename': songQueue[ item ].id,
'coverArtOrigin': 'api',
'hasCoverArt': true,
'queuePos': item,
'origin': 'apple-music',
}
let url = songQueue[ item ].attributes.artwork.url;
url = url.replace( '{w}', songQueue[ item ].attributes.artwork.width );
url = url.replace( '{h}', songQueue[ item ].attributes.artwork.height );
this.songQueue[ item ][ 'coverArtURL' ] = url;
this.handleAdditionalData();
this.sendUpdate( 'songQueue' );
}
},
control( action ) {
if ( action === 'play' ) {
if ( !this.playingSong.origin ) {
this.play( this.songQueue[ 0 ] );
this.isPlaying = true;
} else {
if ( this.playingSong.origin === 'apple-music' ) {
if( !this.musicKit || !this.isPlaying ) {
this.musicKit.play().then( () => {
this.sendUpdate( 'pos' );
} ).catch( err => {
console.log( 'player failed to start' );
console.log( err );
} );
} else {
this.musicKit.pause().then( () => {
this.musicKit.play().catch( err => {
console.log( 'player failed to start' );
console.log( err );
} );
} );
}
try {
this.audioPlayer.pause();
} catch ( err ) {}
} else {
this.audioPlayer.play();
this.musicKit.pause();
}
this.isPlaying = true;
try {
clearInterval( this.progressTracker );
} catch( err ) {};
this.progressTracker = setInterval( () => {
if ( this.playingSong.origin === 'apple-music' ) {
this.pos = parseInt( this.musicKit.currentPlaybackTime );
} else {
this.pos = parseInt( this.audioPlayer.currentTime );
}
if ( this.pos > this.playingSong.duration - 1 ) {
this.control( 'next' );
}
const minuteCount = Math.floor( this.pos / 60 );
this.playbackPosBeautified = minuteCount + ':';
if ( ( '' + minuteCount ).length === 1 ) {
this.playbackPosBeautified = '0' + minuteCount + ':';
}
const secondCount = Math.floor( this.pos - minuteCount * 60 );
if ( ( '' + secondCount ).length === 1 ) {
this.playbackPosBeautified += '0' + secondCount;
} else {
this.playbackPosBeautified += secondCount;
}
if ( this.isShowingRemainingTime ) {
const minuteCounts = Math.floor( ( this.playingSong.duration - this.pos ) / 60 );
this.durationBeautified = '-' + String( minuteCounts ) + ':';
if ( ( '' + minuteCounts ).length === 1 ) {
this.durationBeautified = '-0' + minuteCounts + ':';
}
const secondCounts = Math.floor( ( this.playingSong.duration - this.pos ) - minuteCounts * 60 );
if ( ( '' + secondCounts ).length === 1 ) {
this.durationBeautified += '0' + secondCounts;
} else {
this.durationBeautified += secondCounts;
}
}
}, 50 );
this.sendUpdate( 'pos' );
this.sendUpdate( 'isPlaying' );
}
} else if ( action === 'pause' ) {
if ( this.playingSong.origin === 'apple-music' ) {
this.musicKit.pause();
} else {
this.audioPlayer.pause();
}
this.sendUpdate( 'pos' );
try {
clearInterval( this.progressTracker );
clearInterval( this.notifier );
} catch ( err ) {};
this.isPlaying = false;
this.sendUpdate( 'isPlaying' );
} else if ( action === 'replay10' ) {
if ( this.playingSong.origin === 'apple-music' ) {
this.musicKit.seekToTime( this.musicKit.currentPlaybackTime > 10 ? this.musicKit.currentPlaybackTime - 10 : 0 );
this.pos = this.musicKit.currentPlaybackTime;
} else {
this.audioPlayer.currentTime = this.audioPlayer.currentTime > 10 ? this.audioPlayer.currentTime - 10 : 0;
this.pos = this.audioPlayer.currentTime;
}
this.sendUpdate( 'pos' );
} else if ( action === 'forward10' ) {
if ( this.playingSong.origin === 'apple-music' ) {
if ( this.musicKit.currentPlaybackTime < ( this.playingSong.duration - 10 ) ) {
this.musicKit.seekToTime( this.musicKit.currentPlaybackTime + 10 );
this.pos = this.musicKit.currentPlaybackTime;
this.sendUpdate( 'pos' );
} else {
if ( this.repeatMode !== 'one' ) {
this.control( 'next' );
} else {
this.musicKit.seekToTime( 0 );
this.pos = this.musicKit.currentPlaybackTime;
this.sendUpdate( 'pos' );
}
}
} else {
if ( this.audioPlayer.currentTime < ( this.playingSong.duration - 10 ) ) {
this.audioPlayer.currentTime = this.audioPlayer.currentTime + 10;
this.pos = this.audioPlayer.currentTime;
this.sendUpdate( 'pos' );
} else {
if ( this.repeatMode !== 'one' ) {
this.control( 'next' );
} else {
this.audioPlayer.currentTime = 0;
this.pos = this.audioPlayer.currentTime;
this.sendUpdate( 'pos' );
}
}
}
} else if ( action === 'reset' ) {
clearInterval( this.progressTracker );
this.pos = 0;
if ( this.playingSong.origin === 'apple-music' ) {
this.musicKit.seekToTime( 0 );
} else {
this.audioPlayer.currentTime = 0;
}
this.sendUpdate( 'pos' );
} else if ( action === 'next' ) {
if ( this.queuePos < parseInt( Object.keys( this.songQueue ).length ) - 1 ) {
this.queuePos = parseInt( this.queuePos ) + 1;
this.play( this.songQueue[ this.queuePos ] );
} else {
if ( this.repeatMode === 'all' ) {
this.queuePos = 0;
this.play( this.songQueue[ 0 ] );
} else {
this.control( 'pause' );
}
}
} else if ( action === 'previous' ) {
if ( this.pos > 3 ) {
this.pos = 0;
if ( this.isUsingCustomPlaylist ) {
this.audioPlayer.currentTime = 0;
this.sendUpdate( 'pos' );
} else {
this.musicKit.seekToTime( 0 ).then( () => {
this.sendUpdate( 'pos' );
this.control( 'play' );
} );
}
} else {
if ( this.queuePos > 0 ) {
this.queuePos = parseInt( this.queuePos ) - 1;
this.play( this.songQueue[ this.queuePos ] );
} else {
this.queuePos = parseInt( Object.keys( this.songQueue ).length ) - 1;
this.play[ this.songQueue[ this.queuePos ] ];
}
}
} else if ( action === 'shuffleOff' ) {
// TODO: Make shuffle function
this.isShuffleEnabled = false;
// this.loadPlaylist();
alert( 'not implemented yet' );
} else if ( action === 'shuffleOn' ) {
this.isShuffleEnabled = true;
alert( 'not implemented yet' );
// this.loadPlaylist();
} else if ( action === 'repeatOne' ) {
this.repeatMode = 'one';
} else if ( action === 'repeatAll' ) {
this.repeatMode = 'all';
} else if ( action === 'repeatOff' ) {
this.musicKit.repeatMode = MusicKit.PlayerRepeatMode.none;
this.repeatMode = 'off';
}
},
play( song, specificID ) {
let foundSong = specificID ?? 0;
if ( !specificID ) {
for ( let s in this.songQueue ) {
if ( this.songQueue[ s ] === song ) {
foundSong = s;
}
}
}
this.queuePos = foundSong;
this.sendUpdate( 'queuePos' );
this.pos = 0;
this.sendUpdate( 'posReset' );
this.playingSong = song;
this.sendUpdate( 'playingSong' );
if ( song.origin === 'apple-music' ) {
this.musicKit.setQueue( { 'song': song.filename } ).then( () => {
setTimeout( () => {
this.control( 'play' );
}, 500 );
} ).catch( ( err ) => {
console.log( err );
} );
} else {
setTimeout( () => {
this.control( 'play' );
}, 500 );
}
const minuteCounts = Math.floor( ( this.playingSong.duration ) / 60 );
this.durationBeautified = String( minuteCounts ) + ':';
if ( ( '' + minuteCounts ).length === 1 ) {
this.durationBeautified = '0' + minuteCounts + ':';
}
const secondCounts = Math.floor( ( this.playingSong.duration ) - minuteCounts * 60 );
if ( ( '' + secondCounts ).length === 1 ) {
this.durationBeautified += '0' + secondCounts;
} else {
this.durationBeautified += secondCounts;
}
this.hasFinishedInit = true;
},
toggleShowMode() {
this.isShowingRemainingTime = !this.isShowingRemainingTime;
},
exportCurrentPlaylist() {
let fetchOptions = {
method: 'post',
body: JSON.stringify( this.songQueue ),
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
},
};
fetch( '/savePlaylist', fetchOptions ).then( res => {
if ( res.status === 200 ) {
console.log( 'saved' );
}
} );
},
selectPlaylistFromDisk() {
this.isPreparingToPlay = true;
let playlistSongs = [];
fetch( '/loadPlaylist' ).then( res => {
res.json().then( data => {
this.rawLoadedPlaylistData = data.data;
this.basePath = data.path.slice( 0, data.path.lastIndexOf( '/' ) );
for ( let song in this.rawLoadedPlaylistData ) {
if ( this.rawLoadedPlaylistData[ song ].origin === 'apple-music' ) {
playlistSongs.push( this.rawLoadedPlaylistData[ song ].filename );
}
}
this.musicKit.setQueue( { songs: playlistSongs } ).then( () => {
this.isUsingCustomPlaylist = true;
try {
this.loadCustomPlaylist();
this.hasSelectedPlaylist = true;
this.isPreparingToPlay = false;
} catch( err ) {
this.hasSelectedPlaylist = false;
console.error( err );
alert( 'We were unable to play. Please ensure that DRM (yeah sorry it is Apple Music, we cannot do anything about that) is enabled and working' );
}
} ).catch( err => {
console.error( 'ERROR whilst settings Queue', err );
} );
} );
} );
},
loadCustomPlaylist() {
const songQueue = this.musicKit.queue.items;
let offset = 0;
( async() => {
for ( let item in this.rawLoadedPlaylistData ) {
if ( this.rawLoadedPlaylistData[ item ].origin === 'apple-music' ) {
this.songQueue[ item ] = {
'artist': songQueue[ item - offset ].attributes.artistName,
'title': songQueue[ item - offset ].attributes.name,
'year': songQueue[ item - offset ].attributes.releaseDate,
'genre': songQueue[ item - offset ].attributes.genreNames,
'duration': Math.round( songQueue[ item - offset ].attributes.durationInMillis / 1000 ),
'filename': songQueue[ item - offset ].id,
'coverArtOrigin': 'api',
'hasCoverArt': true,
'queuePos': item,
'origin': 'apple-music',
'offset': offset,
}
let url = songQueue[ item - offset ].attributes.artwork.url;
url = url.replace( '{w}', songQueue[ item - offset ].attributes.artwork.width );
url = url.replace( '{h}', songQueue[ item - offset ].attributes.artwork.height );
this.songQueue[ item ][ 'coverArtURL' ] = url;
} else {
offset += 1;
const queryParameters = {
term: ( this.rawLoadedPlaylistData[ item ].artist ?? '' ) + ' ' + ( this.rawLoadedPlaylistData[ item ].title ?? '' ),
types: [ 'songs' ],
};
// TODO: Make storefront adjustable
const result = await this.musicKit.api.music( '/v1/catalog/ch/search', queryParameters );
let json;
try {
const res = await fetch( '/getMetadata?file=' + this.basePath + '/' + this.rawLoadedPlaylistData[ item ].filename );
json = await res.json();
} catch( err ) {}
if ( result.data ) {
if ( result.data.results.songs ) {
const dat = result.data.results.songs.data[ 0 ];
console.log( json );
this.songQueue[ item ] = {
'artist': dat.attributes.artistName,
'title': dat.attributes.name,
'year': dat.attributes.releaseDate,
'genre': dat.attributes.genreNames,
'duration': json ? Math.round( json.duration ) : undefined,
'filename': this.rawLoadedPlaylistData[ item ].filename,
'coverArtOrigin': 'api',
'hasCoverArt': true,
'queuePos': item,
'origin': 'local',
}
let url = dat.attributes.artwork.url;
url = url.replace( '{w}', dat.attributes.artwork.width );
url = url.replace( '{h}', dat.attributes.artwork.height );
this.songQueue[ item ][ 'coverArtURL' ] = url;
}
}
}
this.handleAdditionalData();
this.sendUpdate( 'songQueue' );
}
} )();
setTimeout( () => {
this.audioPlayer = document.getElementById( 'audio-player' );
}, 1000 );
},
search() {
( async() => {
const searchTerm = prompt( 'Enter search term...' )
const queryParameters = {
term: ( searchTerm ),
types: [ 'songs' ],
};
// TODO: Make storefront adjustable
const result = await this.musicKit.api.music( '/v1/catalog/ch/search', queryParameters );
console.log( result );
} )();
},
connectToNotifier() {
let source = new EventSource( '/mainNotifier', { withCredentials: true } );
source.onmessage = ( e ) => {
let data;
try {
data = JSON.parse( e.data );
} catch ( err ) {
data = { 'type': e.data };
}
if ( data.type === 'blur' ) {
this.isShowingWarning = true;
} else if ( data.type === 'visibility' ) {
this.isShowingWarning = true;
}
};
source.onopen = () => {
this.isReconnecting = false;
console.log( 'client notifier connected successfully' );
};
let self = this;
source.addEventListener( 'error', function( e ) {
if ( e.eventPhase == EventSource.CLOSED ) source.close();
if ( e.target.readyState == EventSource.CLOSED ) {
setTimeout( () => {
if ( !self.isReconnecting ) {
console.log( 'disconnected' );
console.log( 'reconnecting...' );
self.isReconnecting = true;
self.tryReconnect();
}
}, 1000 );
}
}, false );
},
tryReconnect() {
const int = setInterval( () => {
if ( !this.isReconnecting ) {
clearInterval( int );
} else {
this.connectToNotifier();
}
}, 1000 );
},
dismissNotification() {
this.isShowingWarning = false;
}
},
watch: {
pos() {
if ( !this.isDragging ) {
this.sliderProgress = Math.ceil( this.pos / this.playingSong.duration * 1000 + 2 );
this.originalPos = Math.ceil( this.pos / this.playingSong.duration * ( document.getElementById( 'progress-slider' ).scrollWidth - 5 ) );
}
}
},
created() {
document.addEventListener( 'keydown', ( e ) => {
if ( e.key === ' ' ) {
e.preventDefault();
if ( !this.isPlaying ) {
this.control( 'play' );
} else {
this.control( 'pause' );
}
} else if ( e.key === 'ArrowRight' ) {
e.preventDefault();
this.control( 'next' );
} else if ( e.key === 'ArrowLeft' ) {
e.preventDefault();
this.control( 'previous' );
}
} );
if ( !window.MusicKit ) {
document.addEventListener( 'musickitloaded', () => {
self.initMusicKit();
} );
} else {
this.initMusicKit();
}
this.connectToNotifier();
fetch( '/getLocalIP' ).then( res => {
if ( res.status === 200 ) {
res.text().then( ip => {
this.localIP = ip;
} );
}
} );
},
} ).mount( '#app' );

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,136 @@
.song-info {
background-color: #8e9ced;
height: 13vh;
width: 50%;
margin-left: auto;
margin-right: auto;
position: relative;
}
.image {
width: 7vh;
height: 7vh;
object-fit: cover;
object-position: center;
font-size: 7vh;
margin-left: 1vh;
margin-top: 1vh;
}
.name {
margin-left: auto;
margin-right: auto;
}
.song-info-wrapper {
display: flex;
flex-direction: row;
}
.song-info-wrapper h3 {
margin: 0;
margin-bottom: 0.5vh;
margin-top: 1vh;
}
.controls {
margin-left: 5%;
display: flex;
justify-content: center;
align-items: center;
}
.control-icon {
cursor: pointer;
font-size: 3vh;
user-select: none;
}
.play-pause {
font-size: 5vh;
}
.inactive {
color: gray;
cursor: default;
}
.player {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
.playback-pos-info {
display: flex;
flex-direction: row;
width: 98%;
margin-left: 1%;
position: absolute;
bottom: 17px;
}
#showIP {
background-color: rgb(63, 63, 63);
display: none;
position: absolute;
min-height: 16vh;
padding: 2vh;
min-width: 20vw;
z-index: 10;
justify-content: center;
align-items: center;
flex-direction: column;
font-size: 70%;
border-radius: 5px 10px 10px 10px;
}
#showIP h4, #showIP p {
margin: 0;
}
#settings:hover #showIP {
display: flex;
}
#showIP::before {
content: " ";
position: absolute;
bottom: 100%; /* At the bottom of the tooltip */
left: 0;
margin-left: 3px;
border-width: 10px;
border-style: solid;
border-color: transparent transparent rgb(63, 63, 63) transparent;
}
/* Prepare to play */
.preparingToPlay {
background-color: rgba(0, 0, 0, 0.7);
width: 100vw;
height: 100vh;
position: fixed;
align-items: center;
justify-content: center;
display: flex;
flex-direction: column;
top: 0;
left: 0;
}
.loading-spinner {
animation: spin 2s infinite linear;
}
@keyframes spin {
from {
transform: rotate( 0deg );
}
to {
transform: rotate( 720deg );
}
}

View File

@@ -0,0 +1,359 @@
/*
* MusicPlayerV2 - style.css
*
* Created by Janis Hutz 11/14/2023, Licensed under the GPL V3 License
* https://janishutz.com, development@janishutz.com
*
*
*/
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: rgb(49, 49, 49);
font-family: sans-serif;
color: white;
}
/* Start page style */
.start-page {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.image-wrapper {
height: 50vh;
width: 50vh;
}
#logo-main {
height: 50vh;
}
#apple-music-logo {
height: 10vh;
position: relative;
bottom: 10vh;
left: 41vh;
}
.button {
padding: 20px;
background-color: rgb(1, 1, 88);
color: white;
border: none;
border-radius: 50px;
transition: all 1s;
cursor: pointer;
font-size: 120%;
}
.button:hover {
background-color: rgb(1, 1, 120);
border-radius: 20px;
}
/* Main style */
.home {
width: 100%;
height: 100%;
}
.pool-wrapper {
height: 84vh;
margin-top: 16vh;
}
.top-bar {
top: 0;
margin-left: auto;
margin-right: auto;
position: fixed;
z-index: 8;
width: 99%;
height: 15vh;
display: flex;
align-items: center;
flex-direction: row;
border: white 2px solid;
background-color: rgb(49, 49, 49);
}
.player-wrapper {
width: 70vw;
margin-right: auto;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.logo {
height: 13vh;
margin-left: 3%;
margin-right: auto;
}
/* Media Pool */
.playing-symbols {
position: absolute;
left: 10%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
margin: 0;
width: 5vw;
height: 5vw;
background-color: rgba( 0, 0, 0, 0.6 );
}
.playing-symbols-wrapper {
width: 4vw;
height: 5vw;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.playing-bar {
height: 60%;
background-color: white;
width: 10%;
border-radius: 50px;
margin: auto;
}
#bar-1 {
animation: music-playing 0.9s infinite ease-in-out;
}
#bar-2 {
animation: music-playing 0.9s infinite ease-in-out;
animation-delay: 0.3s;
}
#bar-3 {
animation: music-playing 0.9s infinite ease-in-out;
animation-delay: 0.6s;
}
@keyframes music-playing {
0% {
transform: scaleY( 1 );
}
50% {
transform: scaleY( 0.5 );
}
100% {
transform: scaleY( 1 );
}
}
.loading-spinner {
animation: spin 2s infinite linear;
}
@keyframes spin {
from {
transform: rotate( 0deg );
}
to {
transform: rotate( 720deg );
}
}
.media-pool {
width: 100%;
height: 100%;
display: flex;
align-items: center;
flex-direction: column;
}
.no-songs {
height: 50vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.song-list-wrapper {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.song-list {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 80%;
margin: 2px;
padding: 1vh;
border: 1px white solid;
}
.song-list h3 {
margin: 0;
display: block;
margin-left: 10px;
margin-right: auto;
}
.song-list .song-image {
width: 5vw;
height: 5vw;
object-fit: cover;
object-position: center;
font-size: 5vw;
}
.play-icon, .pause-icon {
display: none;
width: 5vw;
height: 5vw;
object-fit: cover;
object-position: center;
font-size: 5vw;
cursor: pointer;
user-select: none;
}
.playing:hover .pause-icon {
display: block;
}
.playing:hover .playing-symbols {
display: none;
}
.song-list:hover .song-image {
display: none;
}
.not-playing:hover .play-icon {
display: block;
}
.active-song .pause-icon {
display: block;
}
.active-song .song-image, .active-song:hover .pause-icon {
display: none;
}
/* Slider */
.progress-slider {
width: 100%;
margin: 0;
position: absolute;
left: 0;
bottom: 0;
height: 5px;
cursor: pointer;
background-color: #baf4c9;
}
.progress-slider::-webkit-progress-value {
background-color: #baf4c9;
}
#slider-knob {
height: 20px;
width: 10px;
display: flex;
justify-content: flex-start;
align-items: flex-end;
position: absolute;
bottom: 0;
left: 0;
z-index: 2;
cursor: grab;
}
#slider-knob-style {
background-color: #baf4c9;
height: 15px;
width: 5px;
}
#drag-support {
display: none;
opacity: 0;
height: 100vh;
width: 100vw;
position: fixed;
top: 0;
left: 0;
z-index: 10;
cursor: grabbing;
}
.drag-support-active {
display: block !important;
}
.slider-inactive {
cursor: default !important;
}
.warning {
display: flex;
justify-content: center;
align-items: center;
width: 40vw;
height: 50vh;
font-size: 2vh;
background-color: rgb(255, 0, 0);
color: white;
position: fixed;
right: 1vh;
top: 1vh;
flex-direction: column;
z-index: 100;
}
.warning h3 {
font-size: 4vh;
}
.warning .flash {
background-color: rgba(255, 0, 0, 0.4);
animation: flashing linear infinite 1s;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
position: fixed;
z-index: -1;
}
@keyframes flashing {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}

View File

@@ -0,0 +1,44 @@
.background {
position: fixed;
left: -50vw;
width: 200vw;
height: 200vw;
top: -50vw;
z-index: -1;
filter: blur(10px);
background: conic-gradient( blue, green, red, blue );
animation: gradientAnim 10s infinite linear;
background-position: center;
}
.beat, .beat-manual {
height: 100%;
width: 100%;
background-color: rgba( 0, 0, 0, 0.15 );
display: none;
}
.beat {
animation: beatAnim 0.6s infinite linear;
}
@keyframes beatAnim {
0% {
background-color: rgba( 0, 0, 0, 0.2 );
}
20% {
background-color: rgba( 0, 0, 0, 0 );
}
100% {
background-color: rgba( 0, 0, 0, 0.2 );
}
}
@keyframes gradientAnim {
from {
transform: rotate( 0deg );
}
to {
transform: rotate( 360deg );
}
}

View File

@@ -0,0 +1,24 @@
/* fallback */
@font-face {
font-family: 'Material Symbols Outlined';
font-style: normal;
font-weight: 100 700;
src: url(/iconFont.woff2) format('woff2');
}
.material-symbols-outlined {
font-family: 'Material Symbols Outlined';
font-weight: normal;
font-style: normal;
font-size: 24px;
line-height: 1;
letter-spacing: normal;
text-transform: none;
display: inline-block;
white-space: nowrap;
word-wrap: normal;
direction: ltr;
-moz-font-feature-settings: 'liga';
-moz-osx-font-smoothing: grayscale;
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 KiB

View File

@@ -0,0 +1,208 @@
.material-symbols-outlined {
font-variation-settings:
'FILL' 0,
'wght' 400,
'GRAD' 0,
'opsz' 24
}
body, html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
color: white;
}
body {
font-family: sans-serif;
}
.content {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.playing-symbols {
position: absolute;
left: 10vw;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
width: 5vw;
height: 5vw;
background-color: rgba( 0, 0, 0, 0.6 );
}
.playing-symbols-wrapper {
width: 4vw;
height: 5vw;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.playing-bar {
height: 60%;
background-color: white;
width: 10%;
border-radius: 50px;
margin: auto;
}
#bar-1 {
animation: music-playing 0.9s infinite ease-in-out;
}
#bar-2 {
animation: music-playing 0.9s infinite ease-in-out;
animation-delay: 0.3s;
}
#bar-3 {
animation: music-playing 0.9s infinite ease-in-out;
animation-delay: 0.6s;
}
@keyframes music-playing {
0% {
transform: scaleY( 1 );
}
50% {
transform: scaleY( 0.5 );
}
100% {
transform: scaleY( 1 );
}
}
.song-list-wrapper {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.song-list {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 80%;
margin: 2px;
padding: 1vh;
border: 1px white solid;
background-color: rgba( 0, 0, 0, 0.4 );
}
.song-details-wrapper {
margin: 0;
display: block;
margin-left: 10px;
margin-right: auto;
}
.song-list .song-image {
width: 5vw;
height: 5vw;
object-fit: cover;
object-position: center;
font-size: 5vw;
}
.pause-icon {
width: 5vw;
height: 5vw;
object-fit: cover;
object-position: center;
font-size: 5vw !important;
user-select: none;
}
.current-song-wrapper {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 55vh;
width: 100%;
margin-bottom: 0.5%;
margin-top: 0.25%;
}
.current-song {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin-top: 1vh;
padding: 1vh;
text-align: center;
background-color: rgba( 0, 0, 0, 0.4 );
}
.fancy-view-song-art {
height: 30vh;
width: 30vh;
object-fit: cover;
object-position: center;
margin-bottom: 10px;
font-size: 30vh !important;
}
#app {
background-color: rgba( 0, 0, 0, 0 );
}
#progress, #progress::-webkit-progress-bar {
background-color: rgba(45, 28, 145);
color: rgba(45, 28, 145);
width: 30vw;
border: none;
border-radius: 0px;
accent-color: white;
-webkit-appearance: none;
appearance: none;
}
#progress::-moz-progress-bar {
background-color: white;
}
#progress::-webkit-progress-value {
background-color: white !important;
}
.mode-selector-wrapper {
opacity: 0;
position: fixed;
right: 0.5%;
top: 0.5%;
padding: 0.5%;
}
.mode-selector-wrapper:hover {
opacity: 1;
}
.dancing-style {
font-size: 250%;
margin: 0;
font-weight: bolder;
}
.info {
position: fixed;
font-size: 12px;
transform: rotate(270deg);
left: -150px;
margin: 0;
padding: 0;
top: 50%;
}

View File

@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=7">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Showcase - MusicPlayerV2</title>
<link rel="stylesheet" href="/showcase.css">
<link rel="stylesheet" href="/backgroundAnim.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
</head>
<body>
<div class="info">Designed and developed by Janis Hutz <a href="https://janishutz.com" target="_blank" style="text-decoration: none; color: white;">https://janishutz.com</a></div>
<div class="content" id="app">
<div v-if="hasLoaded" style="width: 100%">
<div class="current-song-wrapper">
<span class="material-symbols-outlined fancy-view-song-art" v-if="!playingSong.hasCoverArt">music_note</span>
<img v-else-if="playingSong.hasCoverArt && playingSong.coverArtOrigin === 'api'" :src="playingSong.coverArtURL" class="fancy-view-song-art" id="current-image" crossorigin="anonymous">
<img v-else :src="'/getSongCover?filename=' + playingSong.filename" class="fancy-view-song-art" id="current-image">
<div class="current-song">
<progress max="1000" id="progress" :value="progressBar"></progress>
<h1>{{ playingSong.title }}</h1>
<p class="dancing-style" v-if="playingSong.dancingStyle">{{ playingSong.dancingStyle }}</p>
<p>{{ playingSong.artist }}</p>
</div>
</div>
<div class="mode-selector-wrapper">
<select v-model="visualizationSettings" @change="setVisualization()">
<option value="mic">Microphone (Mic access required)</option>
<option value="bpm">BPM (might not be 100% accurate)</option>
<option value="off">No visualization except background</option>
</select>
</div>
<div class="song-list-wrapper">
<div v-for="song in songQueue" class="song-list">
<span class="material-symbols-outlined song-image" v-if="!song.hasCoverArt && ( playingSong.filename !== song.filename || isPlaying )">music_note</span>
<img v-else-if="song.hasCoverArt && ( playingSong.filename !== song.filename || isPlaying ) && song.coverArtOrigin === 'api'" :src="song.coverArtURL" class="song-image">
<img v-else-if="song.hasCoverArt && ( playingSong.filename !== song.filename || isPlaying ) && song.coverArtOrigin !== 'api'" :src="'/getSongCover?filename=' + song.filename" class="song-image">
<div v-if="playingSong.filename === song.filename && isPlaying" class="playing-symbols">
<div class="playing-symbols-wrapper">
<div class="playing-bar" id="bar-1"></div>
<div class="playing-bar" id="bar-2"></div>
<div class="playing-bar" id="bar-3"></div>
</div>
</div>
<span class="material-symbols-outlined pause-icon" v-if="!isPlaying && playingSong.filename === song.filename">pause</span>
<div class="song-details-wrapper">
<h3>{{ song.title }}</h3>
<p>{{ song.artist }}</p>
</div>
<div class="time-until">
{{ getTimeUntil( song ) }}
</div>
</div>
<!-- <img :src="" alt=""> -->
</div>
</div>
<div v-else>
<h1>Loading...</h1>
</div>
<div class="background" id="background">
<div class="beat"></div>
<div class="beat-manual"></div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.0/color-thief.umd.js"></script>
<script src="/showcase.js"></script>
</body>
</html>

View File

@@ -0,0 +1,359 @@
// eslint-disable-next-line no-undef
const { createApp } = Vue;
createApp( {
data() {
return {
hasLoaded: false,
songs: [],
playingSong: {},
isPlaying: false,
pos: 0,
queuePos: 0,
colourPalette: [],
progressBar: 0,
timeTracker: null,
visualizationSettings: 'mic',
micAnalyzer: null,
beatDetected: false,
colorThief: null,
lastDispatch: new Date().getTime() - 5000,
isReconnecting: false,
};
},
computed: {
songQueue() {
let ret = [];
let pos = 0;
for ( let song in this.songs ) {
if ( pos >= this.queuePos ) {
ret.push( this.songs[ song ] );
}
pos += 1;
}
return ret;
},
getTimeUntil() {
return ( song ) => {
let timeRemaining = 0;
for ( let i = this.queuePos; i < Object.keys( this.songs ).length - 1; i++ ) {
if ( this.songs[ i ] == song ) {
break;
}
timeRemaining += parseInt( this.songs[ i ].duration );
}
if ( this.isPlaying ) {
if ( timeRemaining === 0 ) {
return 'Currently playing';
} else {
return 'Playing in less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min';
}
} else {
if ( timeRemaining === 0 ) {
return 'Plays next';
} else {
return 'Playing less than ' + Math.ceil( timeRemaining / 60 - this.pos / 60 ) + 'min after starting to play';
}
}
}
}
},
methods: {
startTimeTracker () {
this.timeTracker = setInterval( () => {
this.pos = ( new Date().getTime() - this.playingSong.startTime ) / 1000 + this.oldPos;
this.progressBar = ( this.pos / this.playingSong.duration ) * 1000;
if ( isNaN( this.progressBar ) ) {
this.progressBar = 0;
}
}, 100 );
},
stopTimeTracker () {
clearInterval( this.timeTracker );
this.oldPos = this.pos;
},
getImageData() {
return new Promise( ( resolve, reject ) => {
if ( this.playingSong.hasCoverArt ) {
setTimeout( () => {
const img = document.getElementById( 'current-image' );
if ( img.complete ) {
resolve( this.colorThief.getPalette( img ) );
} else {
img.addEventListener( 'load', () => {
resolve( this.colorThief.getPalette( img ) );
} );
}
}, 500 );
} else {
reject( 'no image' );
}
} );
},
connect() {
this.colorThief = new ColorThief();
let source = new EventSource( '/clientDisplayNotifier', { withCredentials: true } );
source.onmessage = ( e ) => {
let data;
try {
data = JSON.parse( e.data );
} catch ( err ) {
data = { 'type': e.data };
}
if ( data.type === 'basics' ) {
this.isPlaying = data.data.isPlaying ?? false;
this.playingSong = data.data.playingSong ?? {};
this.songs = data.data.songQueue ?? [];
this.pos = data.data.pos ?? 0;
this.oldPos = data.data.pos ?? 0;
this.progressBar = this.pos / this.playingSong.duration * 1000;
this.queuePos = data.data.queuePos ?? 0;
this.getImageData().then( palette => {
this.colourPalette = palette;
this.handleBackground();
} ).catch( () => {
this.colourPalette = [ { 'r': 255, 'g': 0, 'b': 0 }, { 'r': 0, 'g': 255, 'b': 0 }, { 'r': 0, 'g': 0, 'b': 255 } ];
this.handleBackground();
} );
} else if ( data.type === 'pos' ) {
this.pos = data.data;
this.oldPos = data.data;
this.progressBar = data.data / this.playingSong.duration * 1000;
} else if ( data.type === 'isPlaying' ) {
this.isPlaying = data.data;
this.handleBackground();
} else if ( data.type === 'songQueue' ) {
this.songs = data.data;
} else if ( data.type === 'playingSong' ) {
this.playingSong = data.data;
this.getImageData().then( palette => {
this.colourPalette = palette;
this.handleBackground();
} ).catch( () => {
this.colourPalette = [ [ 255, 0, 0 ], [ 0, 255, 0 ], [ 0, 0, 255 ] ];
this.handleBackground();
} );
} else if ( data.type === 'queuePos' ) {
this.queuePos = data.data;
}
};
source.onopen = () => {
this.isReconnecting = false;
this.hasLoaded = true;
};
let self = this;
source.addEventListener( 'error', function( e ) {
if ( e.eventPhase == EventSource.CLOSED ) source.close();
if ( e.target.readyState == EventSource.CLOSED ) {
setTimeout( () => {
if ( !self.isReconnecting ) {
console.log( 'disconnected' );
self.isReconnecting = true;
self.tryReconnect();
}
}, 1000 );
}
}, false );
},
tryReconnect() {
const int = setInterval( () => {
if ( !this.isReconnecting ) {
clearInterval( int );
} else {
this.connect();
}
}, 1000 );
},
handleBackground() {
let colourDetails = [];
let colours = [];
let differentEnough = true;
if ( this.colourPalette[ 0 ] ) {
for ( let i in this.colourPalette ) {
for ( let colour in colourDetails ) {
const colourDiff = ( Math.abs( colourDetails[ colour ][ 0 ] - this.colourPalette[ i ][ 0 ] ) / 255
+ Math.abs( colourDetails[ colour ][ 1 ] - this.colourPalette[ i ][ 1 ] ) / 255
+ Math.abs( colourDetails[ colour ][ 2 ] - this.colourPalette[ i ][ 2 ] ) / 255 ) / 3 * 100;
if ( colourDiff > 15 ) {
differentEnough = true;
}
}
if ( differentEnough ) {
colourDetails.push( this.colourPalette[ i ] );
colours.push( 'rgb(' + this.colourPalette[ i ][ 0 ] + ',' + this.colourPalette[ i ][ 1 ] + ',' + this.colourPalette[ i ][ 2 ] + ')' );
}
differentEnough = false;
}
}
let outColours = 'conic-gradient(';
if ( colours.length < 3 ) {
for ( let i = 0; i < 3; i++ ) {
if ( colours[ i ] ) {
outColours += colours[ i ] + ',';
} else {
if ( i === 0 ) {
outColours += 'blue,';
} else if ( i === 1 ) {
outColours += 'green,';
} else if ( i === 2 ) {
outColours += 'red,';
}
}
}
} else if ( colours.length < 11 ) {
for ( let i in colours ) {
outColours += colours[ i ] + ',';
}
} else {
for ( let i = 0; i < 10; i++ ) {
outColours += colours[ i ] + ',';
}
}
outColours += colours[ 0 ] ?? 'blue' + ')';
$( '#background' ).css( 'background', outColours );
this.setVisualization();
},
setVisualization () {
if ( Object.keys( this.playingSong ).length > 0 ) {
if ( this.visualizationSettings === 'bpm' ) {
if ( this.playingSong.bpm && this.isPlaying ) {
$( '.beat' ).show();
$( '.beat' ).css( 'animation-duration', 60 / this.playingSong.bpm );
$( '.beat' ).css( 'animation-delay', this.pos % ( 60 / this.playingSong.bpm * this.pos ) + this.playingSong.bpmOffset - ( 60 / this.playingSong.bpm * this.pos / 2 ) );
} else {
$( '.beat' ).hide();
}
try {
clearInterval( this.micAnalyzer );
} catch ( err ) {}
} else if ( this.visualizationSettings === 'off' ) {
$( '.beat' ).hide();
try {
clearInterval( this.micAnalyzer );
} catch ( err ) {}
} else if ( this.visualizationSettings === 'mic' ) {
$( '.beat-manual' ).hide();
try {
clearInterval( this.micAnalyzer );
} catch ( err ) {}
this.micAudioHandler();
}
} else {
console.log( 'not playing yet' );
}
},
micAudioHandler () {
const audioContext = new ( window.AudioContext || window.webkitAudioContext )();
const analyser = audioContext.createAnalyser();
analyser.fftSize = 256;
const bufferLength = analyser.frequencyBinCount;
const dataArray = new Uint8Array( bufferLength );
navigator.mediaDevices.getUserMedia( { audio: true } ).then( ( stream ) => {
const mic = audioContext.createMediaStreamSource( stream );
mic.connect( analyser );
analyser.getByteFrequencyData( dataArray );
let prevSpectrum = null;
let threshold = 10; // Adjust as needed
this.beatDetected = false;
this.micAnalyzer = setInterval( () => {
analyser.getByteFrequencyData( dataArray );
// Convert the frequency data to a numeric array
const currentSpectrum = Array.from( dataArray );
if ( prevSpectrum ) {
// Calculate the spectral flux
const flux = this.calculateSpectralFlux( prevSpectrum, currentSpectrum );
if ( flux > threshold && !this.beatDetected ) {
// Beat detected
this.beatDetected = true;
this.animateBeat();
}
}
prevSpectrum = currentSpectrum;
}, 20 );
} );
},
animateBeat () {
$( '.beat-manual' ).stop();
const duration = Math.ceil( 60 / ( this.playingSong.bpm ?? 180 ) * 500 ) - 50;
$( '.beat-manual' ).fadeIn( 50 );
setTimeout( () => {
$( '.beat-manual' ).fadeOut( duration );
setTimeout( () => {
$( '.beat-manual' ).stop();
this.beatDetected = false;
}, duration );
}, 50 );
},
calculateSpectralFlux( prevSpectrum, currentSpectrum ) {
let flux = 0;
for ( let i = 0; i < prevSpectrum.length; i++ ) {
const diff = currentSpectrum[ i ] - prevSpectrum[ i ];
flux += Math.max( 0, diff );
}
return flux;
},
notifier() {
if ( parseInt( this.lastDispatch ) + 5000 < new Date().getTime() ) {
}
Notification.requestPermission();
console.warn( '[ notifier ]: Status is now enabled \n\n-> Any leaving or tampering with the website will send a notification to the host' );
// Detect if window is currently in focus
window.onblur = () => {
this.sendNotification( 'blur' );
}
// Detect if browser window becomes hidden (also with blur event)
document.onvisibilitychange = () => {
if ( document.visibilityState === 'hidden' ) {
this.sendNotification( 'visibility' );
}
};
},
sendNotification( notification ) {
let fetchOptions = {
method: 'post',
body: JSON.stringify( { 'type': notification } ),
headers: {
'Content-Type': 'application/json',
'charset': 'utf-8'
},
};
fetch( '/clientStatusUpdate', fetchOptions ).catch( err => {
console.error( err );
} );
new Notification( 'YOU ARE UNDER SURVEILLANCE', {
body: 'Please return to the original webpage immediately!',
requireInteraction: true,
} )
}
},
mounted() {
this.connect();
this.notifier();
// if ( this.visualizationSettings === 'mic' ) {
// this.micAudioHandler();
// }
},
watch: {
isPlaying( value ) {
if ( value ) {
this.startTimeTracker();
} else {
this.stopTimeTracker();
}
}
}
} ).mount( '#app' );