-
🐙 Scaricatore v{PUBLIC_VERSION} 🐙
+
+
+
🐙 Scaricatore v{PUBLIC_VERSION} 🐙
- Download Spotify playlists and YouTube videos with ease. Choose your source, paste a link,
- select format, go!
+ This app allows you to download Spotify playlists and YouTube videos directly. Choose your
+ source, paste the link, and select a format to start downloading!
-
- Source Code
+ Click here for the source code
-
+
{/if}
+
+
diff --git a/src/routes/download/+server.ts b/src/routes/download/+server.ts
index 9b62aba..305f0b4 100644
--- a/src/routes/download/+server.ts
+++ b/src/routes/download/+server.ts
@@ -1,14 +1,14 @@
import { error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getYouTubeMetadata, streamYouTube, ytdl } from '$lib/server/ytdlp';
-import { isURLValid, logger, mimeTypeMap } from '$lib/server/helpers';
+import { contentTypeFromFormat, mimeTypeMap } from '$lib/server/helpers';
-const validateRequest = (url: URL) => {
+export const GET: RequestHandler = async ({ url }) => {
// Get query params
const link = url.searchParams.get('link');
const format = url.searchParams.get('format'); // mp3, mp4
const source = url.searchParams.get('source'); // youtube or spotify
- const metadata = url.searchParams.has('metadata');
+ const metadata = url.searchParams.get('metadata');
// Validate input
if (!link || !format || !source) {
@@ -19,54 +19,28 @@ const validateRequest = (url: URL) => {
throw error(400, 'Currently, only YouTube is supported');
}
- if (!isURLValid(link)) {
- throw error(400, 'URL not valid');
- }
-
- if (!mimeTypeMap.get(format)) {
- throw error(400, 'format not valid');
- }
-
- logger.debug(`Request is valid`);
-
- return {
- link,
- format,
- source,
- metadata
- };
-};
-export const GET: RequestHandler = async ({ url }) => {
- const { format, source, metadata, link } = validateRequest(url);
- let filename = '';
- let contentLength = 0;
-
try {
- logger.debug(`Fetching video data to set filename`);
- // Fetch metadata for filename
- const ytMetadata = await getYouTubeMetadata(link);
- const { title, uploader, filesize_approx } = ytMetadata;
- contentLength = filesize_approx;
- const safeTitle = `${uploader} - ${title}`;
- filename = `${safeTitle}.${format}`;
- } catch (err) {
- logger.error(err);
- logger.error('Error fetching metadata:');
- throw error(500, 'Failed to fetch video metadata');
- }
+ let filename = `you-clicked-no-metadata-so-i-cant-put-a-correct-name.${format}`;
+
+ if (metadata) {
+ // Fetch metadata for filename
+ const metadata = await getYouTubeMetadata(link);
+ const { title, uploader } = metadata;
+ const safeTitle = `${uploader} - ${title}`;
+ filename = `${safeTitle}.${format}`;
+ }
- try {
// Stream video/audio
return new Response(streamYouTube(link, format), {
headers: {
- 'Content-Type': `${mimeTypeMap.get(format)}`,
- 'Content-Length': contentLength,
- 'Content-Disposition': `attachment; filename="${filename}"`
+ 'Content-Type': contentTypeFromFormat(format),
+ 'Content-Disposition': `attachment; filename="${filename}"`,
+ 'Set-Cookie': 'downloading=0'
}
});
} catch (err) {
- logger.error(err);
- logger.error('Filed to stream file');
- throw error(500, 'Failed to stream file');
+ console.error(err)
+ console.error('Error fetching metadata:');
+ throw error(500, 'Failed to fetch video metadata');
}
};
diff --git a/static/favicon.png b/static/favicon.png
index 8fe723d..825b9e6 100644
Binary files a/static/favicon.png and b/static/favicon.png differ
diff --git a/static/manifest.json b/static/manifest.json
index 24bf9e1..cd1980a 100644
--- a/static/manifest.json
+++ b/static/manifest.json
@@ -1,16 +1,16 @@
{
- "name": "scaricatore",
+ "name": "EmersaDownloader",
"start_url": "https://dl.emersa.it",
"theme_color": "rgb(34,197,94)",
"background": "black",
"orientation": "portrait",
"display": "fullscreen",
- "short_name": "scaricatore",
+ "short_name": "e-downloader",
"icons": [
{
"src": "favicon.png",
"type": "image/png",
- "sizes": "512x512"
+ "sizes": "128x128"
}
]
}
diff --git a/static/screen.webp b/static/screen.webp
index 10012d6..c35c9b9 100644
Binary files a/static/screen.webp and b/static/screen.webp differ