Skip to content

About

Make your own YouTube Downloader Mp3 Site

Topics

Resources

Stars

8 stars

Watchers

2 watching

Forks

Repository files navigation

YouTube Downloader PHP

Make your own YouTube Downloader Mp3 Site

Requisites

Install ffmpeg, yt-dlp & Deno for video and audio conversions

Linux (Ubuntu / Debian / WSL)

Don't install yt-dlp with apt. The distribution package is usually outdated, and YouTube breaks old versions quickly (errors like HTTP Error 400: Precondition check failed or Requested format is not available).

Install ffmpeg, the SQLite PHP extension and the tools the installers below need:

sudo apt install -y ffmpeg curl unzip php8.4-sqlite3   # use the package for your PHP version

Install the official yt-dlp binary in /usr/local/bin, so every user, including the web server user (www-data), can find it. It is downloaded to a temporary file first, so a failed download does not break an existing installation:

case "$(uname -m)" in aarch64|arm64) asset=yt-dlp_linux_aarch64 ;; *) asset=yt-dlp_linux ;; esac
curl -fL -o /tmp/yt-dlp "https://github.com/yt-dlp/yt-dlp/releases/latest/download/$asset" \
  && sudo install -m 0755 /tmp/yt-dlp /usr/local/bin/yt-dlp \
  && rm /tmp/yt-dlp

If you previously installed yt-dlp with apt, remove it:

sudo apt remove -y yt-dlp

Install Deno system-wide:

curl -fsSL -o /tmp/deno-install.sh https://deno.land/install.sh \
  && sudo DENO_INSTALL=/usr/local sh /tmp/deno-install.sh \
  && rm /tmp/deno-install.sh

Check the installation:

yt-dlp --version
deno --version
ffmpeg -version

Keep yt-dlp up to date. When downloads stop working, updating it is usually the fix:

sudo yt-dlp -U

Mac

brew install ffmpeg yt-dlp deno

Update with brew upgrade yt-dlp.

Install Website

Copy the distributed environment file and set up the DB variables

cp .env.example .env

SQLite is used by default (requires the pdo_sqlite PHP extension). DB_DATABASE can be a path relative to the project root (default database/ydownload.sqlite). Create the empty database file at the path configured in DB_DATABASE, for the default:

touch database/ydownload.sqlite

Run composer, set the key and run the migrations

composer install
php artisan key:generate   # only on a fresh install: it replaces an existing APP_KEY
php artisan migrate

yt-dlp settings

Optional .env variables (see config/services.php):

Variable Default Description
YTDLP_BINARY yt-dlp Path to yt-dlp. Use an absolute path (/usr/local/bin/yt-dlp) when served by a web server, whose user may have a different PATH
FFMPEG_LOCATION (PATH) Path to ffmpeg, if it is not in PATH
YTDLP_FORMAT bestaudio[ext=m4a]/bestaudio Audio format to download before converting to MP3
YTDLP_TIMEOUT 300 Maximum seconds for a download

Permissions for the web server

When the site is served by a web server (e.g. www-data) instead of php artisan serve, it needs write access to storage, bootstrap/cache, the SQLite file and its directory (SQLite creates journal files next to the database):

sudo chgrp -R www-data storage bootstrap/cache database
sudo chmod -R g+rwX storage bootstrap/cache
sudo chmod g+rwx database && sudo chmod g+rw database/ydownload.sqlite

Or run make permissions (set WEB_GROUP=... for a different group).

Using the Makefile

The same steps are available as make targets (run make to list them all):

make system-deps   # ffmpeg, curl, unzip, yt-dlp and Deno (Ubuntu / Debian / WSL, uses sudo)
make install       # composer, .env, APP_KEY, SQLite DB and migrations
make check         # show versions of php, yt-dlp, deno, ffmpeg and pdo_sqlite
make ytdlp-update  # update yt-dlp when downloads stop working
make serve         # start the development server
make test          # run the tests

Local test

php artisan serve

Login

Disable Auth in HomePage

Login Just comment this line __construct of HomeController.php

//$this->middleware('auth');

About

Make your own YouTube Downloader Mp3 Site

Topics

Resources

Stars

8 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages