summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--nowplaying/package.json5
-rwxr-xr-xnowplaying/playing.js72
3 files changed, 79 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 278ae50..7fa114b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
icons/NineIcons/Iconfactory
config/openbox/rc.xml
+nowplaying/node_modules
+nowplaying/package-lock.json
diff --git a/nowplaying/package.json b/nowplaying/package.json
new file mode 100644
index 0000000..37c3082
--- /dev/null
+++ b/nowplaying/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "ws": "^8.18.0"
+ }
+}
diff --git a/nowplaying/playing.js b/nowplaying/playing.js
new file mode 100755
index 0000000..3f334eb
--- /dev/null
+++ b/nowplaying/playing.js
@@ -0,0 +1,72 @@
+#!/usr/bin/node
+
+const WebSocket = require( "ws" );
+
+process.on( "uncaughtException", () => {
+ console.log();
+} );
+
+process.on( "unhandledRejection", () => {
+ console.log();
+} );
+
+let ws = null;
+let idc = 1;
+const setupws = () => {
+ try {
+ ws = new WebSocket( "ws://localhost:7905" );
+ } catch( e ) {
+
+ }
+ ws.onopen = () => {
+ const obj = {
+ name: "authenticate",
+ type: "request",
+ id: `msg-${idc++}`,
+ options: {
+ password: "1234"
+ }
+ }
+
+ ws.send( JSON.stringify( obj ) );
+ }
+ ws.onmessage = ( e ) => {
+ const parsed = JSON.parse( e.data );
+ if( parsed.name == "authenticate" )
+ return sendreq();
+
+ const title = parsed.options.playing_track.title;
+ let ret = ""
+ if( parsed.options.state != 'playing' )
+ ret = '(⏸) ';
+
+ const homedir = require( "os" ).homedir();
+ if( title.startsWith( homedir ) ) {
+ const path = title.substring( homedir.length + 1 );
+ const file = path.split( "/" ).pop();
+ ret += file;
+ }
+ else ret += title;
+ if( ret.length > 30 )
+ ret = ret.substring( 0, 30 ) + "...";
+ console.log( ret );
+ ws.close();
+ };
+}
+
+const sendreq = () => {
+ const obj = {
+ name: "get_playback_overview",
+ type: "request",
+ id: `msg-${idc++}`,
+ options: {
+ password: "1234"
+ }
+ }
+
+ ws.send( JSON.stringify( obj ) );
+}
+
+try {
+ setupws();
+} catch ( e ) {}