-
🐙 Scaricatore v{PUBLIC_VERSION} 🐙
+
+
+
🐙 Scaricatore v{PUBLIC_VERSION} 🐙
- 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!
+ Download Spotify playlists and YouTube videos with ease. Choose your source, paste a link,
+ select format, go!
-
- Click here for the source code
+ Source Code
-
+
{/if}
-
-
diff --git a/src/routes/download/+server.ts b/src/routes/download/+server.ts
index 305f0b4..9b62aba 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 { contentTypeFromFormat, mimeTypeMap } from '$lib/server/helpers';
+import { isURLValid, logger, mimeTypeMap } from '$lib/server/helpers';
-export const GET: RequestHandler = async ({ url }) => {
+const validateRequest = (url: 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.get('metadata');
+ const metadata = url.searchParams.has('metadata');
// Validate input
if (!link || !format || !source) {
@@ -19,28 +19,54 @@ export const GET: RequestHandler = async ({ 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 {
- 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}`;
- }
+ 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');
+ }
+ try {
// Stream video/audio
return new Response(streamYouTube(link, format), {
headers: {
- 'Content-Type': contentTypeFromFormat(format),
- 'Content-Disposition': `attachment; filename="${filename}"`,
- 'Set-Cookie': 'downloading=0'
+ 'Content-Type': `${mimeTypeMap.get(format)}`,
+ 'Content-Length': contentLength,
+ 'Content-Disposition': `attachment; filename="${filename}"`
}
});
} catch (err) {
- console.error(err)
- console.error('Error fetching metadata:');
- throw error(500, 'Failed to fetch video metadata');
+ logger.error(err);
+ logger.error('Filed to stream file');
+ throw error(500, 'Failed to stream file');
}
};
diff --git a/static/favicon.png b/static/favicon.png
index 825b9e6..8fe723d 100644
Binary files a/static/favicon.png and b/static/favicon.png differ
diff --git a/static/manifest.json b/static/manifest.json
index cd1980a..24bf9e1 100644
--- a/static/manifest.json
+++ b/static/manifest.json
@@ -1,16 +1,16 @@
{
- "name": "EmersaDownloader",
+ "name": "scaricatore",
"start_url": "https://dl.emersa.it",
"theme_color": "rgb(34,197,94)",
"background": "black",
"orientation": "portrait",
"display": "fullscreen",
- "short_name": "e-downloader",
+ "short_name": "scaricatore",
"icons": [
{
"src": "favicon.png",
"type": "image/png",
- "sizes": "128x128"
+ "sizes": "512x512"
}
]
}
diff --git a/static/screen.webp b/static/screen.webp
index c35c9b9..10012d6 100644
Binary files a/static/screen.webp and b/static/screen.webp differ