-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |