AlexAplin / nndownload

Download and process links from Niconico (nicovideo.jp)
MIT License
213 stars 28 forks source link

WSS initialization for HLS streams #50

Closed AlexAplin closed 5 years ago

AlexAplin commented 5 years ago

WebSockets are now used for Niconama streams.

AlexAplin commented 5 years ago

wss_url = ["site"]["relive"]["webSocketUrl"] broadcast_id =["site"]["program"]["broadcastId"]

GET wss_url 101 Upgrade

Initialization:

CLIENT: {"type":"watch","body":{"command":"playerversion","params":["leo"]}}
CLIENT: {"type":"watch","body":{"command":"getpermit","requirement":{"broadcastId":broadcast_id,"route":"","stream":{"protocol":"hls","requireNewStream":true,"priorStreamQuality":"abr","isLowLatency":true,"isChasePlay":false},"room":{"isCommentable":true,"protocol":"webSocket"}}}}
SERVER: {"type":"watch","body":{"command":"statistics","params":["66864","41957","0","0"]}}
SERVER: {"type":"watch","body":{"command":"servertime","params":["1562491996809"]}}
SERVER: {"type":"watch","body":{"command":"permit","params":["12100564943432"]}}
CLIENT: {"type":"watch","body":{"command":"getakashic","requirement":{"isChasePlay": false}}}
SERVER: {"type":"watch","body":{"currentStream":{"uri":"https://pb085cb3ae2.dmc.nico/hlslive/ht2_nicolive/nicolive-production-pg12100564943432_87ca7412ec2223150e41e5ed71b9effc1e20b5a246168df9ee14632c4a8237ef/master.m3u8?ht2_nicolive=anonymous-user-0114ad22-44d0-4fc2-b518-4794fffac627.kru1if_pu9mjg_2ssy8uydxz3ja","name":null,"quality":"abr","qualityTypes":["abr","super_high","high","normal","low","super_low"],"mediaServerType":"dmc","mediaServerAuth":null,"streamingProtocol":"hls"},"command":"currentstream"}}

Ping check with server:

SERVER: {"type":"ping","body":{}}
CLIENT: {"type":"pong","body":{}}

Every thirty seconds after first message:

CLIENT: {"type":"watch","body":{"command":"watching","params":[broadcast_id,"-1","0"]}}
AlexAplin commented 5 years ago

Streams seem to be stable when played in an external player and do not seem to change URL. As long as we communicate the watching command and pong back, these should work without any issue.

AlexAplin commented 5 years ago

The client initialization can be reduced to:

{"type":"watch","body":{"command":"getpermit","params":[broadcast_id,"","true","hls",""]}}

playerversion can be ommited.

AlexAplin commented 5 years ago

A fully qualified getpermit is required to get all qualities. The stream stutters in MPC and VLC, even when adjusting buffers. It's stable in mpv/streamlink, so I'm guessing like most HLS/DASH streams it needs an aggressive cache and threading.