Last active
December 10, 2015 05:18
-
-
Save taonico/4386247 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
MAIL="" | |
PASSWORD="" | |
#curl -d mail=$MAIL -d password=$PASSWORD -c cookie.session https://secure.nicovideo.jp/secure/login?site=nicolive | |
LV="lv106878467" | |
USER_SESSION="user_session=" | |
COOKIE=$($HOME/bin/nicocookie) | |
#getPlayerStatusを取得 | |
PlayerStatus=$(curl -b $USER_SESSION$COOKIE http://live.nicovideo.jp/api/getplayerstatus?v=$LV) | |
#PlayerStatus=$(cat $LV".playerstatus") | |
echo $PlayerStatus | tee $LV".playerstatus" | |
replace_NewLine="s/></>\n</g" | |
replace_colon="s/%3A/:/g" | |
replace_slash="s/%2F/\//g" | |
replace_comma="s/%2C/,/g" | |
replace_atmark="s/%40/@/g" | |
replace_amp="s/\&/\&/g" | |
contents=".*<contents .*>\(.*\)<\/contents>.*" | |
premium="premium:.*\(rtmp:\/\/.*:[0-9]*\/.*\)%2C\(.*\)" | |
middle="middle:.*\(rtmp:\/\/.*:[0-9]*\/.*\)%2C\(.*\)" | |
default="default:.*\(rtmp:\/\/.*:[0-9]*\/.*\)%2C\(.*\)" | |
defaulte="default:.*\(rtmpe:\/\/.*:[0-9]*\/.*\)%2C\(.*\)" | |
limelight="limelight:.*\(rtmp:\/\/.*:[0-9]*\/.*\),\(.*\)" | |
akamai="akamai:.*\(rtmp:\/\/.*:[0-9]*\/.*\),\(.*\)" | |
#Contents URI:を取得 | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
-e "$replace_atmark" | tr ',' '\n'\ | |
| sed -e "/$premium/!d" -e "s/$premium/\1 \2/") | |
if [ "$contents_url" = "" ]; then | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
-e "$replace_atmark" | tr ',' '\n'\ | |
| sed -e "/$middle/!d" -e "s/$middle/\1 \2/") | |
fi | |
if [ "$contents_url" = "" ]; then | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
-e "$replace_atmark" | tr ',' '\n'\ | |
| sed -e "/$default/!d" -e "s/$default/\1 \2/") | |
fi | |
if [ "$contents_url" = "" ]; then | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
-e "$replace_atmark" | tr ',' '\n'\ | |
| sed -e "/$defaulte/!d" -e "s/$defaulte/\1 \2/") | |
fi | |
if [ "$contents_url" = "" ]; then | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
| sed -e "/$limelight/!d" -e "s/$limelight/\1 \2/") | |
fi | |
if [ "$contents_url" = "" ]; then | |
contents_url=$(echo $PlayerStatus\ | |
| sed -e "s/$contents/\1/g" -e "$replace_colon" -e "$replace_slash"\ | |
| sed -e "/$akamai/!d" -e "s/$akamai/\1 \2/") | |
fi | |
#rtmp:を取得 | |
premium_contents_url=$(echo $contents_url | awk '{ print $1 }') | |
#ビデオコンテント名を取得 | |
premium_contents=$(echo $contents_url | awk '{ print $2 }') | |
#チケットを取得 | |
tickets=".*<tickets>\(.*\)<\/tickets>.*" | |
stream_name="<stream name=\""$premium_contents"\">\(.*\)<\/stream>" | |
ticket=$(echo $PlayerStatus\ | |
| sed -e "s/$tickets/\1/" | awk 'gsub("><", ">\n<", $0 ) { print $0 }'\ | |
| sed -e "/$stream_name/!d" -e "s/$stream_name/\1/g" -e "$replace_amp") | |
#rtmpdumpの引数を作成 | |
VR=$premium_contents_url"/"$premium_contents"?"$ticket | |
CONN=$premium_contents"?"$ticket | |
echo "-vr "$VR" -C S:"$CONN | |
rtmpdump -vr $VR -C S:$CONN 2>/dev/null | ffplay pipe: | |
#rtmpdump -vr $VR -C S:$CONN -o $LV".flv" 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment