scripts

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

commit d3911b2285e0ba270b7efd82a290c75c2ab7f1bb
parent 76a9e713daf894ef88637c74bcebdd6c25292a83
Author: sin <sin@2f30.org>
Date:   Mon Nov  4 15:02:16 +0000

Simplify code and handle playlists as well

Diffstat:
ytget | 23++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/ytget b/ytget @@ -1,6 +1,6 @@ #!/bin/sh # -# Simple script to download videos from youtube and convert +# Simple script to download videos from youtube and encode # them to mp3 using ffmpeg. out=$HOME/music/yt @@ -17,19 +17,23 @@ which ffmpeg >/dev/null || \ { echo "I can't find ffmpeg, please install it" 1>&2; exit 1; } mkdir -p "$out" +scratch=$(mktemp -d) -trap 'rm -f "/tmp/$infile.part" "$out/$outfile"; exit 1' 2 +# Download all songs to the scratch space +for i in "$@"; do + youtube-dl -o "$scratch/%(title)s.%(ext)s" "$i" +done -function convert { +function encode { in="$1" out="$2" ffmpeg -i "$in" "$out" } -for i in "$@"; do - infile=$(youtube-dl --get-filename -o "%(title)s.%(ext)s" "$i") - outfile="${infile%.*}.mp3" - youtube-dl "$i" -o "/tmp/$infile" - convert "/tmp/$infile" "$out/$outfile" - rm "/tmp/$infile" +# Encode all of them +cd $scratch +for i in *; do + outfile="${i%.*}.mp3" + encode "$i" "$outfile" done +cd -+ \ No newline at end of file