Compare commits
142 commits
Author | SHA1 | Date | |
---|---|---|---|
b43ee05ecf | |||
57d2adbdbc | |||
716ebe9ecd | |||
e3c0c7d1f9 | |||
d43db45617 | |||
67e521b7b4 | |||
3dc834daf0 | |||
5bcbfc70ec | |||
08578eef0b | |||
e82c027ad9 | |||
4303614237 | |||
4bf9d97345 | |||
99263fd14c | |||
|
691e294546 | ||
|
885c802da6 | ||
|
6d0d7ccecc | ||
|
ff5cef233d | ||
|
2b81cb2fa5 | ||
|
9ffcd5f596 | ||
|
1bd6d90814 | ||
|
c46189ff83 | ||
|
c416918a1a | ||
|
7a3bf1fb45 | ||
|
cd8a4c4d69 | ||
9c7f7eace1 | |||
5066c3ba7a | |||
a833c43713 | |||
a18fbb8614 | |||
|
bb233f7cb8 | ||
|
2f502b2530 | ||
|
c32cc4d3e7 | ||
|
5fc6b0700a | ||
|
b94d5ffc19 | ||
|
267da475a6 | ||
|
82aac1d3b9 | ||
56ef54b119 | |||
|
d21d4d57a9 | ||
214619ec3f | |||
|
18adf9a6a3 | ||
|
66196979cc | ||
|
4d0eaed688 | ||
|
6003e59aaa | ||
|
99ae01f895 | ||
|
9f8b49515e | ||
|
c7d65ee49a | ||
|
84feab36dc | ||
|
728db51c59 | ||
|
c3072322d1 | ||
|
565612cf30 | ||
77d1d7331d | |||
ebf597fea6 | |||
|
7dc90c4c27 | ||
|
96d59113bc | ||
|
e0fbca1e6d | ||
2899def330 | |||
|
e4dffe691c | ||
|
c55524221a | ||
|
1f5a6613d0 | ||
a4bec2cb38 | |||
|
f080ccc912 | ||
|
8e37875442 | ||
af9c2084eb | |||
13ba9fd1a1 | |||
3888d9d481 | |||
5ff4dc73de | |||
2f25ccf600 | |||
84d4379f16 | |||
|
9f4a2bc560 | ||
e525eb8a41 | |||
5b278b75c0 | |||
652208aa57 | |||
760812c692 | |||
3aaadc2b92 | |||
4aaaa4eedc | |||
da528e3a81 | |||
cf3733530b | |||
1b76d4de4b | |||
8224e620eb | |||
c16790699c | |||
25312ec595 | |||
24ff0a0738 | |||
0b58d9251e | |||
e4b1bcc677 | |||
f81083dec6 | |||
942e6ed59a | |||
a155cdf791 | |||
aca6510197 | |||
af971bec5d | |||
217a9b1028 | |||
d1b80f2cc9 | |||
89b2e4aaa2 | |||
697a8a73fe | |||
575fdc6386 | |||
1c893617dd | |||
90eaa0cbf1 | |||
728d8f45cf | |||
c8648b5cfe | |||
3a5b705d5f | |||
|
220244e26f | ||
61e08c5bb9 | |||
3be5e67018 | |||
e3e914882f | |||
b0ed4a7cc4 | |||
26a68fc102 | |||
4a12828571 | |||
bb548befc5 | |||
e9040bbf2b | |||
f2673d112b | |||
fa24bc435d | |||
da95e2024f | |||
6f93574e8a | |||
5d0fa4e951 | |||
0d3b797ec8 | |||
284313259a | |||
b5cbef9de7 | |||
109a668413 | |||
631b9e44f0 | |||
99096f3d24 | |||
6b8779f527 | |||
b16b84e5a3 | |||
45b85fed1d | |||
d523c4853f | |||
c7e99846b1 | |||
4b9018ecbb | |||
dcb7cfec27 | |||
204bceeee3 | |||
151b5432cd | |||
10d8ce8a15 | |||
|
79c3c820a4 | ||
15cb677910 | |||
6e86aa7f8c | |||
7c9b80917f | |||
f20b9869cc | |||
11b0b9f6a2 | |||
7213189744 | |||
a5e3e310b7 | |||
e06d04f387 | |||
4c08c6ee4a | |||
6924e8e082 | |||
87746bdcac | |||
b13e27d7e5 | |||
64e3e21621 |
27 changed files with 1572 additions and 855 deletions
23
.dockerignore
Normal file
23
.dockerignore
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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,4 +1,6 @@
|
||||||
|
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 install
|
npm i
|
||||||
npm run prepare
|
npm run prepare
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: Bump deps (only minor versions)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *' # Runs every night at midnight (UTC)
|
- cron: '0 23 * * *' # Runs every night at midnight
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
@ -26,7 +26,7 @@ jobs:
|
||||||
npm install
|
npm install
|
||||||
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.json || exit 0
|
git add package* || 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:
|
||||||
|
|
|
@ -21,24 +21,26 @@ jobs:
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
|
|
||||||
- name: Update deps, install them (to change package-lock.json) and commit
|
- name: Install JQ for extracting package.json version
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y jq
|
apt-get install -y jq
|
||||||
|
|
||||||
- name: Prepare, Check, Lint and Format
|
- name: Create Release
|
||||||
run: |
|
run: |
|
||||||
npm install
|
npm ci
|
||||||
touch .env
|
touch .env.production
|
||||||
echo "HOST=0.0.0.0" >> .env
|
echo "HOST=0.0.0.0" >> .env.production
|
||||||
echo "ORIGIN=https://dl.emersa.it" >> .env
|
echo "PORT=3000" >> .env.production
|
||||||
echo "YTDLP_PATH=./yt-dlp" >> .env
|
echo "ORIGIN=https://dl.emersa.it" >> .env.production
|
||||||
echo "PUBLIC_VERSION=$(cat package.json | jq .version)"
|
echo "PUBLIC_VERSION=$(cat package.json | jq .version)" >> .env.production
|
||||||
|
echo "NODE_ENV=production" >> .env.production
|
||||||
npm run build
|
npm run build
|
||||||
cp package* build/
|
cp package* build/
|
||||||
cp .env build/
|
cp .env.production build/
|
||||||
mkdir releases
|
mkdir releases
|
||||||
tar czvf releases/build.tar.gz build/
|
cd build/
|
||||||
|
tar czvf ../releases/build.tar.gz .
|
||||||
|
|
||||||
- name: Upload release
|
- name: Upload release
|
||||||
uses: actions/forgejo-release@v2
|
uses: actions/forgejo-release@v2
|
||||||
|
|
26
README.md
26
README.md
|
@ -2,22 +2,23 @@
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
<img src='./static/screen.webp' alt='screen' height=300>
|
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.
|
||||||
|
|
||||||
It's a svelte(kit) frontend that uses `yt-dlp` to let the user download things from the web.
|
[`... 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/)
|
||||||
|
|
||||||
## How to Deploy
|
<a href='https://dl.emersa.it'><img src='./static/screen.webp' alt='screen' height=300></a>
|
||||||
|
|
||||||
|
## Self-Hosting
|
||||||
|
|
||||||
### Node
|
### Node
|
||||||
|
|
||||||
0. Install nodejs
|
- Install NodeJS
|
||||||
1. Download the latest release from the [releases](https://git.pweapon.org/odo/dl.emersa.it/releases) page.
|
- Create a new directory (`"${PROJECT_ROOT}"`)
|
||||||
2. Unpack and decompress (`tar xvf build.tar.gz`) the release
|
- run `scripts/install.sh "${PROJECT_ROOT}"`
|
||||||
3. Then `cd` into it and run: `npm ci` and `npm run build`
|
|
||||||
4. Copy `.env.example` to `.env`, and add needed variables
|
Edit `scripts/deploy_example.sh` if you need to deploy `scaricatore` to some server using `SSH`.
|
||||||
5. Run it: `node .`
|
|
||||||
6. You can also try to configure the systemd unit file inside the `configurations` folder.
|
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
|
@ -25,8 +26,8 @@ It's a svelte(kit) frontend that uses `yt-dlp` to let the user download things f
|
||||||
|
|
||||||
## Development: getting started
|
## Development: getting started
|
||||||
|
|
||||||
- Clone the repo
|
- run `git clone git@git.pweapon.org:odo/dl.emersa.it.git`
|
||||||
- Run `npm install` (you have to have node installed)
|
- Run `cd dl.emersa.it; 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
|
||||||
|
@ -35,7 +36,6 @@ It's a svelte(kit) frontend that uses `yt-dlp` to let the user download things f
|
||||||
|
|
||||||
## 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=<PROJECT_ROOT>
|
WorkingDirectory=/home/user/downloader
|
||||||
ExecStart=/usr/bin/node <PROJECT_ROOT>
|
EnvironmentFile=/home/user/downloader/.env
|
||||||
Environment=ORIGIN=http://example.com
|
ExecStart=/usr/bin/node /home/user/downloader
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StandardOutput=syslog
|
StandardOutput=syslog
|
||||||
|
@ -16,3 +16,4 @@ SyslogIdentifier=downloader
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
|
|
1635
package-lock.json
generated
1635
package-lock.json
generated
File diff suppressed because it is too large
Load diff
46
package.json
46
package.json
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "dl.emersa.it",
|
"name": "dl.emersa.it",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.5",
|
"version": "1.0.0-c",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"download-yt-dlp": "wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O yt-dlp",
|
"download-yt-dlp": "wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -O yt-dlp ; chmod +x yt-dlp",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"prepare": "svelte-kit sync || echo ''",
|
"prepare": "svelte-kit sync || echo ''",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
|
@ -15,32 +15,34 @@
|
||||||
"lint": "prettier --check . && eslint ."
|
"lint": "prettier --check . && eslint ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^1.2.5",
|
"@eslint/compat": "^1.2.8",
|
||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.25.0",
|
||||||
"@sveltejs/adapter-node": "^5.2.11",
|
"@sveltejs/adapter-node": "^5.2.12",
|
||||||
"@sveltejs/kit": "^2.16.0",
|
"@sveltejs/kit": "^2.20.7",
|
||||||
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
||||||
"@tailwindcss/vite": "^4.0.0",
|
"@tailwindcss/vite": "^4.1.4",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^9.25.0",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-config-prettier": "^10.1.2",
|
||||||
"eslint-plugin-svelte": "^2.46.1",
|
"eslint-plugin-svelte": "^3.5.1",
|
||||||
"globals": "^15.14.0",
|
"globals": "^16.0.0",
|
||||||
"mdsvex": "^0.12.3",
|
"mdsvex": "^0.12.3",
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.5.3",
|
||||||
"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.0.0",
|
"svelte": "^5.28.1",
|
||||||
"svelte-check": "^4.0.0",
|
"svelte-check": "^4.1.6",
|
||||||
"tailwindcss": "^4.0.0",
|
"sveltekit-sse": "^0.13.18",
|
||||||
"typescript": "^5.0.0",
|
"tailwindcss": "^4.1.4",
|
||||||
"typescript-eslint": "^8.20.0",
|
"typescript": "^5.8.3",
|
||||||
"vite": "^6.0.0"
|
"typescript-eslint": "^8.30.1",
|
||||||
|
"vite": "^6.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/forms": "^0.5.10",
|
"@tailwindcss/forms": "^0.5.10",
|
||||||
"@tailwindcss/postcss": "^4.0.8",
|
"@tailwindcss/postcss": "^4.1.4",
|
||||||
"@tailwindcss/typography": "^0.5.16",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@types/node": "^22.13.5",
|
"@types/node": "^22.14.1",
|
||||||
"youtube-dl-exec": "^3.0.15"
|
"winston": "^3.17.0",
|
||||||
|
"youtube-dl-exec": "^3.0.20"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
|
||||||
# An example hook script to verify what is about to be committed.
|
## Prepares the current environment:
|
||||||
# Called by "git commit" with no arguments. The hook should
|
## - Installing dependencies
|
||||||
# exit with non-zero status after issuing an appropriate message if
|
## - Configuring git hooks
|
||||||
# it wants to stop the commit.
|
|
||||||
#
|
|
||||||
# To enable this hook, rename this file to "pre-commit".
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,23 @@
|
||||||
#!/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)"
|
||||||
|
|
||||||
NO_DELETE=false
|
|
||||||
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}"
|
||||||
|
|
||||||
for arg in "$@"
|
ssh "${SSH_SERVER}" "mkdir -p ${PROJECT_ROOT}"
|
||||||
do
|
rsync "${__dir}/install.sh" "${SSH_SERVER}:${PROJECT_ROOT}/install.sh"
|
||||||
if [ "$arg" == "--no-delete" ]; then
|
ssh "${SSH_SERVER}" "${PROJECT_ROOT}/install.sh ${PROJECT_ROOT}"
|
||||||
NO_DELETE=true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$NO_DELETE" = false ]; then
|
|
||||||
echo "Deleting node_modules..."
|
|
||||||
rm -rf node_modules/
|
|
||||||
else
|
|
||||||
echo "Skipping deletion of node_modules."
|
|
||||||
fi
|
|
||||||
|
|
||||||
npm ci
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
rsync -r --delete --progress build/ "${SSH_REMOTE_DIR}"
|
|
||||||
rsync package.json "${SSH_REMOTE_DIR}"
|
|
||||||
rsync package-lock.json "${SSH_REMOTE_DIR}"
|
|
||||||
|
|
||||||
ssh "${SSH_SERVER}" "cd ${PROJECT_ROOT}; npm ci"
|
|
||||||
ssh "${SSH_SERVER}" "systemctl restart downloader"
|
ssh "${SSH_SERVER}" "systemctl restart downloader"
|
33
scripts/install.sh
Executable file
33
scripts/install.sh
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
### This is a script for installing the latest release
|
||||||
|
### of `scaricatore`.
|
||||||
|
|
||||||
|
PROJECT_ROOT=$1
|
||||||
|
PROXY=$2
|
||||||
|
|
||||||
|
if [ -z ${PROJECT_ROOT+x} ]; then
|
||||||
|
echo "ERROR: No PROJECT_ROOT set (first argument to ${0})"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${PROXY+x} ]; then
|
||||||
|
echo "INFO: no proxy given"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${PROJECT_ROOT}"
|
||||||
|
cd "${PROJECT_ROOT}" || exit 1
|
||||||
|
|
||||||
|
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
|
||||||
|
tar -xvf build.tar.gz -C .
|
||||||
|
rm build.tar.gz
|
||||||
|
npm ci
|
||||||
|
npm run download-yt-dlp
|
||||||
|
echo "YTDLP_PATH=$(readlink -f yt-dlp)" >> .env.production
|
||||||
|
echo "HTTPS_PROXY=${PROXY}" >> .env.production
|
|
@ -7,14 +7,11 @@
|
||||||
<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: 'Press Start 2P';
|
font-family: 'Fira Code', monospace;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
7
src/hooks.server.ts
Normal file
7
src/hooks.server.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
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);
|
||||||
|
}
|
21
src/lib/client/downloader.ts
Normal file
21
src/lib/client/downloader.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
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);
|
||||||
|
};
|
6
src/lib/common/supportedFormats.json
Normal file
6
src/lib/common/supportedFormats.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"mp3": "audio/mpeg",
|
||||||
|
"opus": "audio/ogg",
|
||||||
|
"wav": "audio/wav",
|
||||||
|
"mp4": "video/mp4"
|
||||||
|
}
|
|
@ -1,3 +1,73 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
let props = $props();
|
import { onMount } from 'svelte';
|
||||||
|
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,6 +1,28 @@
|
||||||
<div
|
<div class="w-[150px]">
|
||||||
class="bg-opacity-50 absolute inset-0 z-10 flex items-center justify-center bg-white"
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"
|
||||||
id="spinner"
|
><linearGradient id="a3"
|
||||||
>
|
><stop offset="0" stop-color="#FF156D" stop-opacity="0"></stop><stop
|
||||||
<div class="h-20 w-20 animate-spin rounded-full border-t-2 border-b-2 border-gray-900"></div>
|
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
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
19
src/lib/server/helpers.ts
Normal file
19
src/lib/server/helpers.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import formats from '$lib/common/supportedFormats.json';
|
||||||
|
import winston from 'winston';
|
||||||
|
|
||||||
|
export const logger = winston.createLogger({
|
||||||
|
level: 'debug',
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
export const mimeTypeMap = formatMime;
|
|
@ -1,7 +1,11 @@
|
||||||
import { create } from 'youtube-dl-exec';
|
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 { logger, 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);
|
||||||
|
|
||||||
|
@ -9,37 +13,73 @@ 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) {
|
||||||
return await ytdl(link, {
|
const options = {
|
||||||
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);
|
||||||
|
|
||||||
|
if (!mimeType) {
|
||||||
|
throw new Error('Unsupported format');
|
||||||
|
}
|
||||||
|
logger.debug(`Given format is compatible: ${mimeType}`);
|
||||||
|
|
||||||
return new ReadableStream({
|
return new ReadableStream({
|
||||||
start(controller) {
|
start(controller) {
|
||||||
const args = [
|
const args = ['--no-write-thumbnail', '-o', '-'];
|
||||||
'-o',
|
|
||||||
'-',
|
|
||||||
format === 'mp3' ? '--embed-metadata' : '',
|
|
||||||
'--format',
|
|
||||||
format === 'mp3' ? 'bestaudio' : 'best',
|
|
||||||
'--audio-format',
|
|
||||||
format === 'mp3' ? 'mp3' : '',
|
|
||||||
'--no-playlist'
|
|
||||||
].filter(Boolean);
|
|
||||||
|
|
||||||
const process = spawn('yt-dlp', [...args, link], { stdio: ['ignore', 'pipe', 'ignore'] });
|
if (HTTPS_PROXY) {
|
||||||
|
args.push('--proxy', HTTPS_PROXY);
|
||||||
|
}
|
||||||
|
|
||||||
process.stdout.on('data', (chunk) => controller.enqueue(chunk));
|
if (mimeType?.includes('audio')) {
|
||||||
process.stdout.on('end', () => controller.close());
|
args.push(
|
||||||
|
...['--extract-audio', '--embed-metadata', '--embed-thumbnail', '--audio-format', format]
|
||||||
|
);
|
||||||
|
} else if (mimeType.includes('video')) {
|
||||||
|
args.push(...['--embed-metadata', '--embed-thumbnail', '--format', format]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cmd = `${YTDLP_PATH} ${args.join(' ')} ${link}`;
|
||||||
|
logger.debug(`Running: ${cmd}`);
|
||||||
|
|
||||||
|
const process = spawn(YTDLP_PATH, [...args, link], {
|
||||||
|
cwd: '/tmp',
|
||||||
|
stdio: ['ignore', 'pipe', 'pipe']
|
||||||
|
});
|
||||||
|
|
||||||
|
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('error', (err) => {
|
process.stdout.on('error', (err) => {
|
||||||
console.error('Stream error:', err);
|
logger.error('Stream error:', err);
|
||||||
controller.error(err);
|
controller.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,11 @@
|
||||||
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>
|
||||||
|
|
3
src/routes/+page.server.ts
Normal file
3
src/routes/+page.server.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const prerender = true;
|
||||||
|
export const ssr = true;
|
||||||
|
export const csr = true;
|
|
@ -1,35 +1,77 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {PUBLIC_VERSION} from '$env/static/public';
|
import { PUBLIC_VERSION } from '$env/static/public';
|
||||||
|
import supportedFormats from '$lib/common/supportedFormats.json';
|
||||||
|
import Loader from '$lib/components/Loader.svelte';
|
||||||
|
import { download } from '$lib/client/downloader';
|
||||||
|
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('');
|
||||||
let format = $state('mp3');
|
let format = $state('mp3');
|
||||||
let showModal = $state(false);
|
let showModal = $state(false);
|
||||||
let href = $state('');
|
let href = $state('');
|
||||||
// let formats = ['ogg', 'mp3', 'mp4']
|
let disabled = $state(true);
|
||||||
const formats = [{ value: 'mp3', label: 'MP3' }];
|
let metadata = $state(false);
|
||||||
|
let logs = $state('');
|
||||||
|
let downloadManager: DownloadManager | null = null;
|
||||||
|
|
||||||
|
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 = () => {
|
const toggleModal = () => {
|
||||||
showModal = !showModal;
|
showModal = !showModal;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e: SubmitEvent) => {
|
const dismiss = () => {
|
||||||
e.preventDefault();
|
unmount(downloadManager);
|
||||||
|
};
|
||||||
|
|
||||||
console.log({
|
const onClick = async (evt) => {
|
||||||
source,
|
evt.preventDefault();
|
||||||
link,
|
|
||||||
format
|
const props = $state({ url: href });
|
||||||
});
|
downloadManager = mount(DownloadManager, { target: document.body, props, events: { dismiss } });
|
||||||
|
|
||||||
|
link = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const createAnchor = () => {
|
||||||
|
if (!(source && link && format)) {
|
||||||
|
disabled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new URL(link);
|
||||||
|
disabled = false;
|
||||||
|
} catch (err) {
|
||||||
|
/*
|
||||||
|
if (err.code === 'ERR_INVALID_URL') {
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
disabled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
searchParams.append('source', source);
|
searchParams.append('source', source);
|
||||||
searchParams.append('link', link);
|
searchParams.append('link', link);
|
||||||
searchParams.append('format', format);
|
searchParams.append('format', format);
|
||||||
|
|
||||||
|
if (metadata) searchParams.append('metadata', '1');
|
||||||
|
|
||||||
href = `/download?${searchParams.toString()}`;
|
href = `/download?${searchParams.toString()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
|
createAnchor();
|
||||||
// Auto selected the radio button based on url regex
|
// Auto selected the radio button based on url regex
|
||||||
if (link.includes('spotify')) {
|
if (link.includes('spotify')) {
|
||||||
source = 'spotify';
|
source = 'spotify';
|
||||||
|
@ -41,166 +83,130 @@
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="wrapper"
|
id="wrapper"
|
||||||
class="relative mx-auto rounded-lg bg-black p-6 text-green-500 shadow-lg sm:max-w-sm sm:border-4 sm:border-green-500 md:mt-10 md:max-w-md lg:max-w-lg 2xl:max-w-2xl"
|
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"
|
||||||
>
|
>
|
||||||
<!-- Info Icon -->
|
<!-- Loader Overlay -->
|
||||||
|
<div
|
||||||
|
id="loader"
|
||||||
|
class="absolute inset-0 z-10 hidden items-center justify-center bg-black/80 backdrop-blur-sm"
|
||||||
|
>
|
||||||
|
<Loader />
|
||||||
|
{@html logs}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Info Button -->
|
||||||
<button
|
<button
|
||||||
onclick={toggleModal}
|
onclick={toggleModal}
|
||||||
class="absolute top-3 right-3 text-pink-500 transition hover:text-pink-300"
|
class="absolute top-3 right-3 text-pink-500 transition hover:text-pink-400"
|
||||||
aria-label="Open Info Modal"
|
aria-label="Open Info Modal"
|
||||||
>
|
>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="h-6 w-6" viewBox="0 0 24 24">
|
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="h-5 w-5" 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>
|
||||||
|
|
||||||
<h1 id="title" class="mb-6 text-center text-xl">🐙 Scaricatore 🐙</h1>
|
<!-- Title -->
|
||||||
<form class="space-y-6" onsubmit={handleSubmit}>
|
<p id="title" class="mb-4 text-center font-mono text-xl tracking-tight text-cyan-300">
|
||||||
<!-- Source Selection -->
|
🐙 Scaricatore 🐙
|
||||||
<fieldset class="space-y-4">
|
</p>
|
||||||
<legend class="text-green-400">Choose Source:</legend>
|
|
||||||
|
|
||||||
<label class="flex items-center space-x-3">
|
<!-- Form -->
|
||||||
<input type="radio" name="source" value="youtube" bind:group={source} class="retro-radio" />
|
<form class="space-y-5 font-mono text-sm">
|
||||||
<span>YouTube</span>
|
<!-- Source & Format -->
|
||||||
</label>
|
<div class="flex flex-col gap-4 sm:flex-row">
|
||||||
|
<div class="flex-1">
|
||||||
<label class="flex items-center space-x-3">
|
<label for="source" class="mb-1 block text-cyan-300">Source</label>
|
||||||
<input
|
<select
|
||||||
disabled
|
id="source"
|
||||||
type="radio"
|
|
||||||
name="source"
|
name="source"
|
||||||
value="spotify"
|
bind:value={source}
|
||||||
bind:group={source}
|
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"
|
||||||
class="retro-radio"
|
>
|
||||||
/>
|
{#each sources as source}
|
||||||
<span class="not-available">Spotify</span>
|
<option value={source.value}>{source.label}</option>
|
||||||
</label>
|
{/each}
|
||||||
|
</select>
|
||||||
<label class="flex items-center space-x-3">
|
|
||||||
<input type="radio" name="source" value="other" bind:group={source} class="retro-radio" />
|
|
||||||
<span>
|
|
||||||
Other (<a
|
|
||||||
href="https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
class="text-pink-500 hover:underline"
|
|
||||||
>supported sites
|
|
||||||
</a>)
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<!-- Link Input -->
|
|
||||||
<div>
|
|
||||||
<label for="link" class="mb-2 block text-green-400"> Enter Playlist or Video Link: </label>
|
|
||||||
<input
|
|
||||||
name="link"
|
|
||||||
type="url"
|
|
||||||
id="link"
|
|
||||||
bind:value={link}
|
|
||||||
required
|
|
||||||
placeholder="Paste your link here"
|
|
||||||
class="w-full rounded-lg border-4 border-green-500 bg-green-200 px-4 py-3 text-black focus:border-pink-500 focus:outline-none"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Format Selection -->
|
<div class="flex-1">
|
||||||
<div>
|
<label for="format" class="mb-1 block text-cyan-300">Format</label>
|
||||||
<label for="format" class="mb-2 block text-green-400"> Choose Format: </label>
|
|
||||||
<select
|
<select
|
||||||
id="format"
|
id="format"
|
||||||
name="format"
|
name="format"
|
||||||
bind:value={format}
|
bind:value={format}
|
||||||
class="w-full rounded-lg border-4 border-green-500 bg-green-200 px-4 py-3 text-black focus:border-pink-500 focus:outline-none"
|
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"
|
||||||
>
|
>
|
||||||
{#each formats as format}
|
{#each formats as format}
|
||||||
<option value={format.value}>{format.label}</option>
|
<option value={format.value}>{format.label}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Submit Button -->
|
<!-- Video Link -->
|
||||||
<button
|
<div>
|
||||||
type="submit"
|
<label for="link" class="mb-1 block text-cyan-300">Video Link</label>
|
||||||
class="w-full rounded-lg border-4 border-pink-700 bg-pink-500 px-4 py-3 text-black transition hover:bg-pink-600 active:border-yellow-500"
|
<input
|
||||||
|
type="url"
|
||||||
|
id="link"
|
||||||
|
name="link"
|
||||||
|
bind:value={link}
|
||||||
|
required
|
||||||
|
placeholder="https://..."
|
||||||
|
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"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Metadata Checkbox -->
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="metadata"
|
||||||
|
name="metadata"
|
||||||
|
bind:checked={metadata}
|
||||||
|
class="h-4 w-4 border border-green-400 bg-[#000f00] text-green-500 focus:ring-pink-400"
|
||||||
|
/>
|
||||||
|
<label for="metadata" class="text-cyan-300"
|
||||||
|
>Set filename (<span class="text-red-500">slow</span>)</label
|
||||||
>
|
>
|
||||||
Create download link
|
</div>
|
||||||
</button>
|
|
||||||
|
|
||||||
{#if href}
|
<!-- Download Button -->
|
||||||
<a class="download-link" {href}> Download </a>
|
<a
|
||||||
{/if}
|
id="btn-download"
|
||||||
|
{href}
|
||||||
|
onclick={onClick}
|
||||||
|
class="{disabled
|
||||||
|
? 'pointer-events-none opacity-50'
|
||||||
|
: ''} 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"
|
||||||
|
>
|
||||||
|
DOWNLOAD
|
||||||
|
</a>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
{#if showModal}
|
{#if showModal}
|
||||||
<div class="bg-opacity-80 fixed inset-0 z-50 flex items-center justify-center bg-black">
|
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 text-green-300">
|
||||||
<div
|
<div class="w-[90%] max-w-md rounded-lg border border-green-400 bg-[#001a00] p-5 text-center">
|
||||||
class="w-4/5 max-w-lg rounded-lg border-4 border-green-500 bg-green-900 p-6 text-center text-green-100"
|
<h2 class="mb-3 text-base font-semibold">🐙 Scaricatore v{PUBLIC_VERSION} 🐙</h2>
|
||||||
>
|
|
||||||
<h2 class="mb-4 text-lg">🐙 Scaricatore v{PUBLIC_VERSION} 🐙</h2>
|
|
||||||
<p>
|
<p>
|
||||||
This app allows you to download Spotify playlists and YouTube videos directly. Choose your
|
Download Spotify playlists and YouTube videos with ease. Choose your source, paste a link,
|
||||||
source, paste the link, and select a format to start downloading!
|
select format, go!
|
||||||
</p>
|
</p>
|
||||||
<span class="mt-10 block">
|
<p class="mt-3">
|
||||||
<a class="underline" href="https://git.pweapon.org/odo/dl.emersa.it"
|
<a class="text-cyan-400 underline" href="https://git.pweapon.org/odo/dl.emersa.it"
|
||||||
>Click here for the source code</a
|
>Source Code</a
|
||||||
>
|
>
|
||||||
</span>
|
</p>
|
||||||
<button
|
<button
|
||||||
onclick={toggleModal}
|
onclick={toggleModal}
|
||||||
class="mt-6 rounded-lg border-4 border-pink-700 bg-pink-500 px-4 py-2 text-black hover:bg-pink-600"
|
class="mt-6 rounded-md border border-pink-400 bg-pink-600 px-4 py-2 text-black hover:bg-pink-500"
|
||||||
>
|
>
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
|
||||||
* {
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.download-link {
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 5px;
|
|
||||||
display: block;
|
|
||||||
text-decoration: underline;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.not-available {
|
|
||||||
text-decoration-line: line-through;
|
|
||||||
text-decoration-color: red;
|
|
||||||
}
|
|
||||||
|
|
||||||
.retro-radio {
|
|
||||||
appearance: none;
|
|
||||||
background-color: #000;
|
|
||||||
border: 2px solid #39ff14;
|
|
||||||
width: 20px;
|
|
||||||
height: 20px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.retro-radio:checked {
|
|
||||||
background-color: #39ff14;
|
|
||||||
box-shadow:
|
|
||||||
0 0 4px #39ff14,
|
|
||||||
0 0 10px #39ff14;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type='url'],
|
|
||||||
select {
|
|
||||||
font-family: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
#title {
|
|
||||||
font-size: 22px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,12 +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 } from '$lib/server/ytdlp';
|
import { getYouTubeMetadata, streamYouTube, ytdl } from '$lib/server/ytdlp';
|
||||||
|
import { isURLValid, logger, mimeTypeMap } from '$lib/server/helpers';
|
||||||
|
|
||||||
export const GET: RequestHandler = async ({ url }) => {
|
const validateRequest = (url: 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');
|
||||||
|
|
||||||
// Validate input
|
// Validate input
|
||||||
if (!link || !format || !source) {
|
if (!link || !format || !source) {
|
||||||
|
@ -17,23 +19,56 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||||
throw error(400, 'Currently, only YouTube is supported');
|
throw error(400, 'Currently, only YouTube is supported');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!isURLValid(link)) {
|
||||||
// Fetch metadata for filename
|
throw error(400, 'URL not valid');
|
||||||
const metadata = await getYouTubeMetadata(link);
|
}
|
||||||
const { title, uploader } = metadata;
|
|
||||||
const safeTitle = `${uploader} - ${title}`;
|
|
||||||
const filename = `${safeTitle}.${format}`;
|
|
||||||
|
|
||||||
console.log(filename);
|
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;
|
||||||
|
|
||||||
|
logger.debug(`Requested: ${link}`);
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Stream video/audio
|
// Stream video/audio
|
||||||
return new Response(streamYouTube(link, format), {
|
return new Response(streamYouTube(link, format), {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': format === 'mp3' ? 'audio/mpeg' : 'video/mp4',
|
'Content-Type': `${mimeTypeMap.get(format)}`,
|
||||||
|
'Content-Length': contentLength,
|
||||||
'Content-Disposition': `attachment; filename="${filename}"`
|
'Content-Disposition': `attachment; filename="${filename}"`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error fetching metadata:', err);
|
logger.error(err);
|
||||||
throw error(500, 'Failed to fetch video metadata');
|
logger.error('Filed to stream file');
|
||||||
|
throw error(500, 'Failed to stream file');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 11 KiB |
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "EmersaDownloader",
|
"name": "scaricatore",
|
||||||
"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": "e-downloader",
|
"short_name": "scaricatore",
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "favicon.png",
|
"src": "favicon.png",
|
||||||
"type": "image/png",
|
"type": "image/png",
|
||||||
"sizes": "128x128"
|
"sizes": "512x512"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 14 KiB |
Loading…
Add table
Add a link
Reference in a new issue