Skip to content

Commit

Permalink
Merge branch 'mapio-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlauro committed Jan 10, 2015
2 parents 0534d0c + eac048c commit 89a7c2d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Playlist To Links
This bash script allows to extract video links from a Youtube playlist

This bash script allows to extract video links from a YouTube playlist.

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

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

./playlist2links 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.txt`.
50 changes: 40 additions & 10 deletions playlist2links
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
#!/bin/bash
html2 a 2>/dev/null
if [ $? -eq 127 ]
then
echo "Please, install xml2 to use this script"
exit
fi;
wget "https://www.youtube.com/playlist?list=$1" -o /dev/null -O /tmp/playlist.html
html2 < /tmp/playlist.html > /tmp/playlist.html2 2>/dev/null
grep "/html/body/div/div/div/div/div/div/div/div/div/div/ul/li/div/table/tbody/tr/@data-video-id=" /tmp/playlist.html2 > /tmp/playlist.html3
sed 's/\(.*\)=/https:\/\/www.youtube.com\/watch?v=/g' < /tmp/playlist.html3 > playlist.txt

if [[ -z "$1" ]];
then
echo "Please, specify the playlist code as argument" 1>&2
exit 1
fi
URL="https://www.youtube.com/playlist?list=$1"

if [[ -z $(type -p html2) ]];
then
echo "Please, install xml2 to use this script" 1>&2
exit 1
fi

TMPFILE=`mktemp /tmp/${tempfoo}.XXXXXX` || {
echo "Tempoprary file creation failuer" 1>&2
exit 1
}

COMMAND=""
if [[ -n $(type -p wget) ]];
then
COMMAND="wget -o /dev/null -O '${TMPFILE}.html' '$URL'"
fi
if [[ -z "$COMMAND" ]] && [[ -n $(type -p curl) ]];
then
COMMAND="curl -s -o '${TMPFILE}.html' '$URL'"
fi
if [[ -z "$COMMAND" ]];
then
echo "Please, install wget or curl to use this script" 1>&2
exit 1
fi

eval $COMMAND
html2 < "${TMPFILE}.html" > "${TMPFILE}.html2" 2>/dev/null
grep "/html/body/div/div/div/div/div/div/div/div/div/div/ul/li/div/table/tbody/tr/@data-video-id=" "${TMPFILE}.html2" > "${TMPFILE}.html3"
sed 's/\(.*\)=/https:\/\/www.youtube.com\/watch?v=/g' < "${TMPFILE}.html3" > playlist.txt

rm -f "${TMPFILE}"

0 comments on commit 89a7c2d

Please sign in to comment.