Last active
August 19, 2016 02:36
-
-
Save dardo82/f86df4ac3517a597259d to your computer and use it in GitHub Desktop.
Save Periscope Videos
This file contains hidden or 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
#!/bin/zsh | |
cd "${0%/*}/../conf/url/" | |
for user in $(cat ../users.list); do | |
TWEETS=$(t search timeline -d -l user "#Periscope:" | grep -v " RT @") | |
OLDIFS=$IFS; IFS=$'\n' | |
for tweet in $(echo $TWEETS); do | |
DATE=$(echo $tweet | cut -d\ -f2-6) | |
OLD_LC_ALL=$LC_ALL; export LC_ALL="POSIX" | |
SEC=$(($(date +%s) - $(date -j -f ' %b %e %H:%M ' "$DATE" +%s))) | |
export LC_ALL=$OLD_LC_ALL | |
if [ $SEC -lt $((60*60*24)) ]; then | |
URL=$(echo $tweet | grep -o 'https://.*\.tv/.*') | |
fi | |
URLS="$URLS\\n$URL" | |
done | |
IFS=$OLDIFS | |
if [ -n "${URLS//\\n/}}" ]; then | |
if [ ! -f $user.url ]; then | |
echo "url" > $user.url | |
fi | |
URL=$(cat $user.url) | |
URLS=$(echo $URLS | awk -v url=$URL '{if ($0~url) exit; print}') | |
if [ -n "$URLS" ]; then | |
for url in $(echo $URLS | sed '1!G;h;$!d'); do | |
${0%/*}/video-dl.sh $url $user | |
done | |
echo $url > $user.url | |
fi | |
fi | |
done |
This file contains hidden or 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
#!/bin/zsh | |
cd "${0%/*}/.."; mkdir download; cd download; TOKEN=${1##*/}; JSON="periscope.json" | |
curl "https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=$TOKEN" | json > $JSON | |
M3U8=$(awk -F\" /replay/'{print $4}' $JSON) | |
COOKIE="Cookie: $(awk -F'"' -v ORS="" /CloudFront/\ | |
'{print $4"="; getline; print $4"; "}' $JSON)" | |
curl -O -H "$COOKIE" "${M3U8}" | |
FIRST=$(awk -F'[_.]' '/chunk/{print $2;exit}' playlist.m3u8) | |
LAST=$(awk -F'[_.]' '/chunk/{num=$2}END{print num}' playlist.m3u8) | |
curl -O -H "$COOKIE" "${M3U8%/*}/chunk_[$FIRST-$LAST].ts" | |
cat chunk_{$FIRST..$LAST}.ts > $TOKEN.ts | |
ffmpeg -i $TOKEN.ts $TOKEN.mp4 | |
DIR="../video/$2"; [ -d $DIR ] || mkdir -p $DIR | |
cp $TOKEN.mp4 $DIR; cd ..; rm -fr download |
@byalextran: are those notes to yourself?
@tomck: i have found your comments just now, but your are quite right about s/token/broadcast_id/
.
@byalextran, @tomck: have a look at the improved version!
Download and save Periscope videos
Once downloaded and unzipped you can:
Install
mkdir -p bin conf/url; mv *.sh bin; touch conf/users.list
Config
Add the usernames (one per line,without "@") to conf/users.list
.
Run
cd bin; chmod +x *.sh; ./periscope.sh
WARNING
You will have to run sudo mv /etc/{zshenv,zprofile}
to fix path_helper and use the t ruby gem in the script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make this work, you must change line 4, it seems.
becomes
s/token/broadcast_id/ basically... for some reason it comes out looking worse than on the website, though.
I suggest changing the last two lines to these simpler ones (which also give the file a unique name), they take longer but they also don't touch the video quality: