Compare commits
2 Commits
e168b6f2df
...
45945732c9
Author | SHA1 | Date | |
---|---|---|---|
45945732c9 | |||
7b2ea2a93f |
@ -18,13 +18,23 @@ class PlaylistUpdater:
|
|||||||
|
|
||||||
def _update_tracks(self):
|
def _update_tracks(self):
|
||||||
self._tracks = []
|
self._tracks = []
|
||||||
headers = { 'Authorization': f"Bearer {self._auth_token}" }
|
|
||||||
rnext = f"{self._spotify_api_endpoint}/me/tracks?limit=50"
|
rnext = f"{self._spotify_api_endpoint}/me/tracks?limit=50"
|
||||||
while rnext is not None:
|
while rnext is not None:
|
||||||
r = rq.get(rnext, headers = headers).json()
|
r = self._fetch(rnext);
|
||||||
self._tracks += r['items']
|
self._tracks += r['items']
|
||||||
rnext = r['next']
|
rnext = r['next']
|
||||||
|
|
||||||
|
def _fetch(self, url):
|
||||||
|
headers = { 'Authorization': f"Bearer {self._auth_token}" }
|
||||||
|
while True:
|
||||||
|
r = rq.get(f"{url}", headers=headers)
|
||||||
|
if 200 <= r.status_code <= 299:
|
||||||
|
return r.json()
|
||||||
|
# slow down if spotify is applying rate limiting
|
||||||
|
if r.status_code == 429:
|
||||||
|
time.sleep(30)
|
||||||
|
# don't try again in a crazy fast loop to avoid rate limits
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def update_playlist(self, playlist_id):
|
def update_playlist(self, playlist_id):
|
||||||
pltracks = []
|
pltracks = []
|
||||||
@ -34,12 +44,12 @@ class PlaylistUpdater:
|
|||||||
headers = { 'Authorization': f"Bearer {self._auth_token}" }
|
headers = { 'Authorization': f"Bearer {self._auth_token}" }
|
||||||
added_at_dict = {}
|
added_at_dict = {}
|
||||||
|
|
||||||
r = rq.get(f"{self._spotify_api_endpoint}/playlists/{playlist_id}?fields=tracks,snapshot_id", headers = headers).json()
|
r = self._fetch(f"{self._spotify_api_endpoint}/playlists/{playlist_id}?fields=tracks,snapshot_id")
|
||||||
snapshot_id = r['snapshot_id']
|
snapshot_id = r['snapshot_id']
|
||||||
pltracks = [t['track']['id'] for t in r['tracks']['items']]
|
pltracks = [t['track']['id'] for t in r['tracks']['items']]
|
||||||
rnext = r['tracks']['next']
|
rnext = r['tracks']['next']
|
||||||
while rnext is not None:
|
while rnext is not None:
|
||||||
r = rq.get(rnext, headers = headers).json()
|
r = self._fetch(rnext)
|
||||||
for track in r['items']:
|
for track in r['items']:
|
||||||
pltracks.append(track['track']['id'])
|
pltracks.append(track['track']['id'])
|
||||||
rnext = r['next']
|
rnext = r['next']
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
version: '3.9'
|
|
||||||
|
|
||||||
services:
|
|
||||||
web:
|
|
||||||
hostname: heartbeats-web
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./web/Dockerfile
|
|
||||||
restart: unless-stopped
|
|
||||||
ports:
|
|
||||||
- 8464:80
|
|
||||||
environment:
|
|
||||||
- CLIENT_ID=${CLIENT_ID}
|
|
||||||
- CLIENT_SECRET=${CLIENT_SECRET}
|
|
||||||
- BASE_URL=http://localhost:8464
|
|
||||||
|
|
||||||
redis:
|
|
||||||
hostname: heartbeats-redis
|
|
||||||
image: redis
|
|
||||||
restart: unless-stopped
|
|
||||||
volumes:
|
|
||||||
- './redis-data:/data'
|
|
||||||
|
|
||||||
populater:
|
|
||||||
hostname: heartbeats-populater
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: ./populater/Dockerfile
|
|
||||||
restart: unless-stopped
|
|
||||||
environment:
|
|
||||||
- CLIENT_ID=${CLIENT_ID}
|
|
||||||
- CLIENT_SECRET=${CLIENT_SECRET}
|
|
16
readme.md
Normal file
16
readme.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# :musical_note: heartbeats :saxophone:
|
||||||
|
|
||||||
|
> Maintain a (potentially) public list of your recently liked songs so people know how cool you are
|
||||||
|
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
|
||||||
|
0. Create a spotify developer account and create a new app
|
||||||
|
0. Create a `.env` file with your spotify secrets:
|
||||||
|
|
||||||
|
```
|
||||||
|
CLIENT_ID=<client_id>
|
||||||
|
CLIENT_SECRET=<client_secret>
|
||||||
|
```
|
||||||
|
|
||||||
|
0. Run `docker compose up -d` to start
|
Loading…
Reference in New Issue
Block a user