Giter Site home page Giter Site logo

spotify-playcount's Introduction

ARCHIVED in favor of sp-playcount-librespot. Please use that instead.

Spotify Playcount

Web server API to retrieve play count of all tracks in a Spotify album.

NOTE: Much of how this API works is mainly based on my needs and configuration (though, there is a config file included to make certain changes).

Overall, this hasn't been tested thoroughly and it is very possible that you may need to modify the script in order to fit your needs. Documentation may also be inaccurate or missing information. Submit an issue if you run into any problems.

Requirements

  • Node.js 8+
  • Spotify desktop client for your operating system
  • (Optional) HTTPS Certificate

Installation

  1. To install dependencies:npm install
  2. Ensure configuration in config.json in project directory is correct. (see section below for what each configuration option means)
  3. Important Before launching the API, you must modify your Spotify client in order for it to connect to the main script. This process may need to be done every time the Spotify client updates or you change config.json.
    1. Copy the zlink.spa file from your Spotify installation directory to the project directory. The file is usually located at:
      • Windows: %appdata%\Spotify\Apps\zlink.spa (full path: C:\Users\<username>\AppData\Roaming\Spotify\Apps\zlink.spa)
      • macOS: /Applications/Spotify.app/Contents/Resources/Apps/zlink.spa
      • Linux: The location of this file can vary depending on your distro. Check your package manager to possibly find more info. On my Arch Linux machine, it was located at /opt/spotify/Apps/zlink.spa. (In the Spotify install directory, it's always located at Apps/zlink.spa)
    2. Run in the root of the project directory: node spotify_zlink.js
    3. If the command was successful, copy the file back to the directory where you copied zlink.spa from (it is recommended to make a backup of the old zlink.spa file in case something goes wrong)
  4. Important You must launch Spotify with the following arguments: spotify --ignore-certificate-errors --allow-running-insecure-content
  5. Run the server: node index.js
  6. In the Spotify client, open any album/single page. If everything went well, Spotify should connect to the server and accept requests.
    • If the album page shows an exclamation mark, check your launch arguments for Spotify and your config

Configuration

The server can be configured in the config.json file.

Option Description Data type
port Port on which the web and WebSocket server binds to (TODO: make these separate variables, as this can cause problems and security issues) Integer
useSecure If true, enables https:// and wss:// Boolean
cert Location of https certificate file String
key Location of https private key file String
chain Location of https chain file String
endpoint Endpoint at which the user can send HTTP GET requests to the API String
ipAddress IP Address (preferably a LAN address) at which the Spotify client connects to. This is mainly useful if the web server and the Spotify client are on two different machines. String

Usage

Simply make a GET request to the endpoint with the query string "albumid" set to the ID of a Spotify album (ex. if the URL is https://open.spotify.com/album/30X5rD2J07BzYmd3CKzZTa or spotify:album:30X5rD2J07BzYmd3CKzZTa, the string is 30X5rD2J07BzYmd3CKzZTa)

Curl example: (endpoint is /api/albumPlayCount)

$ curl https://example.com/api/albumPlayCount?albumid=30X5rD2J07BzYmd3CKzZTa
{"success":true,"data":[{"name":"All My Friends","playcount":1608305,"disc":1,"number":1,"uri":"spotify:track:7sGTH1fber0bhncNMfNxmt"}]}

Public API

I am currently hosting this API to the public: https://t4ils.dev:4433/api/beta/albumPlayCount

If the public API is not working correctly, please report it here.

Unfortunately, due to an overwhelming amount of requests and lack of proper hardware to keep the API up, I have to shut down the public API indefinitely.

spotify-playcount's People

Contributors

entriphy avatar slapheadted 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spotify-playcount's Issues

Public API is down

Error: WebSocket is not open: readyState 3 (CLOSED)
    at WebSocket.send (/home/evilarceus/dev/Spotify-PlayCount/node_modules/ws/lib/websocket.js:329:19)
    at WebSocket.ws.json (/home/evilarceus/dev/Spotify-PlayCount/app.js:83:42)
    at app.get (/home/evilarceus/dev/Spotify-PlayCount/app.js:47:12)
    at Layer.handle [as handle_request] (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/layer.js:95:5)
    at /home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/index.js:335:12)
    at next (/home/evilarceus/dev/Spotify-PlayCount/node_modules/express/lib/router/index.js:275:10)

Spotify client not found.

I followed the steps exactly in the README to in order to be able to pull play counts from Spotify (the publicly hosted API works, I'm simply trying to get it to work on my own machine). After completing every single step carefully, (including replacing .spa file, running zlink script ect.) and then running Spotify using the command given in the README (with the appropriate args e.g. "--allow-running-insecure-content" ect.) I get a "Spotify client could not be found" error when trying to make a request to the endpoint which I have specified in the config.json (which looks like this btw):
{ "port": 8080, "useSecure": false, "secure": { "cert": "", "key": "", "chain": "'" }, "http": { "endpoint": "/albums" }, "websocket": { "ipAddress": "127.0.0.1" } }

I'm using index.js to start the simple node server so obviously https isn't necessary, so I left properties blank in "secure".

The URL I was trying to make a GET request to was: http://127.0.0.1:8080/albums?albumid=49K82qcZN4u109e6Zw8io1. I tried other forms of this url to no avail.

Also, when I use the command spotify --ignore-certificate-errors --allow-running-insecure-content it loads the Spotify app normally but I immediately get a Mac notification saying "Session: Spotify (sleep) just terminated" and my terminal shuts down.

Do you have any advice or tips in order to get this to work for myself on my own machine? Since your publicly hosted API works I imagine it may just be something I'm doing wrong. Let me know if more information is needed in order to get to a solution.

Thanks.

Public API Status

Im not sure if Spotify changed anything, but for some reason the public api just isnt working rn

Hosting Instructions

I'd like to host this on my own service, but am not sure how to do this properly. I may not be alone, and think it would be beneficial to have some documentation around how you setup your service.

Love the project by the way, glad you saw a problem and took the initiative of solving it!

No messages sent from Spotify client to server

Environment

  • macOS Mojave 10.14.5
  • Chrome 80.0.3987.87 (Official Build) (64-bit)
  • node 10.16.0
  • Mac Spotify Desktop App 1.1.26.501.gbe11e53b

Reproduction Steps

  • Follow setup to modify zlink.spa, boot up node server, and launch Spotify Desktop app with relevant flags
  • Verify the node process boots the server
  • Verify the Spotify Desktop app connects to the server via websocket
  • You should see the following:
$ node index.js 
http and ws server listening on port 8080!
o_> quack (client connected)
  • At this point we are all good, set up is correct.
  • Navigate to an album in Spotify Desktop app.
  • Make request to server for playcounts for an album.

Actual behaviour: Request hangs...no response from server.
Expected behaviour: Response is sent from server (with playcounts).

Solution

I fixed this locally by changing the variable a -> i in this line. I'm pretty sure that this would be a blocking issue for anyone, at least on Mac, and I strongly suspect Windows + Linux too (I can't see why a variable would be named differently between platforms).

It's difficult to tell by the long line but the change is this:

a.default.resolver.get(uri,(e,t)=>{ -> i.default.resolver.get(uri,(e,t)=>{

Also, I'd open a PR but I don't think I have permissions to push a branch to this repo. PR here #10

P.S.

How the hell do people debug the Spotify App? I see there are console.logs in this repo's code that could only be run on the Spotify App...how do you even see those? My understanding is that Dev Tools used to be available in previous versions of Spotify but that must be a long time ago.

Procedure for Dummies.

I am trying to run the script from my terminal and I am stuck and cannot understand the following things ( i probably don't understand them because of my lack of knowledge, so if you have articles, books, or talks that can help me you are welcome )

IP and SERVER

  • Primarly, port and the IP address have to be related to the WIFI I am connected to ?
  • Secondly, if I want to make it part of a bigger project. How would you interface a system in order to ask the playCount from a Front-END application to a server (you created one but i would like it to be private( since it would be more safe and reliable).

OPEN SPOTIFY.app

  • "spotify --ignore-certificate-errors --allow-running-insecure-content" typing this from the terminal in my Application Folder gives me "command not found".
    How is it possible ? Do I type it in the right place ?

  • ENDPOINTs
    What endopoint should i put in the config.json ?
    On [https://github.com//issues/2] I saw that trjuntunen did :
    { "endpoint": "/albums" }
    should I do like him ?
    -This one is linked to the first question : in an eutopic scenary how would you ask from the front-end the album play count ?

I know It is a lot of stuff and maybe it is not correct. but it will help a lot with approaching this script, which is by the way excellent and essential if you want to do any data analysis on the music out there

Code description

Hello guys,
I was trying to read the code but I didn't can't understand how it works.
Does it work passing a call to spotify through their own desktop app?
Is this method app-based?
How did you write this code?I think lots of people would like to know how you did this.
Thanks for your efforts by the way

Wow

This script is really amazing - thanks!

I wonder: is there a way to modify the script to also get the content of an artist/band About-page?

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.