scripts

misc scripts and tools
git clone git://git.2f30.org/scripts.git
Log | Files | Refs

commit eaaf9c4f63e2ccc4e5ab62ece4ea09f32a272a9f
parent cfe2ebf1bd441a49ad2f67cf661b2904cb0b6fd2
Author: lostd <lostd@2f30.org>
Date:   Thu Nov  7 16:40:28 +0200

rewrite with a per video loop in mind, also no dir config

Diffstat:
ytfetch | 59++++++++++++++++++++++++++++++++---------------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/ytfetch b/ytfetch @@ -1,34 +1,39 @@ #!/bin/sh -# -# Simple script to download songs from youtube and encode -# them to mp3 using ffmpeg. This script also handles playlists. -# -# By default the script writes the encoded files to $HOME/music/yt -# Set the YTDIR enviroment var for a different location. -YTDIR=$(test -n "$YTDIR" && echo "$YTDIR" || echo $HOME/music/yt) +# fetch music videos and convert them to audio files +# it also handles playlists +# depends: youtube-dl ffmpeg wget if test -z "$1"; then - echo "usage: $(basename $0) yt-url..." 1>&2 - exit 1 + echo "usage: $(basename $0) yturl ..." 1>&2 + exit 1 fi -# Check for dependencies -which youtube-dl >/dev/null || \ - { echo "I can't find youtube-dl, please install it" 1>&2; exit 1; } -which ffmpeg >/dev/null || \ - { echo "I can't find ffmpeg, please install it" 1>&2; exit 1; } - -scratch=$(mktemp -d) - -# Download all songs to the scratch space -for v in "$@"; do - youtube-dl -o "$scratch/%(title)s.%(ext)s" "$v" +for URL in "$@"; do + echo "see $URL" + # each --get comes on a line by its own in a predefined order + # command line order does not matter + LIST=$(youtube-dl --restrict-filenames --get-url --get-filename "$URL") + I=0 # keep state + for L in $LIST; do + case $I in + 0) + DIRECT="$L" + ;; + 1) + F="${L%.*}.mp3" + if test -f "$F"; then # already have this? + echo "hav $F" + else + echo "get $F" + wget "$DIRECT" -O "$L" 2> /dev/null + ffmpeg -i "$L" "$F" 2> /dev/null + rm "$L" + fi + ;; + esac + # incr and mod with the number of --get used above + I=$(expr $I + 1) + I=$(expr $I % 2) + done done - -mkdir -p $YTDIR - -# Encode all of them -cd $scratch -find . \( -name "*.mp4" -o -name "*.flv" \) -exec sh -c \ - 'ffmpeg -i "$0" "'$YTDIR'/${0%.*}.mp3"' {} \;