Skip to content

Instantly share code, notes, and snippets.

@szero
Last active September 10, 2023 04:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szero/ed7f656ae8017526dfa00ab47351c409 to your computer and use it in GitHub Desktop.
Save szero/ed7f656ae8017526dfa00ab47351c409 to your computer and use it in GitHub Desktop.
Download a South Park episode from southparkstudios.com
#!/usr/bin/env bash
if [[ $# != 1 ]]; then
echo "Usage: get_south_park <page link>"
exit 0
fi
TD="$(mktemp -d)"
clear_on_exit() {
rm -rf "$TD"
exit
}
trap clear_on_exit SIGINT SIGTERM SIGHUP EXIT
FLIST="$TD/list.txt"
title="$(youtube-dl --no-warnings --dump-single-json "$1" | grep -oP "(?<=\"playlist_title\":\s\").+?(?=\")" | head -n1)"
title="$(echo "$title" | tr " " "_")"
youtube-dl -f mp4 -o "$TD/%(autonumber)s.%(ext)s" "$1"
for f in "$TD"/000*.mp4 ; do
echo "file '$f'" >> "$FLIST"
done
SE=$(echo "$1" | grep -ioP '\-season\-\K[\d]{1,2}')
EP=$(echo "$1" | grep -ioP '\-ep\-\K[\d]{1,2}')
if [[ "${#EP}" == 1 ]]; then
EP="0$EP"
fi
NAME="South_Park.SE${SE}.EP${EP}.$title.mp4"
ffmpeg -hide_banner -f concat -safe 0 -i "$FLIST" -c copy -f mp4 "$TD/$NAME.temp"
ffmpeg -hide_banner -i "$TD/$NAME.temp" -c copy -movflags +faststart -f mp4 "$TD/$NAME"
mv "$TD/$NAME" "$(pwd)"
@szero
Copy link
Author

szero commented Sep 30, 2017

Dependencies:

Use the script with the url of episode that can stream in your browser, for example:

./get_southpark "https://www.southparkstudios.com/episodes/yy0vjs/south-park-the-pandemic-special-season-24-ep-1"

@szero
Copy link
Author

szero commented Jul 11, 2021

Updated the script to work with southparkstudios.com site. Also I'm using grep with -P arg now. MacOS may not like it (not sure) since as I recall Tim Cook ships non-PCRE compliant version of it. Probably fixable with homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment