Skip to content

Commit

Permalink
Refactoring + new output file name convention
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlauro committed Jan 25, 2016
1 parent 20388af commit 9cb65dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
This bash script allows to extract video links from a YouTube playlist.

# Dependencies
The script requires [xml2](http://www.ofb.net/~egnor/xml2/), and
[wget](https://www.gnu.org/software/wget/) or [curl](http://curl.haxx.se/).
The script requires [wget](https://www.gnu.org/software/wget/) or [curl](http://curl.haxx.se/).

# Usage
Playlist: `https://www.youtube.com/playlist?list=123CODEOFPLAYLIST`

./playlist2links 123CODEOFPLAYLIST

The list of YouTube playlist's links is now saved in `playlist.txt`.
The list of YouTube playlist's links is now saved in `playlist_123CODEOFPLAYLIST.txt`.
9 changes: 4 additions & 5 deletions playlist2links
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ then
fi

eval $COMMAND
grep -e "^<tr.*<a href=\"/watch?v=.*$1" "${TMPFILE}.html" | sed 's/.*watch/https:\/\/www.youtube.com\/watch?/g' | sed 's/&amp.*//g' > playlist.txt
grep -e "^<tr.*<a href=\"/watch?v=.*$1" "${TMPFILE}.html" | sed 's/.*watch/https:\/\/www.youtube.com\/watch?/g' | sed 's/&amp.*//g' > playlist_$1.txt

while [[ $(grep "continuation=" ${TMPFILE}.html) ]]
do
sed -i 's/_continuation=1/\n/g' ${TMPFILE}.html
CONTINUATION=$(sed 's/\(.*\)continuation=/https:\/\/www.youtube.com\/browse_ajax?action_continuation=1&/g' <<< $(grep "continuation=" ${TMPFILE}.html))
CONTINUATION=$(sed 's/".*//g' <<< $CONTINUATION)
COMMAND=""
CONTINUATION=$((sed 's/\(.*\)continuation=/https:\/\/www.youtube.com\/browse_ajax?action_continuation=1&/g' | sed 's/".*//g') <<< $(grep "continuation=" ${TMPFILE}.html))

if [[ -n $(type -p wget) ]];
then
wget -o /dev/null -O "${TMPFILE}.html" "$CONTINUATION"
Expand All @@ -44,7 +43,7 @@ do
fi

tr -s '\\|/' '\n' < ${TMPFILE}.html > "${TMPFILE}"
grep "^watch" ${TMPFILE} | sed 's/\\u0026amp;\(.*\)//g' | sed 's/watch/https:\/\/www.youtube.com\/watch/g' | sort -u >> playlist.txt
grep "^watch" ${TMPFILE} | sed 's/\\u0026amp;\(.*\)//g' | sed 's/watch/https:\/\/www.youtube.com\/watch/g' | sort -u >> playlist_$1.txt
done

rm -f ${TMPFILE}*

0 comments on commit 9cb65dc

Please sign in to comment.