Giter VIP home page Giter VIP logo

sp-playcount-librespot's Introduction

sp-playcount-librespot

sp-playcount-librespot is a modification of librespot-java that serves as an enhancement of Spotify-PlayCount.

NOTE: This repository will most likely be archived if I decide to rewrite this in another language.

Disclaimer

This project is to be used for educational purposes only. We (librespot developers, librespot-java developers, and I) do not condone using this tool for commercial purposes. Doing so puts this project at risk and can cause legal issues (the data is property of Spotify, not me). Any attempt or request to pay me for anything related to this project will be denied.

Advantages vs. Spotify-PlayCount

  • Does NOT require the Spotify desktop app (woo)
  • Lower CPU and memory usage
  • More information given in API response
  • Provides endpoint for artist info (monthly listeners, top tracks, follower count, etc)

Requirements

  • Java 8+
  • Spotify Account (recommended to create another account)

Installation

  1. Compile this repository or download an executable JAR.
  2. Run the JAR: java -jar sp-playcount-librespot.jar <spotify_username> <spotify_password>
    • You only need to provide your Spotify username and password once. After creds.json has been generated, the username and password are not required in the launch arguments.
  3. Make any appropriate configuration changes in the generated config.toml file (see "Configuration" section for config options).
  4. Run the JAR again: java -jar sp-playcount-librespot.jar

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/6Lq1lrCfkpxKa4jCo5gKWr or spotify:album:6Lq1lrCfkpxKa4jCo5gKWr, the string is 6Lq1lrCfkpxKa4jCo5gKWr)

Curl example: (endpoint is /albumPlayCount)

$ curl https://example.com/albumPlayCount?albumid=6Lq1lrCfkpxKa4jCo5gKWr
{"success": true, "data": {"uri":"spotify:album:6Lq1lrCfkpxKa4jCo5gKWr","name":"Good Faith","cover":{"uri":"https://i.scdn.co/image/ab67616d00001e02dc384e6d13983fe1cd415ade"},"year":2019,"track_count":10,"discs":[{"number":1 ...

There are also endpoints for retrieving artist info. artistid must be set to the ID of a Spotify artist.

  • /artistInfo?artistid= (monthly listeners, top tracks w/ play count, follower count, albums/singles released by artist, etc)
  • /artistAbout?artistid= (biography, images, social links, etc)
  • /artistInsights?artistid= (monthly listeners, "Discovered On" playlists, cities w/ most listeners, etc)

Compiling (requires Maven)

  1. Clone this repository: git clone https://github.com/evilarceus/sp-playcount-librespot && cd sp-playcount-librespot
  2. Build with Maven: mvn clean package
  3. Run JAR file: java -jar ./core/target/librespot-core-jar-with-dependencies.jar <spotify_username> <spotify_password>

Configuration

A config.toml file is generated after you run the JAR for the first time. This file can be used to change the settings of the server. The settings are located at the very bottom of the file under [server]. To reset the configuration, simply delete the file and run the JAR again.

[server]
port = 8080
albumEndpoint = "/albumPlayCount"
artistEndpoint = "/artistInfo"
artistAboutEndpoint = "/artistAbout"
enableHttps = false
httpsKs = ""
httpsKsPass = ""
Option Description
port Selects what port to listen for HTTP requests on
albumEndpoint Endpoint at which the user can send HTTP GET requests to the API for album info
artistEndpoint Endpoint at which the user can send HTTP GET requests to the API for artist info
artistAboutEndpoint Endpoint at which the user can send HTTP GET requests to the API for an artist's about page
artistInsightsEndpoint Endpoint at which the user can send HTTP GET requests to the API for an artist's insights
enableHttps If true, enables HTTPS support (requires certificate, see section below)
httpsKs Location to keystore with HTTPS certificate and key
httpsKsPass Password to HTTPS keystore file (if applicable)

HTTPS Configuration

The server can be configured to use HTTPS. If you're using LetsEncrypt, use this guide to create a keystore with the certificate.

Then, edit config.toml:

[server]
...
enableHttps = true
httpsKs = "<location of keystore file>"
httpsKsPass = "<keystore password (if applicable)>"

Public API

I am currently hosting this API at https://api.t4ils.dev (endpoints: /albumPlayCount, /artistInfo, /artistAbout). Please use it for educational purposes only (see disclaimer).

If your application previously used Spotify-PlayCount, you will need to update your application to support the new API response.

sp-playcount-librespot's People

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

sp-playcount-librespot's Issues

Unable to get playcounts Error 502

Since today I am unable to get the playcounts for any track. Only getting the folling error:

xyz.gianlu.librespot.mercury.MercuryClient$MercuryException: status: 502
at xyz.gianlu.librespot.mercury.MercuryClient.sendSync(MercuryClient.java:83)
at xyz.gianlu.librespot.handler.PlayCountHandler.handle(PlayCountHandler.java:57)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at jdk.httpserver/sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:82)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:80)
at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:848)
at jdk.httpserver/com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:77)
at jdk.httpserver/sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:817)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

Did something change on Spotify's side?

Where to Host

Hey guys I was planning to host this amazing program on a server.
I thought about Heroku, but I am struggling to deploy and start the program since I cannot find a way to inject the and while running the file.
Has anyone already done it and can help me ? Or suggest another host ?

Thanks in advance

Giovanni

Any plans for python version of this?

I saw there is a javascript version using nodejs, and then a java version. Is there any plans to do a python version as that would be very useful to use. Thanks!

Also, how can I host this API for myself and utilize it from my own server? Doesn't seem that straightforward Thanks!

self hosted this server?

hi, i'm currently using this api.t4ils.dev endpoint, it works fine but sometimes it gets too many request error. i'm assuming you're hosting this on glitch now. is there a tutorial somewhere that i can follow to host it on my own?

Artist Endpoint 'NoneType' error

Getting the following error when hitting the artist endpoint.

An unknown error occurred: 'NoneType' object has no attribute 'get'

Not seeing this error with the album endpoint. Any ideas what this could be?

Artists: Monthly Listeners and Followers

Is your feature request related to a problem? Please describe.
Not a problem per se, but I'd like to be able to retrieve monthly listeners and follower counts for artists.

Describe the solution you'd like
Another endpoint like the album playcounts endpoint e.g. /artist/:id/metadata

Describe alternatives you've considered
Manually doing it in the Spotify Desktop app...slow and manual.

Additional context
I've looked into your "Let's try this out" commit @evilarceus and it looks like we'd probably achieve an Artist MetaData solution by using the MercuryRequest class...I saw an artist-related method in there that seems to get meta data. It might be as simple as creating a new endpoint that uses that method under-the-hood.

How does this work - and api limitations

Hello,

On one of the previous versions of this project, someone requested a description showing how this project works. I don't think you ever posted one, but I would be very interested in learning more about it as well.

Also, what are the approximate limits of the API (both the version you host, and one we host ourselves)? If I wanted to call it thousand times per day, is that possible? What are the constraints? If hosted ourselves, don't we have to use our own Spotify account(s) and if that is the case, are there limits to how many api calls one can make?

Thanks!

Application Error

Was trying to test the api. Getting an Application Error on all calls. Was testing with Postman and keep getting this error "Application Error".

TravelRestriction error

Describe the bug
When I run the program it is giving the following error.

To Reproduce
java -jar sp-playcount-librespot-v1.4.jar user pass

