Skip to content

Commit

Permalink
add squeezebox module
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeraci committed May 31, 2016
1 parent ffac0bd commit 557a1da
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions auto-hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def mta_service_status():
r = requests.get(C['subwayRemoteUrl'])
return Response(r.text, mimetype='text/xml')

@app.route('/song')
def song():
r = requests.get(C['songRemoteUrl'])
return Response(r.text, mimetype='text/html')

@app.route('/birthdays')
def birthdays():
today = datetime.today()
Expand Down
5 changes: 5 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'chores',
'birdPodcasts',
'subway',
'song',
'noConnection',
],

Expand All @@ -29,6 +30,10 @@
'subwayUrl': '/mta-service-status',
'subwayRemoteUrl': 'http://web.mta.info/status/serviceStatus.txt',

'songPollTime': 1000 * 10,
'songUrl': '/song',
'songRemoteUrl': 'http://192.168.1.111:9000/status.html',

# indicate which subway lines you wish to display with a `1`
'subwayLinesToShow': {
'7': 0,
Expand Down
30 changes: 30 additions & 0 deletions static/js/AutoHUDController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,34 @@ window.AutoHUDController = {
""")

return res.join("")


# currenty playing song
#############################################################################

songGetter: ->
$.get(C.songUrl, (data) =>
if !data?
@model.set({song: null})
return

@formatSong(data)
)

formatSong: (data) ->
data = $.parseHTML(data)
html = $("<div></div>").append(data)
playingStatus = html.find("#playingStatus").text().toLowerCase()
isPlaying = playingStatus.indexOf("playing") >= 0

if isPlaying
song = html.find(".playingSong").text()
.replace("(Delete)", "")
.replace(/[\n\r\t]/g, "")
.replace(/\s+/g, " ")
.trim()

@model.set({song: song})
else
@model.set({song: null})
}
30 changes: 30 additions & 0 deletions static/js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,36 @@ window.AutoHUDController = {
res.push("<span class=\"hud-section-subway-line\">" + line + "</span>");
}
return res.join("");
},
songGetter: function() {
return $.get(C.songUrl, (function(_this) {
return function(data) {
if (data == null) {
_this.model.set({
song: null
});
return;
}
return _this.formatSong(data);
};
})(this));
},
formatSong: function(data) {
var html, isPlaying, playingStatus, song;
data = $.parseHTML(data);
html = $("<div></div>").append(data);
playingStatus = html.find("#playingStatus").text().toLowerCase();
isPlaying = playingStatus.indexOf("playing") >= 0;
if (isPlaying) {
song = html.find(".playingSong").text().replace("(Delete)", "").replace(/[\n\r\t]/g, "").replace(/\s+/g, " ").trim();
return this.model.set({
song: song
});
} else {
return this.model.set({
song: null
});
}
}
};

Expand Down
9 changes: 9 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ <h2>
<% } %>
</script>

<script id="song-template" type="text/template">
<% if (d.song) { %>
<div class="hud-section hud-section-song">
<%= d.song %>
<span class="fa fa-music"></span>
</div>
<% } %>
</script>

<script id="noConnection-template" type="text/template">
<% if (d.noConnection) { %>
<div class="hud-section hud-section-no-connection">
Expand Down

0 comments on commit 557a1da

Please sign in to comment.