|
<!DOCTYPE html> |
|
<html lang="en"> |
|
|
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Shazam Playlist to Youtube Playlist</title> |
|
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> |
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> |
|
<script src="https://www.youtube.com/iframe_api"></script> |
|
<style> |
|
#youtube-player, iframe { |
|
width: 100%; |
|
height: 100%; |
|
} |
|
</style> |
|
</head> |
|
|
|
<body> |
|
<div class="container my-4"> |
|
<h1 class="text-center">Shazam Playlist to Youtube Playlist</h1> |
|
<p class="text-center"> |
|
Download the CSV of your playlist from |
|
<a href="https://www.shazam.com/myshazam" target="_blank">https://www.shazam.com/myshazam</a>. |
|
</p> |
|
<p class="text-center">Upload your Shazam Playlist CSV file.</p> |
|
<div class="row mx-2 justify-content-center"> |
|
<div class="col-md-6"> |
|
<input type="file" class="form-control upload-form col-md-6" accept=".csv"> |
|
</div> |
|
</div> |
|
|
|
<div class="row mt-5 justify-content-center"> |
|
<div class="col-md-8"> |
|
<div class="object-fit-contain border rounded ratio ratio-16x9"> |
|
<div id="youtube-player"></div> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<div class="row mt-5"> |
|
<div class="col-md-12 playlist table-responsive"> |
|
<table class="table table-striped"> |
|
<thead> |
|
<tr> |
|
<th>Title</th> |
|
<th>Artist</th> |
|
</tr> |
|
</thead> |
|
<tbody></tbody> |
|
</table> |
|
</div> |
|
</div> |
|
</div> |
|
|
|
<script> |
|
let player; |
|
let videoIds = []; |
|
let currentVideoIndex = 0; |
|
|
|
function onYouTubeIframeAPIReady() { |
|
player = new YT.Player('youtube-player', { |
|
height: '100%', |
|
width: '100%', |
|
playerVars: { autoplay: 1 }, |
|
events: { |
|
'onReady': onPlayerReady, |
|
'onStateChange': onPlayerStateChange |
|
} |
|
}); |
|
} |
|
|
|
function onPlayerReady(event) { |
|
if (videoIds.length > 0) { |
|
event.target.loadVideoById(videoIds[0]); |
|
} |
|
} |
|
|
|
function onPlayerStateChange(event) { |
|
if (event.data == YT.PlayerState.ENDED) { |
|
playNextVideo(); |
|
} |
|
} |
|
|
|
function playNextVideo() { |
|
currentVideoIndex++; |
|
if (currentVideoIndex >= videoIds.length) { |
|
currentVideoIndex = 0; |
|
} |
|
player.loadVideoById(videoIds[currentVideoIndex]); |
|
} |
|
|
|
function updatePlaylist(playlist) { |
|
const tbody = $('#playlist tbody'); |
|
tbody.empty(); |
|
playlist.forEach(function (item) { |
|
tbody.append(`<tr><td>${item.Title}</td><td>${item.Artist}</td></tr>`); |
|
}); |
|
} |
|
|
|
document.querySelector('.upload-form').addEventListener('input', function (e) { |
|
e.preventDefault(); |
|
if (e.target.files.length == 0) { |
|
return; |
|
} |
|
const formData = new FormData(); |
|
formData.append('file', e.target.files[0]); |
|
|
|
fetch( |
|
'/parse_csv', |
|
{ |
|
method: 'POST', |
|
body: formData |
|
}) |
|
.then(response => response.text(), response => response.text()) |
|
.then(response => { |
|
const playlist = document.querySelector('.playlist'); |
|
playlist.innerHTML = response |
|
setTimeout(() => { |
|
playlist.querySelector('table').classList.add(...['table', 'table-striped', 'table-hover']); |
|
}, 100); |
|
}); |
|
}); |
|
|
|
</script> |
|
</body> |
|
|
|
</html> |