-
-
Save dardo82/f86df4ac3517a597259d to your computer and use it in GitHub Desktop.
#!/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 |
#!/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 |
To make this work, you must change line 4, it seems.
curl -v "https://api.periscope.tv/api/v2/getAccessPublic?token=${TOKEN//=/%3D}" | json > periscope.json
becomes
curl -v "https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=${TOKEN//=/%3D}" | json > periscope.json
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:
ffmpeg -i playlist.m3u8 periscope$TOKEN.mp4
cp -v periscope$TOKEN.mp4 ..; cd ..; rm -frv periscope; file periscope$TOKEN.mp4
@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.
thanks for this.
just as a heads up, this requires ffmpeg and json.
Usage
Save the file above to your system.
You get the token by following the instructions in this post. Scroll down to the section that talks about
getAccessPublic
.