this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

migrate away from spotify-tui

+63 -1
+1 -1
.gitignore
··· 9 9 .liked_tracks 10 10 .env 11 11 .cache 12 - backup.py 12 + secrets.json
+62
backup.py
··· 1 + # /// script 2 + # requires-python = ">=3.12" 3 + # dependencies = [ 4 + # "spotipy", 5 + # ] 6 + # /// 7 + 8 + #!/usr/bin/env python3 9 + 10 + from spotipy import Spotify, SpotifyOAuth 11 + from subprocess import run 12 + from pathlib import Path 13 + import sys 14 + 15 + here = Path(__file__).parent 16 + 17 + tokens = json.loads(here / "tokens.json") 18 + 19 + # Initial setup 20 + library = here / "library.tsv" 21 + spotify = Spotify( 22 + auth_manager=SpotifyOAuth( 23 + scope=["user-follow-modify", "user-library-read"], 24 + client_id=tokens["id"], 25 + client_secret=tokens["secret"], 26 + redirect_uri="http://localhost:8080", 27 + ) 28 + ) 29 + 30 + # Get tracks from API 31 + results = spotify.current_user_saved_tracks() 32 + tracks = results["items"] 33 + # while results["next"]: 34 + # results = spotify.next(results) 35 + # tracks.extend(results["items"]) 36 + del results 37 + 38 + print(tracks) 39 + 40 + # Boil them down to (artists, title, album) 41 + new_tracks = [ 42 + '\t'.join([ 43 + ", ".join(a["name"] for a in t["track"].get("artists", [])), 44 + t["track"].get("name", None), 45 + # t["track"]["album"]["name"], 46 + ]) 47 + for t in tracks 48 + ] 49 + 50 + # Get whole library 51 + lib = list(library.read_text('utf8').splitlines()) 52 + tracks, header = lib[1:], lib[0] 53 + # Add our tracks 54 + tracks.extend(new_tracks) 55 + # Sort 56 + tracks.sort() 57 + # Write back library 58 + library.write_text('\n'.join([header] + tracks), encoding='utf8') 59 + # Git add commti and push 60 + run(["git", "add", library]) 61 + run(["git", "commit", "-m", "update"]) 62 + run(["git", "push"])