Fast youtube download bash script using custom build of aria2
I made a script that downloads from youtube super fast using a custom aria2 build.
Aria2 github.com/P3TERX/Aria2-Pro-Core/releases
ffmpeg build github.com/yt-dlp/FFmpeg-Builds/releases
I choose ffmpeg-master-latest-linux64-gpl.tar.xz
<span style="color:#323232;">#!/usr/bin/env bash
</span><span style="color:#323232;">#set -x
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [[ -z $@ ]]; then
</span><span style="color:#323232;"> echo "specify download url"
</span><span style="color:#323232;"> exit
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span><span style="color:#323232;">dir_dl="$PWD"
</span><span style="color:#323232;">url="$@"
</span><span style="color:#323232;">
</span><span style="color:#323232;">ffmpeg_dir="$HOME/.local/bin.notpath/"
</span><span style="color:#323232;">download_archive_dir="$HOME/Videos/yt-dlp/"
</span><span style="color:#323232;">download_archive_filename=".yt-dlp-archived-done.txt"
</span><span style="color:#323232;">
</span><span style="color:#323232;">mkdir -p "$download_archive_dir"
</span><span style="color:#323232;">
</span><span style="color:#323232;">youtube_match_regex='^.*(youtube[.]com|youtu[.]be|youtube-nocookie[.]com).*$'
</span><span style="color:#323232;">
</span><span style="color:#323232;">if [[ "$1" =~ $youtube_match_regex ]]; then
</span><span style="color:#323232;"> url="$(echo "$@" | perl -pe 's/((?:http:|https:)*?//(?:www.|)(?:youtube.com|m.youtube.com|youtu.|#youtube-nocookie.com).*(?:c(?:hannel)?/|u(?:ser)?/|v=|v%3D|v/|(?:a|p)/(?:a|u)/d.*/|watch?|vi(?:=|/)|/#embed/|oembed?|be/|e/)([^&?%#/n]+)).*/$1/gm')"
</span><span style="color:#323232;"> yt-dlp
</span><span style="color:#323232;"> --check-formats
</span><span style="color:#323232;"> --clean-info-json
</span><span style="color:#323232;"> --download-archive "$download_archive_dir$download_archive_filename"
</span><span style="color:#323232;"> --embed-chapters
</span><span style="color:#323232;"> --embed-info-json
</span><span style="color:#323232;"> --embed-metadata
</span><span style="color:#323232;"> --embed-thumbnail
</span><span style="color:#323232;"> --external-downloader aria2c
</span><span style="color:#323232;"> --downloader-args
</span><span style="color:#323232;"> "aria2c:
</span><span style="color:#323232;"> --allow-piece-length-change=true
</span><span style="color:#323232;"> --check-certificate=false
</span><span style="color:#323232;"> --console-log-level=notice
</span><span style="color:#323232;"> --content-disposition-default-utf8=true
</span><span style="color:#323232;"> --continue=true
</span><span style="color:#323232;"> --disk-cache=8192
</span><span style="color:#323232;"> --download-result=full
</span><span style="color:#323232;"> --enable-mmap
</span><span style="color:#323232;"> --file-allocation=falloc
</span><span style="color:#323232;"> --lowest-speed-limit=100K
</span><span style="color:#323232;"> --max-concurrent-downloads=16
</span><span style="color:#323232;"> --max-connection-per-server=64
</span><span style="color:#323232;"> --max-mmap-limit=8192M
</span><span style="color:#323232;"> --max-resume-failure-tries=5
</span><span style="color:#323232;"> --max-file-not-found=2
</span><span style="color:#323232;"> --max-tries=3
</span><span style="color:#323232;"> --min-split-size=64K
</span><span style="color:#323232;"> --no-file-allocation-limit=8192M
</span><span style="color:#323232;"> --piece-length=64k
</span><span style="color:#323232;"> --realtime-chunk-checksum=false
</span><span style="color:#323232;"> --retry-on-400=true
</span><span style="color:#323232;"> --retry-on-403=true
</span><span style="color:#323232;"> --retry-on-406=true
</span><span style="color:#323232;"> --retry-on-unknown=true
</span><span style="color:#323232;"> --retry-wait=1
</span><span style="color:#323232;"> --split=32
</span><span style="color:#323232;"> --stream-piece-selector=geom
</span><span style="color:#323232;"> --summary-interval=0 "
</span><span style="color:#323232;"> --ffmpeg-location "$ffmpeg_dir"
</span><span style="color:#323232;"> --output "$dir_dl"'/%(channel)s/%(title)s_%(channel)s_%(upload_date>%Y-%m-%d)s_%(duration>%H-%M-%S)s_%(resolution)s.%(ext)s'
</span><span style="color:#323232;"> --prefer-free-formats
</span><span style="color:#323232;"> --remux-video mkv
</span><span style="color:#323232;"> --restrict-filenames
</span><span style="color:#323232;"> --sponsorblock-remove "filler,interaction,intro,music_offtopic,outro,preview,selfpromo,sponsor"
</span><span style="color:#323232;"> --sub-langs "en.*,live_chat"
</span><span style="color:#323232;"> --write-auto-subs
</span><span style="color:#323232;"> --write-description
</span><span style="color:#323232;"> --write-info-json
</span><span style="color:#323232;"> --write-playlist-metafiles
</span><span style="color:#323232;"> --write-subs
</span><span style="color:#323232;"> --write-thumbnail
</span><span style="color:#323232;"> "$url"
</span><span style="color:#323232;">else
</span><span style="color:#323232;"> yt-dlp
</span><span style="color:#323232;"> --download-archive "$download_archive_dir$download_archive_filename"
</span><span style="color:#323232;"> --embed-chapters
</span><span style="color:#323232;"> --ffmpeg-location "$ffmpeg_dir"
</span><span style="color:#323232;"> --http-chunk-size 10M
</span><span style="color:#323232;"> --output "$dir_dl/%(title)s_%(duration>%H-%M-%S)s_%(upload_date>%Y-%m-%d)s_%(resolution)s_URL_(%(id)s).%(ext)s"
</span><span style="color:#323232;"> --prefer-free-formats
</span><span style="color:#323232;"> --restrict-filenames
</span><span style="color:#323232;"> "$url"
</span><span style="color:#323232;">fi
</span><span style="color:#323232;">
</span>
Add comment