** Error
2020-08-09 01:15:16,328 INFO ApResolver:66 - Loaded aps into pool: {accesspoint=[guc3-accesspoint-b-rf1j.ap.spotify.com:4070, guc3-accesspoint-b-m208.ap.spotify.com:443, guc3-accesspoint-b-fssp.ap.spotify.com:80, guc3-accesspoint-b-70kt.ap.spotify.com:4070, guc3-accesspoint-b-dppf.ap.spotify.com:443, guc3-accesspoint-b-zkw2.ap.spotify.com:80, gae2-accesspoint-c-zk7b.ap.spotify.com:4070, gew1-accesspoint-b-9v0l.ap.spotify.com:443, gew1-accesspoint-b-g7br.ap.spotify.com:80], dealer=[guc-dealer.spotify.com:443, gew-dealer.spotify.com:443, gae-dealer.spotify.com:443], spclient=[guc-spclient.spotify.com:443, gew-spclient.spotify.com:443, gae-spclient.spotify.com:443]}
2020-08-09 01:15:16,563 INFO Session:94 - Created new session! {deviceId: c70f928698cc099e39bddfd469f7de38e3b805db, ap: guc3-accesspoint-b-dppf.ap.spotify.com:443}
2020-08-09 01:15:17,422 INFO Session:223 - Connected successfully!
Exception in thread "main" xyz.gianlu.librespot.core.Session$SpotifyAuthenticationException: TravelRestriction
at xyz.gianlu.librespot.core.Session.authenticatePartial(Session.java:311)
at xyz.gianlu.librespot.core.Session.authenticate(Session.java:231)
at xyz.gianlu.librespot.core.Session$Builder.create(Session.java:583)
at xyz.gianlu.librespot.Main.main(Main.java:18)

Will not Work on Heroku - Bad Credentials

Has anyone been able to fix an issue that as of a few days ago this will not run on Heroku. The error is Bad Credential. Even though credentials log in just fine locally.

Bad Credentials Issue is back

Exception in thread "main" xyz.gianlu.librespot.core.Session$SpotifyAuthenticationException: BadCredentials

Anyone else having this issue?

Issue with getalbum endpoint

The /getalbum endpoint gives this error about half the time I run it -

{"success": false, "data": "Error while querying: Session is closed"}

Is there something I can do to prevent this happening? I've seen a few others with this issue so I think it's a bug with the api but any help would be amazing :)

How to logout?

I know you have to use the username + password when starting the jar. Is there a way to effectively "logout", and use a different credential? Curious about this because I have different playlists on different Spotify accounts. thanks!

/artistInfo endpoint returns 403

Describe the bug
As of today, /artistInfo endpoint started returning 403 Forbidden as API response. It also logs a 403 MercuryException to the console. All other endpoints including /artistInsights work perfectly fine.

To Reproduce
Make a request to /artistInfo endpoint on a running local deployment OR test via the public API at https://api.t4ils.dev/.
For example; Björk :
do a GET to https://api.t4ils.dev/artistInfo?artistid=6TwO05VN5ZM3DYVEsP9vjK
or http://localhost:{{YOUR PORT}}/artistInfo?artistid=6TwO05VN5ZM3DYVEsP9vjK

Expected behavior
The endpoint was working as expected until yesterday and returned also the artist's release info.

Screenshots/Stracktraces/Logs
Error logged to console to a GET request to /artistInfo
2022-09-23 16:43:02,294 TRACE MercuryClient:156 - Send Mercury request, seq: 2, uri: hm://artist/v1/57vWImR43h4CaDao012Ofp/desktop?format=json&locale=en&cat=1, method: GET 2022-09-23 16:43:02,351 TRACE MercuryClient:199 - Handling packet, cmd: MercuryReq, seq: 2, flags: 1, parts: 1 xyz.gianlu.librespot.mercury.MercuryClient$MercuryException: status: 403 at xyz.gianlu.librespot.mercury.MercuryClient.sendSync(MercuryClient.java:106) at dev.t4ils.handler.ArtistInfoHandler.handle(ArtistInfoHandler.java:56) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:713) at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79) at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:750)

Version/Commit
Latest version 1.4.1, by running the compiled script with USER and PASS

The hosted API seems to be down

It seems the hosted API is currently returning errors only. Whatever I try (albums or artists) I get the following result:

{"success": false, "data": An unknown error has occurred; logged to console}

Installation on Ubuntu

I am trying to install playcount on a Ubuntu machine via the command line, but I wasn't able to as my knowledge is limited on linux.

Also could not find any tutorial on how to do it on the internet. Could anyone post here step by step instructions on how to do it from scratch.

I have it running on windows but I wanted to try it on Ubuntu.

I appreciate a lot your help

Artist info stops including track listing after first 8 albums

Describe the bug
When querying the artistInfo endpoint, only the first 8 albums include the list of tracks, after that it stops including them.

To Reproduce

  1. Query https://api.t4ils.dev/artistInfo?artistid=74KM79TiuVKeVCqs8QtB0B
  2. Look through data.releases.albums.releases and data.releases.singles.releases
  3. Notice how the discs attribute disappears starting from the single called "On My Way"

Expected behavior
This info should be included for every track if possible. I'm building a shortcut for iOS and would like to avoid the overhead of calling albumPlayCount individually for each album.

Screenshots/Stracktraces/Logs
N/A

Version/Commit
Whatever the current version on https://api.t4ils.dev is at the time this issue was created.
Version used or commit pulled if compiled locally.

SyntaxError in artistAbout Endpoint

I was just trying to check the different endpoints, and seems that with this link I get this error SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 30 of the JSON data because there are some " outside the {}

This error is given when I try to see the json response with the Mozilla viewer, it does not happen with the other endpoints.

Playcounts Missing - Capped at 8 entries

Playcounts are missing for random tracks.

It seems that a total combination of 8 albums and singles will include playcounts. eg. If the artist has 4 albums .. then those 4 albums will have playcounts in tact... and up to 4 singles will have playcounts.

If the artists has no albums... 8 singles will have playcounts.

Everything after 8 items doesn’t have playcounts.

Trying to figure out if this is a bug in the code or a limit Spotify is controlling.

I could really use some help figuring this out.

Artists: Additional Info

Hello, your code is a lifesaver. Thanks so much!

Is it possible to add Gallery Images and/or Social Media Links to artistInfo?

Playlist Endpoint

If possible, a playlist endpoint with followers and songlist would make this project 100%.

Singles Playcount

Hey, is there a way we can get playcount of singles/tracks which are not a part of album?

If not, can we have an endpoint where we'll pass the song id and it gives playcount and other details of the single in response?

Thanks for this amazing project :)

Can't run the JAR

Hey, so I'm trying to run the 1.4.1. JAR version, but it always returns the same error
Exception in thread "main" java.lang.NullPointerException at com.spotify.Authentication$LoginCredentials$Builder.setUsername(Authentication.java:3732) at xyz.gianlu.librespot.core.Session$Builder.userPass(Session.java:1009) at dev.t4ils.Main.main(Main.java:16) I've tried using the username and the UUID, and even created another account, but I can't see to find the problem

Unable to access jarfile sp-playcount-librespot.jar

Describe the bug
I'm installing sp-playcount-librespot through the .jar file. When running the jar file in the terminal along with my Spotify username and password , I get "Unable to access sp-playcount-librespot.jar".

To Reproduce

  1. Download the .jar file
  2. cd into the directory where this .jar file is stored
  3. Run java -jar sp-playcount-librespot.jar <username> <password>

Expected behavior
According to the installation guide , a config.toml file should be generated.
Screenshots/Stracktraces/Logs

Screenshot

Version/Commit
v1.4 (latest)

[bug] JSON occasionally fails to parse

Stack trace:

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 5 path $
 at com.google.gson.JsonParser.parseReader(JsonParser.java:66)
 at xyz.gianlu.librespot.mercury.JsonMercuryRequest.instantiate(JsonMercuryRequest.java:26)
 at xyz.gianlu.librespot.mercury.MercuryClient.sendSync(MercuryClient.java:82)
 at xyz.gianlu.librespot.HTTPSServer$PlayCountHandler.handle(HTTPSServer.java:88)
 at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
 at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
 at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
 at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
 at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
 at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at java.lang.Thread.run(Thread.java:748)
Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 5 path $
 at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1564)
 at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1405)
 at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:543)
 at com.google.gson.stream.JsonReader.peek(JsonReader.java:426)
 at com.google.gson.JsonParser.parseReader(JsonParser.java:61)
 ... 12 more

Artist Followers

Hello, It says that you can get the followers of the artists, but actually what you get is only the monthly listeners.
Will be the artist followers feature be added in the future ?

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.