Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
very-doge-wow committed Jan 1, 2024
1 parent 3fc61b0 commit ae2f7db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Migrate your playlists from Amazon Music to Spotify using a simple Flask web int

## Setup and Startup

### Spotify Authentication via OAuth
### 🔑 Spotify Authentication via OAuth

Navigate to [developer.spotify.com](https://developer.spotify.com/dashboard) and
create a new app. Use this as the callback URL:
Expand All @@ -15,7 +15,9 @@ create a new app. Use this as the callback URL:
http://127.0.0.1:5000/callback
```

### Amazon Authentication (Workaround)
Retrieve your client id and client secret for later use.

### 🔑 Amazon Authentication (Workaround)

Currently, the Amazon Music API won't let us create applications for OAuth ourselves without
them needing to be approved by Amazon. Since we only want to perform a one-time
Expand All @@ -30,7 +32,7 @@ Copy the resulting token and set it as environment variable as described in the
Make sure to also copy the `x-api-key` value as provided in the example `curl`
command given on Amazon's website as well.

### Required Environment Variables
### ℹ️ Required Environment Variables

Next set these environment variables. Get the client id and client
secret from the spotify app you have just created.
Expand All @@ -45,15 +47,15 @@ export AMAZON_TOKEN=XXX
export AMAZON_X_API_KEY=XXX
```

### Installation of Dependencies
### 🔧 Installation of Dependencies

Install the dependencies using pipenv:

```shell
pipenv install
```

### Startup
### 🚀 Startup

Start the flask server like this:

Expand All @@ -65,12 +67,15 @@ You can then open the webinterface under the URL `https://127.0.0.1:5000`.
Press the button for authenticating at Spotify before running any migration.
Errors will be printed in the Flask app's log, if any occurred.

## Caveats
| | Tip |
|----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 💡 | Try to verify the status code of the reponses from the Amazon/Spotify API using the log before opening an issue. Refreshing the credentials will most likely resolve the issue. |

## 🚧 Caveats

The following limitations exist:

1. Do **not** run multiple migrations simultaneously. This will probably result in rate-limits being exceeded and the progress bar breaking.
2. The Amazon token will expire after about `30min`. Keep that in mind when running migrations.
3. The app does **not** check if a playlist with the same name already exists. A new playlist is created each time you start a migration.
4. If a song from the Amazon Playlist is not present in Spotify, the Spotify Search API might return false songs, which will then be added to the playlist. Make sure to check the result after the migration has finished.

2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Startup
app = Flask(__name__)
app.secret_key = generate_random_string(32)
app.secret_key = "fakekey"


@app.route('/auth/spotify')
Expand Down
6 changes: 4 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def create_spotify_playlist(name: str):
def add_tracks_to_spotify_playlist(spotify_access_token: str, playlist_id: str, tracks: list[dict]):
count = 0
for track in tracks:
count += 1
# first get track id
logging.debug(f"Searching for track: {track['artist']} - {track['title']}")
url = f'{SPOTIFY_BASE_ENDPOINT}/search'
Expand Down Expand Up @@ -135,4 +134,7 @@ def add_tracks_to_spotify_playlist(spotify_access_token: str, playlist_id: str,

# write progress to session
count += 1
settings.PROGRESS = count / len(tracks) * 100
settings.PROGRESS = (count / len(tracks)) * 100
print(f"length of tracks: {len(tracks)}")
print(f"track count: {count}")
print(f"progress: {settings.PROGRESS}")

0 comments on commit ae2f7db

Please sign in to comment.