LoginSignup
3
4

More than 5 years have passed since last update.

PowerShell_ニコ動ダウンロード

Posted at
PowerShell

$vid="smXXXXXXXXX"

#接続先設定
$url1="http://flapi.nicovideo.jp/api/getflv?v=$vid"
$url3="http://ext.nicovideo.jp/api/getthumbinfo/$vid"
$url4="http://www.nicovideo.jp/watch/$vid"

#ログインする
$res1 = Invoke-RestMethod -Uri "https://secure.nicovideo.jp/secure/login?site=niconico" -Method POST -Body @{mail="[ID]";password="[PASS]"} -SessionVariable fb

#URLを取得
$res2 = Invoke-RestMethod -Uri $url1 -WebSession $fb -Method GET
$url2= ($res2| Select-String "&url=(.*?)&").Matches.Groups[1].Value.Replace("%3A",":").Replace("%2F","/").Replace("%3F","?").Replace("%3D","=")
#エンコードがわからんかったので置換

#拡張子取得
$res3 = Invoke-RestMethod -Uri $url3 -WebSession $fb -Method GET
$ext=$res3.nicovideo_thumb_response.thumb.movie_type #拡張子

#ダウンロード前にチラ見する
$res4 = Invoke-RestMethod -Uri $url4 -WebSession $fb -Method GET

#ダウンロードする
$outPath="$vid.$ext"
Invoke-RestMethod -Uri $url2 -WebSession $fb -Method GET -outfile $outPath


3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4