diff --git a/frontend/public/index.html b/frontend/public/index.html index 583f14a..50f6f62 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -7,7 +7,6 @@ - <%= htmlWebpackPlugin.options.title %> diff --git a/frontend/src/app.js b/frontend/src/app.js index cd2c969..79e799c 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -10,6 +10,7 @@ const indexer = require( './indexer.js' ); const axios = require( 'axios' ); const ip = require( 'ip' ); const jwt = require( 'jsonwebtoken' ); +const shell = require( 'electron' ).shell; app.use( bodyParser.urlencoded( { extended: false } ) ); @@ -64,6 +65,8 @@ let currentDetails = { let connectedMain = {}; // TODO: Add backend integration +require( './appleMusicRoutes.js' )( app ); + app.get( '/', ( request, response ) => { response.sendFile( path.join( __dirname + '/client/showcase.html' ) ); } ); @@ -72,6 +75,11 @@ app.get( '/getLocalIP', ( req, res ) => { res.send( ip.address() ); } ); +app.get( '/useAppleMusic', ( req, res ) => { + shell.openExternal( 'http://localhost:8081/apple-music' ); + res.send( 'ok' ); +} ); + app.get( '/openSongs', ( req, res ) => { // res.send( '{ "data": [ "/home/janis/Music/KB2022" ] }' ); res.send( '{ "data": [ "/mnt/storage/SORTED/Music/audio/KB2022" ] }' ); diff --git a/frontend/src/appleMusicRoutes.js b/frontend/src/appleMusicRoutes.js new file mode 100644 index 0000000..9e8980a --- /dev/null +++ b/frontend/src/appleMusicRoutes.js @@ -0,0 +1,20 @@ +/* +* MusicPlayerV2 - appleMusicRoutes.js +* +* Created by Janis Hutz 11/14/2023, Licensed under the GPL V3 License +* https://janishutz.com, development@janishutz.com +* +* +*/ + +const path = require( 'path' ); + +module.exports = ( app ) => { + app.get( '/apple-music', ( req, res ) => { + res.sendFile( path.join( __dirname + '/client/appleMusic/index.html' ) ); + } ); + + app.get( '/apple-music/helpers/:file', ( req, res ) => { + res.sendFile( path.join( __dirname + '/client/appleMusic/' + req.params.file ) ); + } ); +} \ No newline at end of file diff --git a/frontend/src/client/appleMusic/index.html b/frontend/src/client/appleMusic/index.html new file mode 100644 index 0000000..5059789 --- /dev/null +++ b/frontend/src/client/appleMusic/index.html @@ -0,0 +1,23 @@ + + + + + + MusicPlayerV2 + + + +
+
+

Apple Music

+ +
+
+ +
+
+ + + + + \ No newline at end of file diff --git a/frontend/src/client/appleMusic/index.js b/frontend/src/client/appleMusic/index.js new file mode 100644 index 0000000..6cbf3b5 --- /dev/null +++ b/frontend/src/client/appleMusic/index.js @@ -0,0 +1,47 @@ +const app = Vue.createApp( { + data() { + return { + musicKit: null, + isLoggedIn: false, + } + }, + methods: { + logInto() { + if ( !this.musicKit.isAuthorized ) { + this.musicKit.authorize().then( () => { + this.musicKit.play(); + this.isLoggedIn(); + } ); + } + }, + 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' + } + } ); + this.musicKit = MusicKit.getInstance(); + if ( this.musicKit.isAuthorized ) { + this.isLoggedIn = true; + } + } ); + } + } ); + } + }, + created() { + if ( !window.MusicKit ) { + document.addEventListener( 'musickitloaded', () => { + self.initMusicKit(); + } ); + } else { + this.initMusicKit(); + } + }, +} ).mount( '#app' ); \ No newline at end of file diff --git a/frontend/public/musickit.js b/frontend/src/client/appleMusic/musickit.js similarity index 100% rename from frontend/public/musickit.js rename to frontend/src/client/appleMusic/musickit.js diff --git a/frontend/src/client/appleMusic/style.css b/frontend/src/client/appleMusic/style.css new file mode 100644 index 0000000..64abd8c --- /dev/null +++ b/frontend/src/client/appleMusic/style.css @@ -0,0 +1,16 @@ +/* +* 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; + font-family: sans-serif; +} \ No newline at end of file diff --git a/frontend/src/components/appleMusic.vue b/frontend/src/components/appleMusic.vue deleted file mode 100644 index 46cfd8f..0000000 --- a/frontend/src/components/appleMusic.vue +++ /dev/null @@ -1,45 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/src/components/mediaPool.vue b/frontend/src/components/mediaPool.vue index 38c12f3..6030e81 100644 --- a/frontend/src/components/mediaPool.vue +++ b/frontend/src/components/mediaPool.vue @@ -29,6 +29,7 @@

No songs loaded

+
@@ -379,6 +380,9 @@ this.update( { 'type': 'playback', 'status': false } ); this.$emit( 'com', { 'type': 'pause', 'song': song } ); }, + useAppleMusic() { + fetch( 'http://localhost:8081/useAppleMusic' ); + } } } \ No newline at end of file diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index d36befc..a943e83 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -1,5 +1,5 @@