Skip to content

Instantly share code, notes, and snippets.

@wolever
Last active February 4, 2016 21:06
Show Gist options
  • Save wolever/9d20e336180282ed5092 to your computer and use it in GitHub Desktop.
Save wolever/9d20e336180282ed5092 to your computer and use it in GitHub Desktop.
youtube2podcast: turn YouTube videos into a podcast

A couple of scripts I use to turn YouTube videos into podcasts.

Example:

$ youtube2podcast https://www.youtube.com/watch?v=p22LSKPUxJk https://www.youtube.com/watch?v=zEqDbsPUgH8
...
Starting podcast server...
http://0.0.0.0:9431/youtube-podcast

Requires avconv, youtube-dl, and dir2podcast:

$ brew install avconv
$ pip install youtube-dl
$ pip install https://github.com/wolever/dir2podcast/archive/master.zip
#!/bin/bash
IFS="`printf "\n\t"`"
set -eu
TEMPDIR="$PWD" outputdir="$(mktemp -d youtube2mp3-XXXX)"
trap "rm -rf '$PWD/$outputdir' 2>&1 > /dev/null" EXIT
if [[ -z "${1-}" ]]; then
echo "usage: $0 --video YOUTUBE_URL [YOUTUBE_URL ...]"
exit 1
fi
last_is_video=0
while [[ "$#" -gt 0 ]]; do
if [[ "$1" == "--video" || "$1" == "-v" ]]; then
last_is_video=1
shift
continue
fi
url="$1"
shift
if [[ -d "$outputdir" ]]; then
rm -r "$outputdir"
fi
mkdir "$outputdir"
pushd "$outputdir" > /dev/null
if [[ "$last_is_video" -eq 0 ]]; then
youtube-dl --format=worst -v "$url"
video="$(echo *)"
audio="${video%.*}.mp3"
avconv -i "$video" "$audio"
else
youtube-dl -v "$url"
video="$(echo *)"
mkdir outdir
video-to-iphone -o outdir "$video"
audio="$(find outdir | head -n1)"
fi
popd > /dev/null
mv "$outputdir/$audio" .
echo "SAVED: $audio"
rm -r "$outputdir"
done
#!/bin/bash
# usage: youtube2podcast https://www.youtube.com/watch?v=p22LSKPUxJk https://www.youtube.com/watch?v=zEqDbsPUgH8
IFS="`printf "\n\t"`"
set -eu
cd ~/tmp/youtube-podcast/
if [[ "${1-}" != "-s" ]]; then
youtube2mp3 "${@}"
fi
echo "Starting podcast server..."
~/code/dir2podcast/dir2podcast "$PWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment