// Initialize all tooltips on the page
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
// Function to open the search modal and trigger the search automatically
function openSearchModal(trackTitle, spotify_id) {
const modal = new bootstrap.Modal(document.getElementById('searchModal'));
const searchQueryInput = document.getElementById('search-query');
const spotifyIdInput = document.getElementById('spotify-id');
// Pre-fill the input fields
searchQueryInput.value = trackTitle;
spotifyIdInput.value = spotify_id;
// Show the modal
modal.show();
setTimeout(() => {
searchQueryInput.form.requestSubmit(); // Trigger the form submission
}, 200); // Delay the search slightly to ensure the modal is visible before searching
}
let currentAudio = null;
let currentButton = null;
function playPreview(button, previewUrl) {
if (currentAudio) {
currentAudio.pause();
if (currentButton) {
currentButton.innerHTML = '';
}
}
if (currentAudio && currentAudio.src === previewUrl) {
currentAudio = null;
currentButton = null;
} else {
currentAudio = new Audio(previewUrl);
currentAudio.play();
currentButton = button;
button.innerHTML = '';
currentAudio.onended = function () {
button.innerHTML = '';
currentAudio = null;
currentButton = null;
};
}
}
function playJellyfinTrack(button, jellyfinId) {
if (currentAudio && currentButton === button) {
currentAudio.pause();
currentAudio = null;
currentButton.innerHTML = '';
currentButton = null;
return;
}
if (currentAudio) {
currentAudio.pause();
if (currentButton) {
currentButton.innerHTML = '';
}
}
fetch(`/get_jellyfin_stream/${jellyfinId}`)
.then(response => response.json())
.then(data => {
const streamUrl = data.stream_url;
currentAudio = new Audio(streamUrl);
currentAudio.play();
currentButton = button;
button.innerHTML = '';
currentAudio.onended = function () {
button.innerHTML = '';
currentAudio = null;
currentButton = null;
};
})
.catch(error => console.error('Error fetching Jellyfin stream URL:', error));
}