Compare commits
No commits in common. "main" and "v0.7.2" have entirely different histories.
27 changed files with 879 additions and 1457 deletions
|
@ -1,23 +0,0 @@
|
||||||
Dockerfile
|
|
||||||
.dockerignore
|
|
||||||
.git
|
|
||||||
.gitignore
|
|
||||||
.gitattributes
|
|
||||||
README.md
|
|
||||||
.npmrc
|
|
||||||
.prettierrc
|
|
||||||
.eslintrc.cjs
|
|
||||||
.graphqlrc
|
|
||||||
.editorconfig
|
|
||||||
.svelte-kit
|
|
||||||
.vscode
|
|
||||||
node_modules
|
|
||||||
build
|
|
||||||
package
|
|
||||||
**/.env
|
|
||||||
|
|
||||||
scripts/
|
|
||||||
downloads
|
|
||||||
|
|
||||||
yt-dlp
|
|
||||||
build.tar.gz
|
|
|
@ -1,6 +1,4 @@
|
||||||
NODE_ENV=development
|
|
||||||
HOST=0.0.0.0
|
HOST=0.0.0.0
|
||||||
ORIGIN=https://dl.emersa.it
|
ORIGIN=https://dl.emersa.it
|
||||||
YTDLP_PATH=./yt-dlp
|
YTDLP_PATH=./yt-dlp
|
||||||
PUBLIC_VERSION=0.6.3
|
PUBLIC_VERSION=0.6.3
|
||||||
HTTPS_PROXY=
|
|
|
@ -17,5 +17,5 @@ jobs:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
- name: Prepare, Check, Lint and Format
|
- name: Prepare, Check, Lint and Format
|
||||||
run: |
|
run: |
|
||||||
npm i
|
npm ci
|
||||||
npm run prepare
|
npm run prepare
|
||||||
|
|
|
@ -23,10 +23,10 @@ jobs:
|
||||||
- name: Update deps, install them (to change package-lock.json) and commit
|
- name: Update deps, install them (to change package-lock.json) and commit
|
||||||
run: |
|
run: |
|
||||||
npx npm-check-updates --target minor -u
|
npx npm-check-updates --target minor -u
|
||||||
npm install
|
npm ci
|
||||||
git config --global user.name "forgejo-bot"
|
git config --global user.name "forgejo-bot"
|
||||||
git config --global user.email "bot@pweapon.org"
|
git config --global user.email "bot@pweapon.org"
|
||||||
git add package* || exit 0
|
git add package.json || exit 0
|
||||||
git commit -m "chore: update minor dependencies"
|
git commit -m "chore: update minor dependencies"
|
||||||
git push origin HEAD:${GITHUB_REF#refs/heads/}
|
git push origin HEAD:${GITHUB_REF#refs/heads/}
|
||||||
env:
|
env:
|
||||||
|
|
|
@ -33,7 +33,6 @@ jobs:
|
||||||
echo "HOST=0.0.0.0" >> .env
|
echo "HOST=0.0.0.0" >> .env
|
||||||
echo "ORIGIN=https://dl.emersa.it" >> .env
|
echo "ORIGIN=https://dl.emersa.it" >> .env
|
||||||
echo "PUBLIC_VERSION=$(cat package.json | jq .version)" >> .env
|
echo "PUBLIC_VERSION=$(cat package.json | jq .version)" >> .env
|
||||||
echo "NODE_ENV=production" >> .env
|
|
||||||
npm run build
|
npm run build
|
||||||
cp package* build/
|
cp package* build/
|
||||||
cp .env build/
|
cp .env build/
|
||||||
|
|
26
README.md
26
README.md
|
@ -2,23 +2,22 @@
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|
|
||||||
|
|
||||||
It's a svelte(kit) frontend + backend that uses [`yt-dlp`](https://github.com/yt-dlp/yt-dlp) to let people download audio/video files from the web.
|
<img src='./static/screen.webp' alt='screen' height=300>
|
||||||
|
|
||||||
[`... we don't have the concept of users, when we refer to people, we call them people.`](https://ar.al/2020/08/07/what-is-the-small-web/)
|
It's a svelte(kit) frontend that uses `yt-dlp` to let the user download things from the web.
|
||||||
|
|
||||||
<a href='https://dl.emersa.it'><img src='./static/screen.webp' alt='screen' height=300></a>
|
## How to Deploy
|
||||||
|
|
||||||
## Self-Hosting
|
|
||||||
|
|
||||||
### Node
|
### Node
|
||||||
|
|
||||||
- Install NodeJS
|
0. Install nodejs
|
||||||
- Create a new directory (`"${PROJECT_ROOT}"`)
|
1. Download the latest release from the [releases](https://git.pweapon.org/odo/dl.emersa.it/releases) page.
|
||||||
- run `scripts/install.sh "${PROJECT_ROOT}"`
|
2. Unpack and decompress (`tar xvf build.tar.gz`) the release
|
||||||
|
3. Then `cd` into it and run: `npm ci` and `npm run build`
|
||||||
Edit `scripts/deploy_example.sh` if you need to deploy `scaricatore` to some server using `SSH`.
|
4. Copy `.env.example` to `.env`, and add needed variables
|
||||||
|
5. Run it: `node .`
|
||||||
|
6. You can also try to configure the systemd unit file inside the `configurations` folder.
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
|
@ -26,8 +25,8 @@ Edit `scripts/deploy_example.sh` if you need to deploy `scaricatore` to some ser
|
||||||
|
|
||||||
## Development: getting started
|
## Development: getting started
|
||||||
|
|
||||||
- run `git clone git@git.pweapon.org:odo/dl.emersa.it.git`
|
- Clone the repo
|
||||||
- Run `cd dl.emersa.it; npm install` (you have to have node installed)
|
- Run `npm install` (you have to have node installed)
|
||||||
- Run `npm run download-yt-dlp`
|
- Run `npm run download-yt-dlp`
|
||||||
- Copy `.env.example` to `.env`
|
- Copy `.env.example` to `.env`
|
||||||
- Change `.env` to set `YTDLP_PATH` to the yt-dlp binary previously downloaded
|
- Change `.env` to set `YTDLP_PATH` to the yt-dlp binary previously downloaded
|
||||||
|
@ -36,6 +35,7 @@ Edit `scripts/deploy_example.sh` if you need to deploy `scaricatore` to some ser
|
||||||
|
|
||||||
## To do:
|
## To do:
|
||||||
|
|
||||||
|
- Proper logs (I don't like them, not useful for production build)
|
||||||
- Containerfile for container build
|
- Containerfile for container build
|
||||||
- Source spotify (spotdl)
|
- Source spotify (spotdl)
|
||||||
- Parse URL info without `youtube-dl-exec`
|
- Parse URL info without `youtube-dl-exec`
|
||||||
|
|
|
@ -5,9 +5,9 @@ After=network.target
|
||||||
[Service]
|
[Service]
|
||||||
User=user
|
User=user
|
||||||
Group=user
|
Group=user
|
||||||
WorkingDirectory=/home/user/downloader
|
WorkingDirectory=<PROJECT_ROOT>
|
||||||
EnvironmentFile=/home/user/downloader/.env
|
ExecStart=/usr/bin/node <PROJECT_ROOT>
|
||||||
ExecStart=/usr/bin/node /home/user/downloader
|
Environment=ORIGIN=http://example.com
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StandardOutput=syslog
|
StandardOutput=syslog
|
||||||
|
@ -16,4 +16,3 @@ SyslogIdentifier=downloader
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
1627
package-lock.json
generated
1627
package-lock.json
generated
File diff suppressed because it is too large
Load diff
38
package.json
38
package.json
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "dl.emersa.it",
|
"name": "dl.emersa.it",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.0-b",
|
"version": "0.7.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
@ -15,34 +15,32 @@
|
||||||
"lint": "prettier --check . && eslint ."
|
"lint": "prettier --check . && eslint ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^1.2.8",
|
"@eslint/compat": "^1.2.7",
|
||||||
"@eslint/js": "^9.25.0",
|
"@eslint/js": "^9.21.0",
|
||||||
"@sveltejs/adapter-node": "^5.2.12",
|
"@sveltejs/adapter-node": "^5.2.12",
|
||||||
"@sveltejs/kit": "^2.20.7",
|
"@sveltejs/kit": "^2.17.2",
|
||||||
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||||
"@tailwindcss/vite": "^4.1.4",
|
"@tailwindcss/vite": "^4.0.8",
|
||||||
"eslint": "^9.25.0",
|
"eslint": "^9.21.0",
|
||||||
"eslint-config-prettier": "^10.1.2",
|
"eslint-config-prettier": "^10.0.1",
|
||||||
"eslint-plugin-svelte": "^3.5.1",
|
"eslint-plugin-svelte": "^2.46.1",
|
||||||
"globals": "^16.0.0",
|
"globals": "^16.0.0",
|
||||||
"mdsvex": "^0.12.3",
|
"mdsvex": "^0.12.3",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.2",
|
||||||
"prettier-plugin-svelte": "^3.3.3",
|
"prettier-plugin-svelte": "^3.3.3",
|
||||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||||
"svelte": "^5.28.1",
|
"svelte": "^5.20.2",
|
||||||
"svelte-check": "^4.1.6",
|
"svelte-check": "^4.1.4",
|
||||||
"sveltekit-sse": "^0.13.18",
|
"tailwindcss": "^4.0.8",
|
||||||
"tailwindcss": "^4.1.4",
|
"typescript": "^5.7.3",
|
||||||
"typescript": "^5.8.3",
|
"typescript-eslint": "^8.24.1",
|
||||||
"typescript-eslint": "^8.30.1",
|
"vite": "^6.1.1"
|
||||||
"vite": "^6.3.2"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/forms": "^0.5.10",
|
"@tailwindcss/forms": "^0.5.10",
|
||||||
"@tailwindcss/postcss": "^4.1.4",
|
"@tailwindcss/postcss": "^4.0.8",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@types/node": "^22.14.1",
|
"@types/node": "^22.13.5",
|
||||||
"winston": "^3.17.0",
|
"youtube-dl-exec": "^3.0.15"
|
||||||
"youtube-dl-exec": "^3.0.20"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
## Prepares the current environment:
|
# An example hook script to verify what is about to be committed.
|
||||||
## - Installing dependencies
|
# Called by "git commit" with no arguments. The hook should
|
||||||
## - Configuring git hooks
|
# exit with non-zero status after issuing an appropriate message if
|
||||||
|
# it wants to stop the commit.
|
||||||
|
#
|
||||||
|
# To enable this hook, rename this file to "pre-commit".
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,9 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
# This is a script for running `install.sh`
|
|
||||||
# in a remote server using SSH.
|
|
||||||
# Configure SSH_SERVER and PROJECT_ROOT variables
|
|
||||||
# for using this script.
|
|
||||||
|
|
||||||
###### ATTENTION ######
|
|
||||||
# The install.sh script has a confirmation prompt
|
|
||||||
# because it deletes the content of the PROJECT_ROOT folder,
|
|
||||||
# just put "yes | install.sh" to automatically confirm.
|
|
||||||
|
|
||||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
SSH_SERVER="example"
|
SSH_SERVER="example"
|
||||||
PROJECT_ROOT=example_directory
|
PROJECT_ROOT=example_directory
|
||||||
|
|
||||||
SSH_REMOTE_DIR="${SSH_SERVER}:${PROJECT_ROOT}"
|
SSH_REMOTE_DIR="${SSH_SERVER}:${PROJECT_ROOT}"
|
||||||
|
|
||||||
ssh "${SSH_SERVER}" "mkdir -p ${PROJECT_ROOT}"
|
ssh "${SSH_SERVER}" "mkdir -p ${PROJECT_ROOT}"
|
||||||
|
|
|
@ -1,33 +1,18 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
### This is a script for installing the latest release
|
|
||||||
### of `scaricatore`.
|
|
||||||
|
|
||||||
PROJECT_ROOT=$1
|
PROJECT_ROOT=$1
|
||||||
PROXY=$2
|
|
||||||
|
|
||||||
if [ -z ${PROJECT_ROOT+x} ]; then
|
if [ -z ${PROJECT_ROOT+x} ]; then
|
||||||
echo "ERROR: No PROJECT_ROOT set (first argument to ${0})"
|
echo "error no project_root set"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z ${PROXY+x} ]; then
|
|
||||||
echo "INFO: no proxy given"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "${PROJECT_ROOT}"
|
mkdir -p "${PROJECT_ROOT}"
|
||||||
cd "${PROJECT_ROOT}" || exit 1
|
cd "${PROJECT_ROOT}" || exit 1
|
||||||
|
rm -rf ./*
|
||||||
read -p "We're about to run rm -rf ${PROJECT_ROOT}/*. Are you sure?" -n 1 -r
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]
|
|
||||||
then
|
|
||||||
rm -rf ./*
|
|
||||||
fi
|
|
||||||
|
|
||||||
wget https://git.pweapon.org/odo/dl.emersa.it/releases/download/latest/build.tar.gz
|
wget https://git.pweapon.org/odo/dl.emersa.it/releases/download/latest/build.tar.gz
|
||||||
tar -xvf build.tar.gz -C .
|
tar -xvf build.tar.gz -C .
|
||||||
rm build.tar.gz
|
rm build.tar.gz
|
||||||
npm ci
|
npm ci
|
||||||
npm run download-yt-dlp
|
npm run download-yt-dlp
|
||||||
echo "YTDLP_PATH=$(readlink -f yt-dlp)" >>.env
|
echo "YTDLP_PATH=$(readlink -f yt-dlp)" >>.env
|
||||||
echo "HTTPS_PROXY=${PROXY}" >>.env
|
|
||||||
|
|
|
@ -7,11 +7,14 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
<style>
|
<style>
|
||||||
* {
|
@font-face {
|
||||||
font-family: 'Fira Code', monospace;
|
font-family: 'Press Start 2P';
|
||||||
|
src: url('/fonts/PressStart2P-Regular.ttf');
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background: black; /* Fallback */
|
background: black; /* Fallback */
|
||||||
|
font-family: 'Press Start 2P', sans-serif;
|
||||||
color: #37ff1456; /* Retro green text */
|
color: #37ff1456; /* Retro green text */
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { logger } from '$lib/server/helpers';
|
|
||||||
|
|
||||||
export async function handle({ event, resolve }) {
|
|
||||||
logger.info(`Received ${event.request.method} request: ${event.url}`);
|
|
||||||
|
|
||||||
return await resolve(event);
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
const createAnchorElement = (url: string, filename: string): HTMLAnchorElement => {
|
|
||||||
const anchor = document.createElement('a');
|
|
||||||
anchor.href = url;
|
|
||||||
anchor.download = filename;
|
|
||||||
return anchor;
|
|
||||||
};
|
|
||||||
export const download = async (url: string, filename: string) => {
|
|
||||||
const response = await fetch(url);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Network response was not ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = await response.blob();
|
|
||||||
const objectURL = window.URL.createObjectURL(blob);
|
|
||||||
const anchor = createAnchorElement(url, filename);
|
|
||||||
document.body.appendChild(anchor);
|
|
||||||
anchor.click();
|
|
||||||
anchor.remove();
|
|
||||||
window.URL.revokeObjectURL(objectURL);
|
|
||||||
};
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"mp3": "audio/mpeg",
|
"mp3": "audio/mpeg",
|
||||||
"opus": "audio/ogg",
|
"mp4": "video/mp4",
|
||||||
"wav": "audio/wav",
|
"opus": "audio/ogg",
|
||||||
"mp4": "video/mp4"
|
"wav": "audio/wav"
|
||||||
}
|
}
|
|
@ -1,73 +1,3 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
let props = $props();
|
||||||
let { url, dismiss } = $props();
|
|
||||||
|
|
||||||
let visible = $state(false);
|
|
||||||
let progress = $state(0);
|
|
||||||
let filename = $state('');
|
|
||||||
onMount(async () => {
|
|
||||||
if (!url) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
visible = true;
|
|
||||||
|
|
||||||
const response = await fetch(url);
|
|
||||||
if (!response.ok) throw new Error('Download failed');
|
|
||||||
|
|
||||||
const contentDisposition: string = response?.headers?.get('content-disposition');
|
|
||||||
filename = contentDisposition.split('filename=')[1];
|
|
||||||
const contentLength: number = Number(response?.headers?.get('content-length'));
|
|
||||||
const reader = response?.body?.getReader();
|
|
||||||
const chunks: Uint8Array[] = [];
|
|
||||||
let receivedLength = 0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const { done, value }: ReadableStreamReadResult<Uint8Array> = await reader.read();
|
|
||||||
if (done) break;
|
|
||||||
if (value) {
|
|
||||||
chunks.push(value);
|
|
||||||
receivedLength += value.length;
|
|
||||||
progress = Math.round((receivedLength / contentLength) * 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = new Blob(chunks);
|
|
||||||
const downloadUrl = URL.createObjectURL(blob);
|
|
||||||
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = downloadUrl;
|
|
||||||
a.download = filename;
|
|
||||||
a.click();
|
|
||||||
|
|
||||||
URL.revokeObjectURL(downloadUrl);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
visible = false;
|
|
||||||
}, 1500); // auto-dismiss
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
visible = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if visible}
|
|
||||||
<div
|
|
||||||
class="fixed inset-0 z-50 flex items-center justify-center bg-black/80 font-mono backdrop-blur-sm"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="w-[90%] max-w-sm rounded-2xl border border-green-400 bg-[#000f00] p-6 text-sm text-green-300 shadow-2xl"
|
|
||||||
>
|
|
||||||
<p class="mb-2 text-center text-cyan-300">
|
|
||||||
Downloading <span class="font-semibold text-green-400">{filename}</span>
|
|
||||||
</p>
|
|
||||||
<div class="h-4 w-full overflow-hidden rounded-md border border-green-500 bg-black">
|
|
||||||
<div
|
|
||||||
class="h-full bg-gradient-to-r from-green-400 to-green-600 transition-all duration-300"
|
|
||||||
style="width: {progress}%"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<p class="mt-2 text-center text-pink-400">{progress}%</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
|
@ -1,28 +1,8 @@
|
||||||
<div class="w-[150px]">
|
<div
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"
|
class=" backdrop-blur-xs bg-black/20 absolute inset-0 z-10 flex items-center justify-center "
|
||||||
><linearGradient id="a3"
|
id="spinner"
|
||||||
><stop offset="0" stop-color="#FF156D" stop-opacity="0"></stop><stop
|
>
|
||||||
offset="1"
|
<div class="w-[150px]">
|
||||||
stop-color="#FF156D"
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><linearGradient id="a3"><stop offset="0" stop-color="#FF156D" stop-opacity="0"></stop><stop offset="1" stop-color="#FF156D"></stop></linearGradient><circle fill="none" stroke="url(#a3)" stroke-width="15" stroke-linecap="round" stroke-dasharray="0 44 0 44 0 44 0 44 0 360" cx="100" cy="100" r="70" transform-origin="center"><animateTransform type="rotate" attributeName="transform" calcMode="discrete" dur="2" values="360;324;288;252;216;180;144;108;72;36" repeatCount="indefinite"></animateTransform></circle></svg>
|
||||||
></stop></linearGradient
|
</div>
|
||||||
><circle
|
|
||||||
fill="none"
|
|
||||||
stroke="url(#a3)"
|
|
||||||
stroke-width="15"
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-dasharray="0 44 0 44 0 44 0 44 0 360"
|
|
||||||
cx="100"
|
|
||||||
cy="100"
|
|
||||||
r="70"
|
|
||||||
transform-origin="center"
|
|
||||||
><animateTransform
|
|
||||||
type="rotate"
|
|
||||||
attributeName="transform"
|
|
||||||
calcMode="discrete"
|
|
||||||
dur="2"
|
|
||||||
values="360;324;288;252;216;180;144;108;72;36"
|
|
||||||
repeatCount="indefinite"
|
|
||||||
></animateTransform></circle
|
|
||||||
></svg
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
import formats from '$lib/common/supportedFormats.json';
|
import formats from '$lib/common/supportedFormats.json';
|
||||||
import winston from 'winston';
|
|
||||||
import { dev } from '$app/environment';
|
|
||||||
|
|
||||||
export const logger = winston.createLogger({
|
const formatMime = new Map(Object.entries(formats))
|
||||||
level: import.meta.env.DEV ? 'debug' : 'error',
|
|
||||||
format: winston.format.json(),
|
|
||||||
transports: [new winston.transports.Console()]
|
|
||||||
});
|
|
||||||
const formatMime = new Map(Object.entries(formats));
|
|
||||||
export const isURLValid = (url: string) => {
|
export const isURLValid = (url: string) => {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url)
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
}
|
||||||
export const mimeTypeMap = formatMime;
|
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;
|
||||||
|
}
|
|
@ -2,10 +2,9 @@ import { create } from 'youtube-dl-exec';
|
||||||
import { env } from '$env/dynamic/private';
|
import { env } from '$env/dynamic/private';
|
||||||
import { spawn } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
import supportedFormats from '$lib/common/supportedFormats.json';
|
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 YTDLP_PATH: string = env.YTDLP_PATH as string;
|
||||||
const HTTPS_PROXY: string = env.HTTPS_PROXY as string;
|
|
||||||
|
|
||||||
export const ytdl = create(YTDLP_PATH);
|
export const ytdl = create(YTDLP_PATH);
|
||||||
|
|
||||||
|
@ -13,73 +12,45 @@ export const ytdl = create(YTDLP_PATH);
|
||||||
* Fetch YouTube metadata (title, uploader/artist)
|
* Fetch YouTube metadata (title, uploader/artist)
|
||||||
*/
|
*/
|
||||||
export async function getYouTubeMetadata(link: string) {
|
export async function getYouTubeMetadata(link: string) {
|
||||||
const options = {
|
return await ytdl(link, {
|
||||||
dumpSingleJson: true,
|
dumpSingleJson: true,
|
||||||
noCheckCertificates: true,
|
noCheckCertificates: true,
|
||||||
noWarnings: true,
|
noWarnings: true,
|
||||||
preferFreeFormats: true
|
preferFreeFormats: true
|
||||||
};
|
});
|
||||||
|
|
||||||
if (HTTPS_PROXY) {
|
|
||||||
options.proxy = HTTPS_PROXY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ytdl(link, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Streams the YouTube video/audio using youtube-dl-exec
|
* Streams the YouTube video/audio using youtube-dl-exec
|
||||||
*/
|
*/
|
||||||
export function streamYouTube(link: string, format: string): ReadableStream<Uint8Array> {
|
export function streamYouTube(link: string, format: string): ReadableStream<Uint8Array> {
|
||||||
logger.debug(`Starting to stream: ${link}`);
|
const mimeType: string | undefined = mimeTypeMap.get(format)
|
||||||
const mimeType: string | undefined = mimeTypeMap.get(format);
|
|
||||||
|
|
||||||
if (!mimeType) {
|
if (!mimeType) {
|
||||||
throw new Error('Unsupported format');
|
throw new Error("Unsupported format");
|
||||||
}
|
}
|
||||||
logger.debug(`Given format is compatible: ${mimeType}`);
|
|
||||||
|
|
||||||
return new ReadableStream({
|
return new ReadableStream({
|
||||||
start(controller) {
|
start(controller) {
|
||||||
const args = ['--no-write-thumbnail', '-o', '-'];
|
const args = [
|
||||||
|
'-o',
|
||||||
|
'-',
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
if (HTTPS_PROXY) {
|
if(mimeType?.includes('audio')) {
|
||||||
args.push('--proxy', HTTPS_PROXY);
|
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')) {
|
} 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}`;
|
console.info(`${YTDLP_PATH} ${args.join(' ')} ${link}`)
|
||||||
logger.debug(`Running: ${cmd}`);
|
|
||||||
|
|
||||||
const process = spawn(YTDLP_PATH, [...args, link], {
|
const process = spawn('yt-dlp', [...args, link], { stdio: ['ignore', 'pipe', 'ignore'] });
|
||||||
cwd: '/tmp',
|
|
||||||
stdio: ['ignore', 'pipe', 'pipe']
|
|
||||||
});
|
|
||||||
|
|
||||||
process.stdout.on('data', (chunk) => {
|
process.stdout.on('data', (chunk) => controller.enqueue(chunk));
|
||||||
try {
|
process.stdout.on('end', () => controller.close());
|
||||||
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('error', (err) => {
|
process.stdout.on('error', (err) => {
|
||||||
logger.error('Stream error:', err);
|
console.error('Stream error:', err);
|
||||||
controller.error(err);
|
controller.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,4 @@
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-height: 600px) {
|
|
||||||
/* Your CSS rules here */
|
|
||||||
footer {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
export const prerender = true;
|
|
||||||
export const ssr = true;
|
|
||||||
export const csr = true;
|
|
|
@ -2,9 +2,7 @@
|
||||||
import { PUBLIC_VERSION } from '$env/static/public';
|
import { PUBLIC_VERSION } from '$env/static/public';
|
||||||
import supportedFormats from '$lib/common/supportedFormats.json';
|
import supportedFormats from '$lib/common/supportedFormats.json';
|
||||||
import Loader from '$lib/components/Loader.svelte';
|
import Loader from '$lib/components/Loader.svelte';
|
||||||
import { download } from '$lib/client/downloader';
|
import { onMount } from 'svelte';
|
||||||
import DownloadManager from '$lib/components/DownloadManager.svelte';
|
|
||||||
import { mount, unmount } from 'svelte';
|
|
||||||
|
|
||||||
let source = $state('youtube');
|
let source = $state('youtube');
|
||||||
let link = $state('');
|
let link = $state('');
|
||||||
|
@ -12,36 +10,42 @@
|
||||||
let showModal = $state(false);
|
let showModal = $state(false);
|
||||||
let href = $state('');
|
let href = $state('');
|
||||||
let disabled = $state(true);
|
let disabled = $state(true);
|
||||||
let metadata = $state(false);
|
let metadata = $state(true);
|
||||||
let logs = $state('');
|
let downloading = $state(false);
|
||||||
let downloadManager: DownloadManager | null = null;
|
|
||||||
|
|
||||||
const formats = Object.keys(supportedFormats).map((f) => {
|
const formats = Object.keys(supportedFormats).map((f) => {
|
||||||
return { value: f, label: f.toUpperCase() };
|
return { value: f, label: f.toUpperCase() };
|
||||||
});
|
});
|
||||||
const sources = [
|
|
||||||
{ value: 'youtube', label: 'YouTube' },
|
|
||||||
{ value: 'youtube', label: 'Any Other Website' }
|
|
||||||
];
|
|
||||||
|
|
||||||
const toggleModal = () => {
|
const toggleModal = () => {
|
||||||
showModal = !showModal;
|
showModal = !showModal;
|
||||||
};
|
};
|
||||||
|
|
||||||
const dismiss = () => {
|
onMount(() => {
|
||||||
unmount(downloadManager);
|
document.cookie = 'downloading=0'
|
||||||
};
|
});
|
||||||
|
|
||||||
const onClick = async (evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
|
|
||||||
const props = $state({ url: href });
|
|
||||||
downloadManager = mount(DownloadManager, { target: document.body, props, events: { dismiss } });
|
|
||||||
|
|
||||||
|
const onClick = () => {
|
||||||
link = '';
|
link = '';
|
||||||
|
downloading = true;
|
||||||
|
document.cookie = 'downloading=1'
|
||||||
|
|
||||||
|
const id = setInterval(() => {
|
||||||
|
if (document.cookie.includes('downloading=0')) {
|
||||||
|
console.log("FINITO!")
|
||||||
|
downloading = false && clearInterval(id);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createAnchor = () => {
|
const createAnchor = () => {
|
||||||
|
console.log({
|
||||||
|
source,
|
||||||
|
link,
|
||||||
|
format,
|
||||||
|
metadata
|
||||||
|
});
|
||||||
|
|
||||||
if (!(source && link && format)) {
|
if (!(source && link && format)) {
|
||||||
disabled = true;
|
disabled = true;
|
||||||
return;
|
return;
|
||||||
|
@ -64,8 +68,7 @@
|
||||||
searchParams.append('source', source);
|
searchParams.append('source', source);
|
||||||
searchParams.append('link', link);
|
searchParams.append('link', link);
|
||||||
searchParams.append('format', format);
|
searchParams.append('format', format);
|
||||||
|
searchParams.append('metadata', metadata);
|
||||||
if (metadata) searchParams.append('metadata', '1');
|
|
||||||
|
|
||||||
href = `/download?${searchParams.toString()}`;
|
href = `/download?${searchParams.toString()}`;
|
||||||
};
|
};
|
||||||
|
@ -80,107 +83,112 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="wrapper"
|
id="wrapper"
|
||||||
class="relative mx-auto max-w-full rounded-2xl bg-black p-4 text-green-400 shadow-xl sm:max-w-sm md:max-w-md lg:max-w-lg"
|
class="relative mx-auto rounded-lg bg-black p-6 text-[#00ff7f] shadow-lg sm:max-w-sm sm:border-4 sm:border-[#00ff7f] md:mt-10 md:max-w-md lg:max-w-lg 2xl:max-w-2xl"
|
||||||
>
|
>
|
||||||
<!-- Loader Overlay -->
|
<div id="loader" class={[{ downloading }]}>
|
||||||
<div
|
|
||||||
id="loader"
|
|
||||||
class="absolute inset-0 z-10 hidden items-center justify-center bg-black/80 backdrop-blur-sm"
|
|
||||||
>
|
|
||||||
<Loader />
|
<Loader />
|
||||||
{@html logs}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Info Button -->
|
<!-- Info Icon -->
|
||||||
<button
|
<button
|
||||||
onclick={toggleModal}
|
onclick={toggleModal}
|
||||||
class="absolute top-3 right-3 text-pink-500 transition hover:text-pink-400"
|
class="absolute top-3 right-3 text-[#ff007f] transition hover:text-[#ff3399]"
|
||||||
aria-label="Open Info Modal"
|
aria-label="Open Info Modal"
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="h-5 w-5" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="h-6 w-6" viewBox="0 0 24 24">
|
||||||
<path
|
<path
|
||||||
d="M12 0C5.373 0 0 5.373 0 12c0 6.627 5.373 12 12 12s12-5.373 12-12C24 5.373 18.627 0 12 0zm.75 18h-1.5v-6h1.5v6zm0-8h-1.5V8h1.5v2z"
|
d="M12 0C5.373 0 0 5.373 0 12c0 6.627 5.373 12 12 12s12-5.373 12-12C24 5.373 18.627 0 12 0zm.75 18h-1.5v-6h1.5v6zm0-8h-1.5V8h1.5v2z"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- Title -->
|
<h1 id="title" class="mb-6 text-center text-2xl text-[#00e5ff]">🐙 Scaricatore 🐙</h1>
|
||||||
<p id="title" class="mb-4 text-center font-mono text-xl tracking-tight text-cyan-300">
|
<form class="space-y-6">
|
||||||
🐙 Scaricatore 🐙
|
<!-- Source Selection -->
|
||||||
</p>
|
<fieldset class="space-y-4">
|
||||||
|
<legend class="text-[#00e5ff]">Choose Source:</legend>
|
||||||
|
|
||||||
<!-- Form -->
|
<label class="flex items-center space-x-3">
|
||||||
<form class="space-y-5 font-mono text-sm">
|
<input type="radio" name="source" value="youtube" bind:group={source} class="retro-radio" />
|
||||||
<!-- Source & Format -->
|
<span>YouTube</span>
|
||||||
<div class="flex flex-col gap-4 sm:flex-row">
|
</label>
|
||||||
<div class="flex-1">
|
|
||||||
<label for="source" class="mb-1 block text-cyan-300">Source</label>
|
<label class="flex items-center space-x-3">
|
||||||
<select
|
<input
|
||||||
id="source"
|
disabled
|
||||||
|
type="radio"
|
||||||
name="source"
|
name="source"
|
||||||
bind:value={source}
|
value="spotify"
|
||||||
class="w-full rounded-md border border-green-400 bg-[#000f00] px-3 py-2 text-green-300 focus:border-pink-400 focus:outline-none"
|
bind:group={source}
|
||||||
>
|
class="retro-radio"
|
||||||
{#each sources as source}
|
/>
|
||||||
<option value={source.value}>{source.label}</option>
|
<span class="not-available">Spotify</span>
|
||||||
{/each}
|
</label>
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex-1">
|
<label class="flex items-center space-x-3">
|
||||||
<label for="format" class="mb-1 block text-cyan-300">Format</label>
|
<input type="radio" name="source" value="other" bind:group={source} class="retro-radio" />
|
||||||
<select
|
<span>
|
||||||
id="format"
|
Other (<a
|
||||||
name="format"
|
href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md"
|
||||||
bind:value={format}
|
target="_blank"
|
||||||
class="w-full rounded-md border border-green-400 bg-[#000f00] px-3 py-2 text-green-300 focus:border-pink-400 focus:outline-none"
|
rel="noopener noreferrer"
|
||||||
>
|
class="text-[#ff3399] hover:underline"
|
||||||
{#each formats as format}
|
>supported sites
|
||||||
<option value={format.value}>{format.label}</option>
|
</a>)
|
||||||
{/each}
|
</span>
|
||||||
</select>
|
</label>
|
||||||
</div>
|
</fieldset>
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Video Link -->
|
<!-- Link Input -->
|
||||||
<div>
|
<div>
|
||||||
<label for="link" class="mb-1 block text-cyan-300">Video Link</label>
|
<label for="link" class="mb-2 block text-[#00e5ff]"> Enter Playlist or Video Link: </label>
|
||||||
<input
|
<input
|
||||||
|
name="link"
|
||||||
type="url"
|
type="url"
|
||||||
id="link"
|
id="link"
|
||||||
name="link"
|
|
||||||
bind:value={link}
|
bind:value={link}
|
||||||
required
|
required
|
||||||
placeholder="https://..."
|
placeholder="Paste your link here"
|
||||||
class="w-full rounded-md border border-green-400 bg-[#000f00] px-3 py-2 text-green-300 placeholder:text-green-600 focus:border-pink-400 focus:outline-none"
|
class="w-full rounded-lg border-4 border-[#00ff7f] bg-[#001a00] px-4 py-3 text-[#00ff7f] focus:border-[#ff3399] focus:outline-none"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Metadata Checkbox -->
|
<!-- Format Selection -->
|
||||||
<div class="flex items-center gap-2">
|
<div>
|
||||||
|
<label for="format" class="mb-2 block text-[#00e5ff]"> Choose Format: </label>
|
||||||
|
<select
|
||||||
|
id="format"
|
||||||
|
name="format"
|
||||||
|
bind:value={format}
|
||||||
|
class="w-full rounded-lg border-4 border-[#00ff7f] bg-[#001a00] px-4 py-3 text-[#00ff7f] focus:border-[#ff3399] focus:outline-none"
|
||||||
|
>
|
||||||
|
{#each formats as format}
|
||||||
|
<option value={format.value}>{format.label}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Metadata -->
|
||||||
|
<div>
|
||||||
|
<label for="metadata" class="mb-2 block text-[#00e5ff]"> Filename </label>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="metadata"
|
id="metadata"
|
||||||
name="metadata"
|
name="metadata"
|
||||||
bind:checked={metadata}
|
bind:checked={metadata}
|
||||||
class="h-4 w-4 border border-green-400 bg-[#000f00] text-green-500 focus:ring-pink-400"
|
class="rounded-lg border-4 border-[#00ff7f] bg-[#001a00] px-4 py-3 text-[#00ff7f] focus:border-[#ff3399] focus:outline-none"
|
||||||
/>
|
/>
|
||||||
<label for="metadata" class="text-cyan-300"
|
|
||||||
>Set filename (<span class="text-red-500">slow</span>)</label
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Download Button -->
|
|
||||||
<a
|
<a
|
||||||
id="btn-download"
|
id="btn-download"
|
||||||
{href}
|
{href}
|
||||||
onclick={onClick}
|
onclick={onClick}
|
||||||
class="{disabled
|
class="{disabled
|
||||||
? 'pointer-events-none opacity-50'
|
? 'disabled'
|
||||||
: ''} block w-full rounded-md border border-pink-400 bg-pink-600 px-4 py-3 text-center text-base font-bold text-black transition hover:bg-pink-500 active:border-yellow-400"
|
: ''} block w-full rounded-lg border-4 border-[#ff3399] bg-[#ff007f] px-4 py-3 text-center text-4xl text-black transition hover:bg-[#ff3399] active:border-yellow-500"
|
||||||
>
|
>
|
||||||
DOWNLOAD
|
DOWNLOAD
|
||||||
</a>
|
</a>
|
||||||
|
@ -189,24 +197,79 @@
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
{#if showModal}
|
{#if showModal}
|
||||||
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 text-green-300">
|
<div class="bg-opacity-80 fixed inset-0 z-50 flex items-center justify-center bg-black">
|
||||||
<div class="w-[90%] max-w-md rounded-lg border border-green-400 bg-[#001a00] p-5 text-center">
|
<div
|
||||||
<h2 class="mb-3 text-base font-semibold">🐙 Scaricatore v{PUBLIC_VERSION} 🐙</h2>
|
class="w-4/5 max-w-lg rounded-lg border-4 border-[#00ff7f] bg-[#002b00] p-6 text-center text-[#00ff7f]"
|
||||||
|
>
|
||||||
|
<h2 class="mb-4 text-lg">🐙 Scaricatore v{PUBLIC_VERSION} 🐙</h2>
|
||||||
<p>
|
<p>
|
||||||
Download Spotify playlists and YouTube videos with ease. Choose your source, paste a link,
|
This app allows you to download Spotify playlists and YouTube videos directly. Choose your
|
||||||
select format, go!
|
source, paste the link, and select a format to start downloading!
|
||||||
</p>
|
</p>
|
||||||
<p class="mt-3">
|
<span class="mt-10 block">
|
||||||
<a class="text-cyan-400 underline" href="https://git.pweapon.org/odo/dl.emersa.it"
|
<a class="underline text-[#00e5ff]" href="https://git.pweapon.org/odo/dl.emersa.it"
|
||||||
>Source Code</a
|
>Click here for the source code</a
|
||||||
>
|
>
|
||||||
</p>
|
</span>
|
||||||
<button
|
<button
|
||||||
onclick={toggleModal}
|
onclick={toggleModal}
|
||||||
class="mt-6 rounded-md border border-pink-400 bg-pink-600 px-4 py-2 text-black hover:bg-pink-500"
|
class="mt-6 rounded-lg border-4 border-[#ff3399] bg-[#ff007f] px-4 py-2 text-black hover:bg-[#ff3399]"
|
||||||
>
|
>
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
font-size: 14px;
|
||||||
|
font-family: 'Press Start 2P', cursive;
|
||||||
|
}
|
||||||
|
|
||||||
|
#loader {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#loader.downloading {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
.not-available {
|
||||||
|
text-decoration-line: line-through;
|
||||||
|
text-decoration-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.retro-radio {
|
||||||
|
appearance: none;
|
||||||
|
background-color: #000;
|
||||||
|
border: 2px solid #00ff7f;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.retro-radio:checked {
|
||||||
|
background-color: #00ff7f;
|
||||||
|
box-shadow:
|
||||||
|
0 0 4px #00ff7f,
|
||||||
|
0 0 10px #00ff7f;
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='url'],
|
||||||
|
select {
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#title {
|
||||||
|
font-size: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn-download {
|
||||||
|
font-size: 26px;
|
||||||
|
transition: opacity 0.3s ease;
|
||||||
|
}
|
||||||
|
a.disabled {
|
||||||
|
pointer-events: none;
|
||||||
|
cursor: default;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import type { RequestHandler } from './$types';
|
import type { RequestHandler } from './$types';
|
||||||
import { getYouTubeMetadata, streamYouTube, ytdl } from '$lib/server/ytdlp';
|
import { getYouTubeMetadata, streamYouTube, ytdl } from '$lib/server/ytdlp';
|
||||||
import { isURLValid, logger, mimeTypeMap } from '$lib/server/helpers';
|
import { contentTypeFromFormat, isURLValid, mimeTypeMap } from '$lib/server/helpers';
|
||||||
|
|
||||||
const validateRequest = (url: URL) => {
|
const validateRequest = (url) => {
|
||||||
// Get query params
|
// Get query params
|
||||||
const link = url.searchParams.get('link');
|
const link = url.searchParams.get('link');
|
||||||
const format = url.searchParams.get('format'); // mp3, mp4
|
const format = url.searchParams.get('format'); // mp3, mp4
|
||||||
const source = url.searchParams.get('source'); // youtube or spotify
|
const source = url.searchParams.get('source'); // youtube or spotify
|
||||||
const metadata = url.searchParams.has('metadata');
|
const metadata = url.searchParams.get('metadata');
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!link || !format || !source) {
|
if (!link || !format || !source) {
|
||||||
|
@ -27,46 +27,42 @@ const validateRequest = (url: URL) => {
|
||||||
throw error(400, 'format not valid');
|
throw error(400, 'format not valid');
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`Request is valid`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link,
|
link, format, source, metadata
|
||||||
format,
|
}
|
||||||
source,
|
}
|
||||||
metadata
|
|
||||||
};
|
|
||||||
};
|
|
||||||
export const GET: RequestHandler = async ({ url }) => {
|
export const GET: RequestHandler = async ({ url }) => {
|
||||||
const { format, source, metadata, link } = validateRequest(url);
|
const { format, source, metadata, link } = validateRequest(url)
|
||||||
let filename = '';
|
let filename = `you-clicked-no-metadata-so-i-cant-put-a-correct-name.${format}`;
|
||||||
let contentLength = 0;
|
|
||||||
|
|
||||||
try {
|
if (metadata) {
|
||||||
logger.debug(`Fetching video data to set filename`);
|
try {
|
||||||
// Fetch metadata for filename
|
// Fetch metadata for filename
|
||||||
const ytMetadata = await getYouTubeMetadata(link);
|
const metadata = await getYouTubeMetadata(link);
|
||||||
const { title, uploader, filesize_approx } = ytMetadata;
|
const { title, uploader } = metadata;
|
||||||
contentLength = filesize_approx;
|
const safeTitle = `${uploader} - ${title}`;
|
||||||
const safeTitle = `${uploader} - ${title}`;
|
filename = `${safeTitle}.${format}`;
|
||||||
filename = `${safeTitle}.${format}`;
|
} catch (err) {
|
||||||
} catch (err) {
|
console.error(err)
|
||||||
logger.error(err);
|
console.error('Error fetching metadata:');
|
||||||
logger.error('Error fetching metadata:');
|
throw error(500, 'Failed to fetch video metadata');
|
||||||
throw error(500, 'Failed to fetch video metadata');
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Stream video/audio
|
// Stream video/audio
|
||||||
return new Response(streamYouTube(link, format), {
|
return new Response(streamYouTube(link, format), {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': `${mimeTypeMap.get(format)}`,
|
'Content-Type': contentTypeFromFormat(format),
|
||||||
'Content-Length': contentLength,
|
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||||
'Content-Disposition': `attachment; filename="${filename}"`
|
'Set-Cookie': 'downloading=0'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
console.error(err)
|
||||||
logger.error('Filed to stream file');
|
console.error('Filed to stream file');
|
||||||
throw error(500, 'Failed to stream file');
|
throw error(500, 'Failed to stream file');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "scaricatore",
|
"name": "EmersaDownloader",
|
||||||
"start_url": "https://dl.emersa.it",
|
"start_url": "https://dl.emersa.it",
|
||||||
"theme_color": "rgb(34,197,94)",
|
"theme_color": "rgb(34,197,94)",
|
||||||
"background": "black",
|
"background": "black",
|
||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"display": "fullscreen",
|
"display": "fullscreen",
|
||||||
"short_name": "scaricatore",
|
"short_name": "e-downloader",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "favicon.png",
|
"src": "favicon.png",
|
||||||
"type": "image/png",
|
"type": "image/png",
|
||||||
"sizes": "512x512"
|
"sizes": "128x128"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 13 KiB |
Loading…
Add table
Add a link
Reference in a new issue