Skip to content

Commit

Permalink
Clarifying licensing of spotify_backup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
linsomniac committed Feb 1, 2025
1 parent 3af8e76 commit 8dd60be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Portions licensed under MIT license (spotify-backup.py)

Creative Commons Legal Code

CC0 1.0 Universal
Expand Down
43 changes: 27 additions & 16 deletions spotify2ytmusic/spotify_backup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python3
#
# This file is licensed under the MIT license
# This file originates from https://github.com/caseychu/spotify-backup

import codecs
import http.client
Expand Down Expand Up @@ -60,16 +63,13 @@ def authorize(client_id, scope):

@staticmethod
def _construct_auth_url(client_id, scope, redirect_uri):
return (
"https://accounts.spotify.com/authorize?"
+ urllib.parse.urlencode(
{
"response_type": "token",
"client_id": client_id,
"scope": scope,
"redirect_uri": redirect_uri,
}
)
return "https://accounts.spotify.com/authorize?" + urllib.parse.urlencode(
{
"response_type": "token",
"client_id": client_id,
"scope": scope,
"redirect_uri": redirect_uri,
}
)

def _construct_url(self, url, params):
Expand Down Expand Up @@ -122,7 +122,9 @@ def _handle_token(self):
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.end_headers()
self.wfile.write(b"<script>close()</script>Thanks! You may now close this window.")
self.wfile.write(
b"<script>close()</script>Thanks! You may now close this window."
)
access_token = re.search("access_token=([^&]*)", self.path).group(1)
raise SpotifyAPI._Authorization(access_token)

Expand Down Expand Up @@ -150,7 +152,9 @@ def fetch_user_data(spotify, dump):
playlist_data = spotify.list("me/playlists", {"limit": 50})
for playlist in playlist_data:
print(f"Loading playlist: {playlist['name']}")
playlist["tracks"] = spotify.list(playlist["tracks"]["href"], {"limit": 100})
playlist["tracks"] = spotify.list(
playlist["tracks"]["href"], {"limit": 100}
)
playlists.extend(playlist_data)

return playlists, liked_albums
Expand All @@ -172,7 +176,10 @@ def write_to_file(file, format, playlists, liked_albums):
uri=track["track"]["uri"],
name=track["track"]["name"],
artists=", ".join(
[artist["name"] for artist in track["track"]["artists"]]
[
artist["name"]
for artist in track["track"]["artists"]
]
),
album=track["track"]["album"]["name"],
release_date=track["track"]["album"]["release_date"],
Expand All @@ -183,9 +190,13 @@ def write_to_file(file, format, playlists, liked_albums):

def main(dump="playlists,liked", format="json", file="playlists.json", token=""):
print("Starting backup...")
spotify = SpotifyAPI(token) if token else SpotifyAPI.authorize(
client_id="5c098bcc800e45d49e476265bc9b6934",
scope="playlist-read-private playlist-read-collaborative user-library-read",
spotify = (
SpotifyAPI(token)
if token
else SpotifyAPI.authorize(
client_id="5c098bcc800e45d49e476265bc9b6934",
scope="playlist-read-private playlist-read-collaborative user-library-read",
)
)

playlists, liked_albums = fetch_user_data(spotify, dump)
Expand Down

0 comments on commit 8dd60be

Please sign in to comment.