Sets the Spotify credentials.
Request Body:
{
"client_id": "your_spotify_client_id",
"client_secret": "your_spotify_client_secret"
}
Response:
{
"status": "success"
}
Logs out the user.
Response:
{
"status": "success"
}
Gets the authentication status.
Response:
{
"authenticated": boolean,
"has_credentials": boolean
}
Gets the User Profile (image URL can be null).
Response:
{
"display_name": "John Doe",
"image_url": "https://profile-image.spotify.com/user/..." | null
}
Fetches playlists from a specified YouTube channel.
Request Body:
{
"channelId": "YOUTUBE_CHANNEL_ID"
}
Response:
[
{
"playlistId": "string",
"playlistName": "string"
},
{
"playlistId": "string",
"playlistName": "string"
}
]
Imports playlists from YouTube to Spotify.
Request Query Parameters:
playlists=[
{"playlistId":"PLH0cqYRIH9", "playlistName":"Rock Classics"},
{"playlistId":"PLJ8cMiYb3", "playlistName":"Summer Hits"}
]
Example Import Log:
data: Starting import of playlist: Rock Classics
data: success: Found Stairway to Heaven by Led Zeppelin
data: success: Found Sweet Child O' Mine by Guns N' Roses
data: success: Added batch of 50 tracks
data: warning: Not found: Rare Live Performance
data: success: Created playlist 'Rock Classics' - https://open.spotify.com/playlist/...
data: Starting import of playlist: Summer Hits
data: success: Found Blinding Lights by The Weeknd
data: success: Found Dance Monkey by Tones and I
data: success: Added batch of 50 tracks
data: success: Created playlist 'Summer Hits' - https://open.spotify.com/playlist/...
data: All imports completed
The following JavaScript function handles importing playlists on the dashboard:
async function importSelectedPlaylists() {
const selected = Array.from(document.querySelectorAll('.playlist-checkbox:checked'))
.map(checkbox => ({
playlistId: checkbox.id,
playlistName: checkbox.nextElementSibling.textContent.trim()
}));
if (selected.length === 0) {
alert('Please select at least one playlist');
return;
}
const progressLog = document.getElementById('progressLog');
progressLog.innerHTML = '';
document.getElementById('progressContainer').classList.remove('hidden');
const eventSource = new EventSource(`/api/import-playlists?playlists=${encodeURIComponent(JSON.stringify(selected))}`);
eventSource.onmessage = function (event) {
const p = document.createElement('p');
const data = event.data;
if (data.includes('success:')) {
p.className = 'text-green-600';
const message = data.replace('success:', '').trim();
p.innerHTML = message.includes('spotify') ?
`${message.split(' - ')[0]} - <a href="${message.split(' - ')[1]}" target="_blank" class="text-blue-500 hover:underline">${message.split(' - ')[1]}</a>` :
message;
} else if (data.includes('warning:')) {
p.className = 'text-yellow-600';
p.textContent = data.replace('warning:', '').trim();
} else if (data.includes('error:')) {
p.className = 'text-red-600';
p.textContent = data.replace('error:', '').trim();
} else {
p.textContent = data;
}
progressLog.appendChild(p);
progressLog.scrollTop = progressLog.scrollHeight;
document.addEventListener('keydown', function (event) {
if (event.key === 'ArrowDown') {
progressLog.scrollTop = progressLog.scrollHeight;
}
});
if (data === 'All imports completed') {
importInProgress = false;
document.getElementById('importButton').style.display = 'block';
eventSource.close();
}
};
}
- User visits React frontend.
- Frontend displays credential input form.
- User enters Spotify Client ID and Secret.
- Frontend calls POST /login with credentials.
- After successful credential save, frontend shows "Connect to Spotify" button.
- Button click redirects to Spotify auth page.
- User authorizes the application.
- Callback redirects to frontend dashboard.
- Frontend checks auth status via GET /api/auth-status.
- Loads user profile via GET /api/user-profile.
- User enters YouTube channel ID.
- Frontend fetches playlists via POST /api/fetch-playlists.
- User selects playlists to import.
- Frontend initiates EventSource connection to /api/import-playlists.
- Backend processes each playlist:
- Fetches video details.
- Matches songs using Gemini AI.
- Creates Spotify playlist.
- Adds tracks in batches.
- Frontend displays real-time progress.
- Process completes with playlist links.
- User can logout via GET /logout.
- Frontend handles auth state changes.
- Token refresh happens automatically.