w0rd-driven / beatseek

Seek the music you may be missing by analyzing your collection
https://beatseek.fly.dev/
MIT License
3 stars 0 forks source link

API `Verification.Spotify` module from prototype #4

Closed w0rd-driven closed 1 year ago

w0rd-driven commented 1 year ago

There's likely a better name for this but it likely involves wiring up SpotifyEx and making the appropriate calls.

Upserts should capture new records but it may be safer to do queries to filter out existing albums. I could do something like "Get all album names for this artist. Enum.filter where name NOT in list."

w0rd-driven commented 1 year ago

A new issue should add a migration for a spotify_id as we likely don't need to get the artist id every call. I don't know if this changes though but I do know picking the artist can be problematic.

w0rd-driven commented 1 year ago

Debugging the library and how I authenticate with each request (this is fine but definitely overkill):

** (MatchError) no match of right hand side value: {:ok, %{"error" => %{"message" => "Only valid bearer authentication supported", "status" => 400}}}
    (beatseek 0.1.0) lib/beatseek/verification/spotify.ex:16: Beatseek.Verification.Spotify.get_artist/1
    (beatseek 0.1.0) lib/beatseek/verification/spotify.ex:8: Beatseek.Verification.Spotify.verify/1
    iex:1: (file)

If this happens it's usually because the credentials aren't found. System.get_env("SPOTIFY_CLIENT_ID") and System.get_env("SPOTIFY_CLIENT_SECRET") should both return the credentials configured in Spotify. What usually happens is Spotify.encoded_credentials() returns "Og==" instead of a longer base64 encoded string. This happens because Spotify in deps/spotify_ex/lib/spotify_ex.ex is looking for Application.get_env(:spotify_ex, :client_id) or compile time values. This is not easily apparent in the Phoenix 1.5 test app at https://github.com/jsncmgs1/spotify_ex_test.

For the trouble this is worth and the fact that I can't run Albums.get_artists_albums nor can I really customize the query to just be in the US market, I find the library really doesn't give me much. I could build the credentials piece in Req but this is honestly fine.

I had done this for a take-home project luckily because I ran into issues immediately. I have no clue where I got the code to do this either btw, but it just works when it does. I would've been so fucking lost without past me figuring this out a year ago. Way to go.