Is this possible... ?

Posted by Tralfaz on Sun 15 Nov 2020 08:45 PM — 11 posts, 39,408 views.

#0
IF it's possible, I want to have Mushclient import the currently playing artist/album from Foobar2K on Win10 to an &info on ShangrilaMUSH. I know that may not be doable, but I know juuust enough to think it could be. I need advice, if you can help. I'm not a coder, and not finding any preexisting posts that relate.
Thanks.
Australia Forum Administrator #1
I don't know enough about Foobar2K to know if it is doable or not. I doubt it, somehow. You would need to query Foobar2K via some API, which may or may not be possible.
#2
Of the music player progs I've tried, Foobar2K appears to be very much open-source, and configurable. My problem is that I think it may be possible to do what I desire, but I'm not gonna be he who does it. My programming stopped after the early 90's. I've looked at Mushclient helps, and at those for Foobar2K, and those for ShangrilaMUSH. Gave me a headache!

It's just for fun, something to play wif. The helps of all three are overwhelming for this ol' fart.

I've got $100 for anyone that can make it work. Money's easy, neurons are hard. And old. But, life ain't boring! I'm leaving it all on the field.

Seriously, thanks for taking a look at it, you're a good human bean. :) Stay safe, y'all.

-Tralfaz
USA Global Moderator #3
Maybe you can install the https://github.com/hyperblast/beefweb foobar2k plugin to set up an HTTP API for foobar and then query it from MUSHclient using luasocket.
Amended on Mon 16 Nov 2020 04:05 AM by Fiendish
Australia Forum Administrator #4
That sound plausible, in principle. But as the OP isn't a coder someone is going to have to show the technique ...
USA Global Moderator #5
Add this component to foobar2k: https://github.com/hyperblast/beefweb/releases/download/v0.4/foo_beefweb-0.4.fb2k-component

And then in MUSHclient you can do this using Lua:


http = require "socket.http"
require "json"

local page, _, _ = http.request("http://localhost:8880/api/query?player=true&trcolumns=%25artist%25%2C%25album%25%2C%25title%25")
local pagetable = json.decode(page)

local artist, album, track = unpack(pagetable.player.activeItem.columns)
local playback_state = pagetable.player.playbackState

print(artist, album, track, playback_state)


Quote:
I've got $100 for anyone that can make it work

paypal.me/mushclientfiendish :)
Amended on Tue 17 Nov 2020 06:42 AM by Fiendish
Australia Forum Administrator #6
Just to expand on what Fiendish said, I made a plugin that implements that.

You need to download and install this component into Foobar2000.

Then:

Template:saveplugin=Foobar2000_track_playing
To save and install the Foobar2000_track_playing plugin do this:
  1. Copy the code below (in the code box) to the Clipboard
  2. Open a text editor (such as Notepad) and paste the plugin code into it
  3. Save to disk on your PC, preferably in your plugins directory, as Foobar2000_track_playing.xml
    • The "plugins" directory is usually under the "worlds" directory inside where you installed MUSHclient.
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Foobar2000_track_playing.xml (which you just saved in step 3) as a plugin
  7. Click "Close"
  8. Save your world file, so that the plugin loads next time you open it.



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Foobar2000_track_playing"
   author="Nick Gammon"
   id="cd346c228c0e8479480c933d"
   language="Lua"
   purpose="Shows which track you are listening to"
   date_written="2020-11-17 20:58:28"
   requires="5.00"
   version="1.0"
   >
</plugin>

<!--  Timers  -->

<timers>
  <timer name="ShowTrack" 
         script="ShowTrack" 
         enabled="y" 
         second="5.00" >
  </timer>
</timers>

<!--  Script  -->

<script>
<![CDATA[
http = require "socket.http"
require "json"

-- With thanks to Fiendish for suggesting the code below

oldTrack = nil
oldState = nil
playing = nil

function ShowTrack (name)
  local page, _, _ = http.request("http://localhost:8880/api/query?player=true&trcolumns=%25artist%25%2C%25album%25%2C%25title%25")
  
  -- check Foobar2k is running
  if not page and (playing or playing == nil) then
    ColourNote ("orange", "", "Foobar2000 is not running")
    playing = false
  end -- if 

  -- no information? Can't decode it
  if not page then
    return
  end -- if 
  
  -- decode the track information
  local pagetable = json.decode(page)

  local artist, album, track = unpack(pagetable.player.activeItem.columns)
  local playback_state = pagetable.player.playbackState
  
  if playback_state ~= oldState and playback_state == "stopped" then
    ColourNote ("orange", "", "Playback stopped")
    oldState = playback_state
  end -- if
  
  if track and artist then
    playing = true
    if track ~= oldTrack or playback_state ~= oldState then
      ColourNote ("orange", "", string.format ("Now %s %s by %s from %s", playback_state, track, artist, album))
      oldTrack = track
      oldState = playback_state
    end -- if track changed
  else
    playing = false
  end -- if

end -- ShowTrack


]]>
</script>

</muclient>


The plugin connects to Foobar2000 every 5 seconds and checks what track is playing (if any). It then does a ColourNote to put that into your output window. You could change that to send to the MUD, for example:


Send (string.format ("chat Hey everyone! Currently %s %s by %s from %s", playback_state, track, artist, album))
Amended on Tue 17 Nov 2020 10:12 PM by Nick Gammon
USA Global Moderator #7
I'm still waiting to see if they pay the $100. ^_^
Australia Forum Administrator #8
Note that without Foobar2000 running this plugin seems to degrade keyboard input significantly. I suspect that it is attempting to connect to the (local) web server, and hanging for a couple of seconds, then timing out.

Only install the plugin if you are actually planning to use Foobar2000.
USA Global Moderator #9
They can also google "luasocket asynchronous http.request" or something.
USA Global Moderator #10
Still no $100 :(