-
+
diff --git a/src/lib/server/helpers.ts b/src/lib/server/helpers.ts
index 4b42bbb..af5111d 100644
--- a/src/lib/server/helpers.ts
+++ b/src/lib/server/helpers.ts
@@ -1,20 +1,14 @@
import formats from '$lib/common/supportedFormats.json';
-import winston from 'winston';
-import { dev } from '$app/environment';
-export const logger = winston.createLogger({
- level: dev ? 'debug' : 'error',
- format: winston.format.json(),
- transports: [new winston.transports.Console()]
-});
-const formatMime = new Map(Object.entries(formats));
-export const isURLValid = (url: string) => {
- try {
- new URL(url);
- } catch {
- return false;
- }
+const formatMime = new Map(Object.entries(formats))
- return true;
-};
export const mimeTypeMap = formatMime;
+export const contentTypeFromFormat = (format: string): string => {
+ const toReturn: string | undefined = formatMime.get(format)
+
+ if (!toReturn) {
+ throw new Error("Unsupported format")
+ }
+
+ return toReturn;
+}
\ No newline at end of file
diff --git a/src/lib/server/ytdlp.ts b/src/lib/server/ytdlp.ts
index bbeecab..9afded2 100644
--- a/src/lib/server/ytdlp.ts
+++ b/src/lib/server/ytdlp.ts
@@ -2,10 +2,9 @@ import { create } from 'youtube-dl-exec';
import { env } from '$env/dynamic/private';
import { spawn } from 'node:child_process';
import supportedFormats from '$lib/common/supportedFormats.json';
-import { logger, mimeTypeMap } from '$lib/server/helpers';
+import { mimeTypeMap } from '$lib/server/helpers';
const YTDLP_PATH: string = env.YTDLP_PATH as string;
-const HTTPS_PROXY: string = env.v as string;
export const ytdl = create(YTDLP_PATH);
@@ -17,8 +16,7 @@ export async function getYouTubeMetadata(link: string) {
dumpSingleJson: true,
noCheckCertificates: true,
noWarnings: true,
- preferFreeFormats: true,
- proxy: HTTPS_PROXY ? HTTPS_PROXY : ''
+ preferFreeFormats: true
});
}
@@ -26,55 +24,33 @@ export async function getYouTubeMetadata(link: string) {
* Streams the YouTube video/audio using youtube-dl-exec
*/
export function streamYouTube(link: string, format: string): ReadableStream
{
- logger.debug(`Starting to stream: ${link}`);
- const mimeType: string | undefined = mimeTypeMap.get(format);
-
+ const mimeType: string | undefined = mimeTypeMap.get(format)
+
if (!mimeType) {
- throw new Error('Unsupported format');
+ throw new Error("Unsupported format");
}
- logger.debug(`Given format is compatible: ${mimeType}`);
return new ReadableStream({
start(controller) {
- const args = ['--no-write-thumbnail', '-o', '-'];
+ const args = [
+ '-o',
+ '-',
+ ].filter(Boolean);
- if (HTTPS_PROXY) {
- args.push('--proxy', HTTPS_PROXY);
- }
-
- if (mimeType?.includes('audio')) {
- args.push(
- ...['--extract-audio', '--embed-metadata', '--embed-thumbnail', '--audio-format', format]
- );
+ if(mimeType?.includes('audio')) {
+ args.push(...['--extract-audio', '--embed-metadata', '--embed-thumbnail', '--audio-format', format])
} else if (mimeType.includes('video')) {
- args.push(...['--embed-metadata', '--embed-thumbnail', '--format', format]);
+ args.push(...['--embed-metadata', '--embed-thumbnail', '--format', format])
}
- const cmd = `${YTDLP_PATH} ${args.join(' ')} ${link}`;
- logger.debug(`Running: ${cmd}`);
+ console.info(`yt-dlp ${args.join(' ')} ${link}`)
- const process = spawn(YTDLP_PATH, [...args, link], {
- cwd: '/tmp',
- stdio: ['ignore', 'pipe', 'pipe']
- });
+ const process = spawn('yt-dlp', [...args, link], { stdio: ['ignore', 'pipe', 'ignore'] });
- process.stdout.on('data', (chunk) => {
- try {
- controller.enqueue(chunk);
- } catch (ex) {
- process.kill();
- }
- });
- process.stderr.on('data', (chunk) => logger.debug(chunk.toString()));
- process.stdout.on('end', () => {
- try {
- controller.close();
- } catch (ex) {
- logger.error(ex);
- }
- });
+ process.stdout.on('data', (chunk) => controller.enqueue(chunk));
+ process.stdout.on('end', () => controller.close());
process.stdout.on('error', (err) => {
- logger.error('Stream error:', err);
+ console.error('Stream error:', err);
controller.error(err);
});
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 0d97a1a..61642b3 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -17,11 +17,4 @@
transform: rotate(180deg);
display: inline-block;
}
-
- @media screen and (max-height: 600px) {
- /* Your CSS rules here */
- footer {
- display: none;
- }
- }
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts
deleted file mode 100644
index 5b66645..0000000
--- a/src/routes/+page.server.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const prerender = true;
-export const ssr = true;
-export const csr = true;
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 07793c0..714644d 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -10,49 +10,42 @@
let showModal = $state(false);
let href = $state('');
let disabled = $state(true);
- let metadata = $state(false);
+ let metadata = $state(true);
let downloading = $state(false);
- let logs = $state('');
- let logId = undefined;
const formats = Object.keys(supportedFormats).map((f) => {
return { value: f, label: f.toUpperCase() };
});
- const sources = [
- { value: 'youtube', label: 'YouTube' },
- { value: 'youtube', label: 'Any Other Website' }
- ];
const toggleModal = () => {
showModal = !showModal;
};
onMount(() => {
- document.cookie = 'downloading=0';
+ document.cookie = 'downloading=0'
});
- const readLogs = () => {
- logId = setInterval(() => {
- logs += "We're downloading
";
- }, 2000);
- };
const onClick = () => {
- let checkIterations = 0;
link = '';
downloading = true;
- document.cookie = 'downloading=1';
-
- readLogs();
+ document.cookie = 'downloading=1'
const id = setInterval(() => {
- if (document.cookie.includes('downloading=0') || checkIterations > 3) {
- downloading = false && clearInterval(id) && clearInterval(logId);
+ if (document.cookie.includes('downloading=0')) {
+ console.log("FINITO!")
+ downloading = false && clearInterval(id);
}
- checkIterations++;
}, 1000);
};
const createAnchor = () => {
+ console.log({
+ source,
+ link,
+ format,
+ metadata
+ });
+
if (!(source && link && format)) {
disabled = true;
return;
@@ -75,8 +68,7 @@
searchParams.append('source', source);
searchParams.append('link', link);
searchParams.append('format', format);
-
- if (metadata) searchParams.append('metadata', '1');
+ searchParams.append('metadata', metadata);
href = `/download?${searchParams.toString()}`;
};
@@ -91,20 +83,12 @@
}
});
-
-
+
- {@html logs}
@@ -120,42 +104,46 @@
-
🐙 Scaricatore 🐙
+
🐙 Scaricatore 🐙