Skip to content

Instantly share code, notes, and snippets.

@jayemko
Forked from tobru/README.md
Last active August 8, 2017 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayemko/7ffbfdeb7345d72554287f83eba4495c to your computer and use it in GitHub Desktop.
Save jayemko/7ffbfdeb7345d72554287f83eba4495c to your computer and use it in GitHub Desktop.
A dashing widget which displays the currently playing song on a squeezebox player.

Logitech Squeezebox Now Playing

Preview

Screenshot: Squeezebox Widget in action

Description

Squeezebox Now Playing is a a Dashing widget which displays now playing information from a Logitech Squeezebox player.

Usage

  • Install this fork of the widget using dashing install 7ffbfdeb7345d72554287f83eba4495c

    • or do it manually:

      • Copy squeezebox.rb to the /jobs directory.
      • Create a folder called squeezebox under /widgets.
      • Copy squeezebox.coffee, squeezebox.html and squeezebox.scss into /widgets/squeezebox.
  • Add the following code snippet to your dashboard .erb file:

     <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
        <div data-id="now-playing" data-view="Squeezebox" data-title="Squeezebox"></div>
     </li>
    

Settings

Add LMS_URL and SB_PLAYER_ID to your environment variables

  • LMS_URL: URL to your Squeebox Server (also known as Logitech Media Server). f.e.: http://myhomeserver:9000

  • SB_PLAYER_ID: ID of the player, can be the IP address or the MAC address. This information can be found on the webinterface under "Settings".

  • Example:

     export LMS_URL='http://myhomeserver:9000'
     export SB_PLAYER_ID='a1:b2:c3:d4:e5:f6'
    
class Dashing.Squeezebox extends Dashing.Widget
ready: ->
# This is fired when the widget is done being rendered
onData: (data) ->
# Handle incoming data
# You can access the html node of this widget with `@node`
# Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
<div class="player-name" data-bind="player_name"></div>
<div class="cover-image-holder">
<img class="cover-image" data-bind-src="artwork_url" />
</div>
<div class="title" data-bind="title"></div>
<div class="artist" data-bind="artist"></div>
<span class="icon-background fa fa-music"></span>
require 'json'
require 'net/http'
require 'uri'
LMS_URL = ENV['LMS_URL']
SB_PLAYER_ID = ENV['SB_PLAYER_ID']
def slim_request(params)
form_data = { 'id' => 1,
'method' => 'slim.request',
'params' => params,
}
uri = URI.parse(LMS_URL + '/jsonrpc.js')
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.body = form_data.to_json
response = JSON.parse(http.request(request).body)
return response['result']
end
def send_to_widget(artist, artwork_url, current_title, player_name, status, title)
send_event 'now-playing', { artist: artist,
artwork_url: artwork_url,
current_title: current_title,
player_name: player_name,
status:status,
title: title }
end
SCHEDULER.every '5s', allow_overlapping: false, :first_in => 0 do
player_status = [ SB_PLAYER_ID, [ 'status', '-', 1, 'tags:cgABbehldiqtyrSuoKLNJ' ] ]
begin
data = slim_request(player_status)
player_name = data['player_name']
status = data['mode']
if data['player_connected'] == 1
case status
when 'play','pause'
artist = data['playlist_loop'][0]['artist'].gsub(/([\w\s]{30}).+/,'\1...')
album_art = data['playlist_loop'][0]['artwork_url']
current_title = data['current_title'].gsub(/([\w\s]{30}).+/,'\1...')
if data['playlist_loop'][0].has_key?('title')
title = data['playlist_loop'][0]['title'].gsub(/([\w\s]{30}).+/,'\1...')
else
title = data['playlist_loop'][0]['album'].gsub(/([\w\s]{30}).+/,'\1...')
end
send_to_widget(artist, album_art, current_title, player_name, status, title)
when 'stop'
send_to_widget('', LMS_URL + '/imageproxy/stopped', '', player_name, 'stopped', '')
else
end
else
# player is not connected
send_to_widget('', LMS_URL + '/imageproxy/disconnected', '', player_name, 'squeezebox is disconnected', '')
end
rescue
puts "[ERROR] Squeezebox widget broke!"
end
end
.widget-squeezebox {
background: #333;
.player-name {
font-size: 0.8em;
margin-bottom: 0.4em;
}
.title {
font-size:1em;
}
.artist {
font-size:0.8em;
}
.cover-image {
width: 60%;
height: 60%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment