This commit is contained in:
TylerCG 2025-04-27 20:18:00 -04:00
parent fa99cd2251
commit 49307515c8
2 changed files with 30 additions and 25 deletions

View File

@ -64,7 +64,7 @@ async def dropoutDownload(
return JSONResponse(status_code=500, content={"status": "error", "message": str(e)})
@app.post("/ydl")
async def ydl(url: str, location: str):
async def ydl(url: str = Form(...), location: str = Form(...)):
try:
await loop.run_in_executor(None, partial(download.youtube.ydl, url, location))
# download.youtube.ydl(url,location)

View File

@ -47,40 +47,45 @@
<!-- {navBar} -->
<form id="ydl_download">
<input class="downloader" name="url" type="text" id="download_field" placeholder="Enter URL">
<select class="downloader" name="location" id="download_location">
<option value="/nsfw">NSFW</option>
<option value="/podcasts">Podcast</option>
<option value="/asmr">ASMR</option>
<option value="/youtube">YouTube</option>
</select><br>
<button class="downloader" type="submit">Download</button> <!-- Added a submit button -->
<button class="downloader" type="submit">Download</button>
</form>
<div id="downloadResult"></div>
</body>
<script>
function clearInput() {
$('#download_field').val(''); // Clear the input field
}
// Handle the form submission with AJAX
$(document).ready(function () {
$('#ydl_download').submit(function (event) {
event.preventDefault(); // Prevent the default form submission
alert("File is now downloading");
$.ajax({
type: 'POST', // Use POST method to send data
url: '/ydl', // Target URL for the CherryPy handler
data: $('#ydl_download').serializeArray(), // Serialize the form data
success: function (data) {
$('#downloadResult').html(data); // Display the result in the specified div
alert("File has finished downloading");
}
<script>
function clearInput() {
$('#download_field').val(''); // Clear the input field
}
$(document).ready(function () {
$('#ydl_download').submit(function (event) {
event.preventDefault(); // Prevent default form submission
alert("File is now downloading..."); // Placeholder, can be replaced with a loading spinner
$.ajax({
type: 'POST',
url: '/ydl', // URL for handling the request on the server
data: $('#ydl_download').serializeArray(), // Serialize form data
success: function (data) {
$('#downloadResult').html(data); // Show server response
alert("File has finished downloading"); // Update as necessary
clearInput(); // Clear the form fields after download is finished
},
error: function () {
alert("An error occurred during the download process. Please try again.");
}
});
});
});
});
</script>
</script>
<!-- <script type="text/javascript" src="/static/javascript/ydl.js"></script> -->
</html>