Skip to content

Instantly share code, notes, and snippets.

@nejni-marji
Created June 16, 2016 17:35
Show Gist options
  • Save nejni-marji/09ae213ea3df4a8922b60cef9207cff4 to your computer and use it in GitHub Desktop.
Save nejni-marji/09ae213ea3df4a8922b60cef9207cff4 to your computer and use it in GitHub Desktop.
#!/bin/bash
#set -x
# {{{ getopts
while getopts ":i::o:p" VAR ; do
case $VAR in
i) # --input-file
export PLYDL_INPUT=$OPTARG
;;
o) # --output-file
export PLYDL_OUTPUT=$OPTARG
;;
esac
done
# }}}
# {{{ setopts
if [[ -z "$PLYDL_INPUT" ]] ; then
echo "No input file selected, exiting"
export PLYDL_INPUT=plydl_input.txt # Default needed for -p
exit
fi
if [[ -z "$PLYDL_OUTPUT" ]] ; then
export PLYDL_OUTPUT=playlist.m3u
fi
# }}}
export PLYDL_LEN=`cat $PLYDL_INPUT | wc -l`
touch $PLYDL_OUTPUT && rm $PLYDL_OUTPUT
# {{{ download and make
for PLYDL_VIDEO in `seq 1 2 $PLYDL_LEN` ; do
export PLYDL_TITLE_NUM=$PLYDL_VIDEO
export PLYDL_ID_NUM=$(($PLYDL_VIDEO + 1))
export PLYDL_TITLE="`sed $PLYDL_TITLE_NUM'p;d' $PLYDL_INPUT`"
export PLYDL_ID="`sed $PLYDL_ID_NUM'p;d' $PLYDL_INPUT`"
youtube-dl --ignore-errors --output "%(id)s.%(ext)s" -- $PLYDL_ID
export PLYDL_FILE="`find $PWD | grep -- $PLYDL_ID`"
echo "#EXTM3U" >> $PLYDL_OUTPUT
echo "#EXTINF:,$PLYDL_TITLE" >> $PLYDL_OUTPUT
echo "$PLYDL_FILE" >> $PLYDL_OUTPUT
echo "#EXTM3U"
echo "#EXTINF:,$PLYDL_TITLE"
echo "$PLYDL_FILE"
done
# }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment