Skip to content

Instantly share code, notes, and snippets.

@MatMercer
Last active December 20, 2022 21:16
Show Gist options
  • Save MatMercer/99090a375795d8613fa0a6ea7aff7509 to your computer and use it in GitHub Desktop.
Save MatMercer/99090a375795d8613fa0a6ea7aff7509 to your computer and use it in GitHub Desktop.
Download youtube, twitter, youtube shorts, tiktok, reddit videos with termux app in android
#!/bin/sh
# helper script to download videos using termux and auto-indexing them
#
# required apps:
# termux: https://f-droid.org/en/packages/com.termux/
# termux-api: https://f-droid.org/en/packages/com.termux.api/
# required packages
# termux-api, python: apt install termux-api python python3
# yt-dlp: pip --upgrade install yt-dlp
[ $# -eq 0 ] && { echo "usage: $0 video-link"; exit 1; }
# setup the output path with what you want, shows up at the phone gallery
OUTPATH="/mnt/sdcard/Pictures/yt-dlp"
mkdir -p "$OUTPATH"
# vcodec:h264 has huge compatibility with wpp, telegram, instagram
yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" \
-S vcodec:h264 \
--force-overwrites \
--restrict-filenames \
--windows-filenames \
--no-mtime \
-P "$OUTPATH" "$1"
# adds the downloaded media to the phone gallery quietly and without hanging the script
termux-media-scan -r "$OUTPATH" > /dev/null &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment