Last active
December 16, 2017 09:42
-
-
Save atchoo78/697747ce21495fa0d67ba15c54635a01 to your computer and use it in GitHub Desktop.
Display current iTunes Track on LED display (max7219 or compatible Dot Matrix LED) connected to Raspberry PI/Arduino.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#!/usr/bin/env python | |
# server side script for Raspberry PI | |
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
import re | |
import argparse | |
import time | |
# Luma.LED_Matrix drivers & library is © 2017 Richard Hull | |
# https://luma-led-matrix.readthedocs.io/en/latest/index.html | |
# https://github.com/rm-hull/luma.led_matrix | |
from luma.core.interface.serial import spi, noop | |
from luma.core.render import canvas | |
from luma.led_matrix.device import max7219 | |
from luma.core.virtual import viewport | |
from luma.core.legacy import text, show_message | |
from luma.core.legacy.font import proportional, LCD_FONT | |
serial = spi(port=0, device=0, gpio=noop()) | |
# Details regarding the block_orientation and cascaded options: | |
# https://luma-led-matrix.readthedocs.io/en/latest/python-usage.html#daisy-chaining | |
device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0) | |
class S(BaseHTTPRequestHandler): | |
def _set_headers(self): | |
self.send_response(200) | |
self.send_header('Content-type', 'text/html') | |
self.end_headers() | |
def do_POST(self): | |
content_length = int(self.headers['Content-Length']) | |
post_data = self.rfile.read(content_length) | |
self._set_headers() | |
show_message(device, post_data, fill="white", font=proportional(LCD_FONT)) | |
def run(server_class=HTTPServer, handler_class=S, port=8181): | |
server_address = ('', port) | |
httpd = server_class(server_address, handler_class) | |
print 'Starting LED Alert...' | |
httpd.serve_forever() | |
if __name__ == "__main__": | |
from sys import argv | |
if len(argv) == 2: | |
run(port=int(argv[1])) | |
else: | |
run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
#!/usr/bin/env python | |
# run this on your Mac | |
import Foundation | |
from AppKit import * | |
from PyObjCTools import AppHelper | |
import requests | |
LED_URL = "http://raspberrypi.local:8181" | |
class GetSongs(NSObject): | |
def getMySongs_(self, song): | |
song_details = {} | |
ui = song.userInfo() | |
song_details = dict(zip(ui.keys(), ui.values())) | |
playerState = (song_details['Player State']) | |
if not('Stopped' in playerState): | |
nowPlaying = song_details['Artist'] + ' : ' + song_details['Name'] | |
else: | |
return | |
if('Playing' in playerState): | |
r = requests.post(url = LED_URL, data = nowPlaying.encode('utf-8')) | |
nc = Foundation.NSDistributedNotificationCenter.defaultCenter() | |
GetSongs = GetSongs.new() | |
nc.addObserver_selector_name_object_(GetSongs, 'getMySongs:', 'com.apple.iTunes.playerInfo',None) | |
nc.addObserver_selector_name_object_(GetSongs, 'getMySongs:', 'com.spotify.client.PlaybackStateChanged',None) | |
AppHelper.runConsoleEventLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The result: