Giter Site home page Giter Site logo

hankhank10 / vinylemulator Goto Github PK

View Code? Open in Web Editor NEW
166.0 13.0 28.0 54 KB

Emulate the tactile experience of a vinyl collection through your Sonos system, but with a back end run by Spotify

Home Page: https://www.hackster.io/mark-hank/sonos-spotify-vinyl-emulator-3be63d

License: GNU General Public License v3.0

Python 100.00%
sonos spotify node-spotify-api raspberry pi python nfc

vinylemulator's Introduction

vinylemulator

Emulate the tactile experience of a vinyl collection through your Sonos system, but with a back end run by Spotify.

There is a step-by-step tutorial on how to set this up from first principles on a Raspberry Pi here: https://www.hackster.io/mark-hank/sonos-spotify-vinyl-emulator-ssve-3be63d

Update: confirmed works with Sonos S2 released 8 June 2020

Update: this code relies on NFCpy which is incompatible with some newer card readers. You may wish to use Node Sonos NFC rather than this library. This is a Node implementation of this idea - the NFC cards should be compatible between both implementations.

Description

Start playing a Spotify album or playlist through Sonos when you place a physical object on an NFC reader connected to a Raspberry Pi.

You can attach these tiny NFC tags to any physical object you want: I like polaroid-style prints of album covers and tape cassettes for playlists/mixtapes, but you do you; send me a photo if you're baller enough to print album art on 12-inch square aluminium plates and tag it to that.

Background

Originally forked from musicbox project which was itself a fork from songblocks project. I have rewritten and simplified this a lot, however, so this version looks very different to those two.

All the actual back end work of this is done by the node-sonos-http-api which will need to be installed and set up in order to work.

This is not the first project to link NFC to Sonos / Spotify, but I couldn't find one that did both in the way I wanted. Unlike other projects of this type - which take a NFC tag id and cross reference that against a database on the Raspberry Pi to find the music URI - this project actually stores the album details directly on the NFC tag. This has a few advantages:

First, you can have a very large collection which will continue to exist independent of digital storage on the Raspberry Pi. Even if you manage to wipe the database on your Pi, your collection will live forever (just like real vinyl);

Second, these NFC tags aren't tied to the particular Raspberry Pi. This means that the tags are portable to other Raspberry Pis running the same scripts. So take your favourite jazz album from your city pad up to the country house to listen to in the study when it's Laphroig time, or take a rare deep cut you've stumbled across to a friend's house for a listening party. Other use cases are available for those who aren't millionaires.

It also means that other applications can read the tags - I am working on an implementation for Android phones which don't rely on Pi for the NFC, for instance.

It's all coded in Python. Kind of.

Usage

This currently accesses three any of three different services depending on the content of the NFC tag presented. The relevant service is determined by the start of the text passed by the NFC tag.

Service name Behaviour
spotify: Plays a spotify album, track or playlist URI
tunein: Plays a radio station identified by a tunein ID number
bbcsounds: Plays a BBC radio station identified by stream name as detailed in node-sonos-http-api readme
apple: Plays a Apple Music album, track or playlist URI
amazonmusic: Plays a Amazon Music album, track or playlist URI
room: Changes the room in which the script plays
command: Executes a command in the current room; can accept any command as defined in node-sonos-http-api
favorite: Plays a Sonos favorite identified by its name

Examples of what can be passed:

      spotify:track:4LI1ykYGFCcXPWkrpcU7hn
      spotify:album:4hW2wvP51Myt7UIVTgSp4f
      spotify:user:spotify:playlist:32O0SSXDNWDrMievPkV0Im

      tunein/play/44491
      
      favourite/BBC_Radio_2

      bbcsounds:bbc_radio_two

      command:playpause
      command:mute
      command:next
      command:volume/50
      command:volume/+10
      command:shuffle/on

Setup instructions

I made a full tutorial, starting from absolute first principles, here: https://www.hackster.io/mark-hank/sonos-spotify-vinyl-emulator-ssve-3be63d

Important note

Since developing this code in early 2020 it's become apparent that a number of the newer ACR122U NFC readers (which is what I recommended for this project) are not compatible with NFCpy, which is the library that my Python code uses.

Even worse, there seems to be no way to know whether the ACR122U reader you are going to get will work or not... which is annoying.

Luckily ryanolf has created a new library which is compatible with the newer readers and is available here: https://github.com/ryanolf/node-sonos-nfc

Anonymous stats

This is set up to send anonymous usage stats for the purposes of debugging. All that is stored is an anonymised uuid generated by your Raspberry Pi (so not linked to you at all), a log when the app starts, the NFC payload received and how the app interprets this. You can turn this off by changing the relevant setting in usersettings.py to anything except "yes"

vinylemulator's People

Contributors

ashenshugarret avatar esamanoaz avatar hankhank10 avatar secureuplink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vinylemulator's Issues

NFC reader will not connect

For some reason I have an NFC connection issue.

PM2 status shows readnfc as connected, I've stopped the service and restarted although same problem exists.

pi@raspberrypi:~ $ python -m nfc
This is the 1.0.3 version of nfcpy run in Python 2.7.16
on Linux-5.4.51-v7+-armv7l-with-debian-10.4
I'm now searching your system for contactless devices
** found ACS ACR122U PN532v1.6 at usb:001:003
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs

Which seems good although:-

pi@raspberrypi:~ $ python vinylemulator/readnfc.py

Loading and checking readnfc


SCRIPT
You are running version Alpha 0.9.2...
... and latest version is Alpha 0.9.2
Your script is up to date

NFC READER
Connecting to NFC reader...
... could not connect to reader

----------------------------------------------------------
I actually have an identical NFC reader which I use on my PC, I've attached this and this doesn't work either

I'm really stuck, hope someone can help here

500 error from terminal, but 200 from browser

I'm hitting the endpoint on my raspberry pi with python trying to play a song in the living room with the following:

r = requests.get('http://localhost:5005/Living%20Room/applemusic/now/album:370090822')

When running in terminal I get a 500 {"status":"error"}

However when I copy the exact url and paste it into a browser it works and I get {"status":"success"}

I am still relatively new to python so I'm hoping I didn't overlook something obvious. But any clarification on why this would be happening would be much appreciated.

Everything works with Sony NFC reader, but albums all play shuffled?

Followed the guide as best I could get everything working (I had an incompatible Yosoo reader that was fixed by using a Sony) and tapping the reader with a tag gets music to play, but each time I tap, it plays a different song from the album.

Spotify doesn't appear to be in "shuffle" mode and same thing for Sonos, as far as I can tell. What things should I check to ensure proper playback?

Issue with Sonos queue and Apple Music

Hi Mark,

This is a great build and a perfect writeup, I was done in almost 60 minutes...
Now I am having an issue (or several) with the way the script calls the Sonos queue when using Apple Music.
If the queue is empty, everything runs as intended. Fill queue and start with track 1.
If the same album already runs, it will restart with track 2. It should restart with track 1.
If a playlist already runs in random, the script will correctly empty the queue and fill it with the album on the chip, but will keep the random setting and start with any track.
Is there any chance you can change this behaviour?

Thanks
Marius

Issue re recognition of Spotify Account

I have now got everything installed. All seemed fine up to the vinyl emulator step. Until then, I was able to play albums suing the local host :5005 site and the Spotify file format. Now that I have completed all steps, using either the :5005 site or the NFC cards, I get a message in the Sonos app that I need to upgrade Spotify account to full subscriber, even though I am on a full premium Account as a paid (not trial) subscriber.

Any thoughts?

David T

Trouble running vinylemulator

I am running into an issue around step 13. I have the Sony RC-S380 card reader. It was found by the pi and it worked when I tested vinylemulator. When I closed the terminal and did step 14, my NFC chips would not work. So, I did the logical thing and completely started over. There had been a few trial and error moments during the initial setup, so I thought doing a fresh install might fix the problem. It did not. On my second attempt, I am getting an error on step 13 when I test vinylemulator. When I type python vinylemulator/readnfc.py, this is the error I get:

Loading and checking readnfc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SCRIPT
You are running version Alpha 0.9.2...
Traceback (most recent call last):
  File "vinylemulator/readnfc.py", line 136, in <module>
    if r.status_code != 200:
NameError: name 'r' is not defined

Mark, I made sure that "requests" was installed, and the requirements were already satisfied. I then made sure the Python library could communicate with my NFC reader, python -m nfc and I got no error messages.

This is the 1.0.3 version of nfcpy run in Python 2.7.16
on Linux-5.4.51-v7l+-armv7l-with-debian-10.4
I'm now searching your system for contactless devices
** found SONY RC-S380/S NFC Port-100 v1.11 at usb:001:009
I'm not trying serial devices because you haven't told me
-- add the option '--search-tty' to have me looking
-- but beware that this may break other serial devs

I tried to load vinylemulator again and I got the same error message as before. What next?

Node.js v10.21.0 not supported by NPM

Just trying to setup your project, and I have errored out on the NPM Node.js install, with the Pi telling me that "npm does not support the current version of Node.js, v.10.21.0". "Supported releases of Node.js are 4, 6, 7, 8 and 9".

Any suggestions?

help

not a good start { fell at the 1st hurdle } i have not got the option to download Rasbian can you help

Cannot get any spotify to work.

Hi,

I've installed by following each step and every thing is working until I get to the point of playing on Spotify.
it doesn't matter if its a album or playlist all I get is a status error.
I have no problem with using http://192.x.x.x:5005/Dining%20Room/playpause volume, zone etc.

Its only when I try with Spotify eg http://192.x.x.x:5005/Dining%20Room/spotify:user:spotify:playlist:5huIma0YU4iusLcT2reVEU
or http://192.168.1.4:5005/Dining%20Room/spotify:user:spotify:album:0PMasrHdpaoIRuHuhHp72O

I've tried numerous albums and playlist but same outcome.

Regards

G smith

NFC Reader Won’t Power On

I decided to give this project a try, purchased all the necessary hardware, went through the tutorial step by step with almost no issues at all until I got to the part where I had to plug the NFC reader into the pi. I decided to this on the Raspberry Pi 2 B+ as it was the only pi I had that wasn’t being used. I swapped out psu to one that can handle up to 5v 3.5A and it still didn’t work. I even swapped the pi to a pi 3 I am using on another project and still won’t work. I am out of ideas and am hoping someone can help me out. Thanks for this awesome project, hopefully I can get it to work soon.

Support for RC522

I have installed an RC522as an RFID reader/writer, but I don't know what device path to use. It doesn't show up using lsusb. What should I do?

Unable to get vinylemulator to run on boot

Hi - I've been trying out your project on RaspPi 4, and love the idea; I am however running into a small problem:

I've gotten as far as having the Spotify server run automatically on boot, but haven't been able to set the readnfc.py script to do the same. I can get Spotify to run as per step 9 , but when it comes to using pm2 to set the vinylemulator script to autoboot, I get this:

┌─────┬────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name       │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ npm        │ default     │ N/A     │ fork    │ 857      │ 14m    │ 0    │ online    │ 0%       │ 44.8mb   │ pi       │ disabled │
│ 2   │ readnfc    │ default     │ N/A     │ fork    │ 1089     │ 0      │ 1    │ errored   │ 0%       │ 0b       │ pi       │ disabled │
└─────┴────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
pi@raspberrypi:~ $ 

I can use pm2 start vinylemulator/readnfc.py to put it online, but if I reboot, I frequently get "stopped" show against this job! Any ideas as to how I can get around this please? The reader I'm using is an NFC ACR122 unit.

I'm using python3 to run - it meant updating some of the commands listed in the tutorial, but otherwise it seems to run OK. If I run the readnfc.py script manually, it works OK - I do have to unplug the reader and plug it back in again though, before the reader decides to recognise my card :-)

Issue while reading

It used to work great but suddenly it stopped working. I checked everything is installed properly and the reader is working. However, when I try to run the command to test the read function I get this error back:

pi@raspberrypi:~ $ python vinylemulator/readnfc.py


Loading and checking readnfc
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SCRIPT
You are running version Alpha 0.9.2...
Traceback (most recent call last):
  File "vinylemulator/readnfc.py", line 116, in <module>
    if r.status_code != 200:
NameError: name 'r' is not defined

Request: Pause when NFC Tag is removed

Hi Mark,

i have added a new function "release" that is called when the NFC Tag is released from the reader. This way i wanted to pause playback when the tag is removed.
I am having trouble calling the on-release function from the reader it seems, as i cannot get it to work.

Would you be able to help?

Thanks
Marius

Autostop possible?

Hi,
awesome project! I made it with a raspberry pi Zero 2 and it works like a charm. I have done it for my son and it would be great if something like an „album“ starts when the nfc tag is recognized and stops automatically if the tag is removed. Like a Tonie Box. Would this be possible?

thanks

Spotify “end session” command through Sonos api?

I’m wondering if you can help with an issue I’m running into:

When I have a queue setup from the Sonos app the emulator works fine, but when I start a song from the Spotify app it doesn’t work and I have to go into the Sonos app and press “end session” before the emulator can work.

I can’t see on the Sonos api a command for end session, and clearqueue doesn’t seem to work - do you know if such a command exists? Or how I can watch the api command line when I press a button in the app to see what it tells the system to do?

Thanks,
Ben

Mifare Classic support

Hi,

I set up everything without problems but when I tried to read my cards I recognized that Mifare Classic cards are not supported. Why not? I have plenty of them lying around (used for other projects as well). What's the problem with these cards?

Thx,
Marco

Spotify songs not queueing or playing

Hi all,
I am working through this project and really looking forward to finalising it. Thanks Mark, this is a great project. However...
I have my Pi (Raspberry Pi OS Kernel 5.4 - release 2020-08-20) set up and running Node.js and NPM as well as the node-sonos-http-api package and pm2 to run on startup.
The following works as expected:
http://192.168.1.27:5005/
http://192.168.1.27:5005/zones
http://192.168.1.27:5005/Rumpus%20Room/playpause

However when I try to play something it does not hit the queue or play... e.g.
http://192.168.1.27:5005/Rumpus%20Room/spotify/open.spotify.com/track/78lgmZwycJ3nzsdgmPPGNx
Output: {"status":"success"} (its Led Zepplin - for all us oldies)

If I run the "Zones" request again it does not show up as queued and does not play.
Any help / ideas would be greatly appreciated.

Thanks

Podcasts

Hey, is there any chance you could add a podcast feature? When I wake up, I really like to listen to podcasts. the spotify uri is very simple
spotify:show:(podcast ID).
Thanks

500 error when retrieving albums

I have been running your wonderful program for a few years no with no issues. Suddenly my NFC tags have stopped calling up Spotify music. The Sonos API seems to be OK when I access http://myPi_IPAddress:5005/ Also, I can control Spotify on my Sonos with the http://myPi_IPAddress:5005/playpause command.

However, if I try playing an album on a windows machine with a web browser, for example: http://myPi_IPAddress:5005/Lounge/spotify/now/spotify:album:12n11cgnpjXKLeqrnIERoS as in your John Grant example, I receive this error:
{"status":"error","error":"Got status 500 when invoking /MediaRenderer/AVTransport/Control","stack":"Error: Got status 500 when invoking /MediaRenderer/AVTransport/Control\n at Object.invoke (/home/pi/node-sonos-http-api/node_modules/sonos-discovery/lib/helpers/soap.js:99:10)\n at Player.addURIToQueue (/home/pi/node-sonos-http-api/node_modules/sonos-discovery/lib/models/Player.js:616:15)\n at promise.then (/home/pi/node-sonos-http-api/lib/actions/spotify.js:37:33)"}

Any thoughts as to what may be happening? By the way, I am still running "Buster" on this Pi.
Thanks, David T

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.