scripts

scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | README | LICENSE

commit 2c594366add68f26fcd1b059bf9569a12bade763
parent ee85fce4da3afbf83cd6756caae5545e98bcb26b
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 25 Feb 2023 10:46:45 +0100

added ytd script

Diffstat:
MREADME.adoc | 8++++++++
Abin/ytd | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/README.adoc b/README.adoc @@ -78,6 +78,14 @@ Uses mpv and youtube-dl to easily look up videos from command-line with an audio * mpv (https://github.com/mpv-player/mpv) * youtube-dl (https://github.com/ytdl-org/youtube-dl) +== ./bin/ytd + +Uses yt-dlp to easily download videos from youtube. Has options for audio-only files from youtube, can also download playlists, and allows for searches on either URL's or keywords. + +.Requires: + +* yt-dlp (https://github.com/yt-dlp/yt-dlp) + == ./bin/dl-album Used to download full albums by playlist. The script creates a directory with the bandname followed by a directory with albumname in which the playlist is saved as mp3 files. diff --git a/bin/ytd b/bin/ytd @@ -0,0 +1,45 @@ +#!/bin/bash + +is_playlist=0 +is_audio=0 +is_search=0 + +while getopts ":pas" arg; do + case $arg in + p) is_playlist=1;; + a) is_audio=1;; + s) is_search=1;; + *) echo "Unknown option -${OPTARG}";; + esac +done + +shift $((OPTIND-1)) +url=$* + +getUrl() { + if [[ -z "${url}" ]]; then + echo "Give the search criteria to download." >&2 + read -r url + url="${url}" + fi + + if [ "${is_search}" -eq 1 ]; then + url="ytsearch:${url}" + fi + echo "${url}" +} + +getArgs() { + if [ "${is_audio}" -eq 1 ]; then + echo "-x -f bestaudio" + fi +} + +url="$(getUrl)" +args="$(getArgs)" + +if [ "${is_playlist}" -eq 1 ]; then + yt-dlp ${args} -i -o "%(playlist_index)s - %(title)s.%(ext)s" "${url}" +else + yt-dlp --no-playlist ${args} -o "%(title)s.%(ext)s" "${url}" +fi