Skip to content

plugins.nicolive: re-implement plugin #4155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2021

Conversation

bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Nov 6, 2021

  • re-implement websocket client
    • remove watchinginterval message and scheduler logic
    • remove currentstream command handler
  • rewrite login and parse response using a validation schema
  • rewrite websocket API URL parser using a validation schema
  • rewrite custom HLSStream which needs the websocket client reference
    • close websocket when stream closes
    • close websocket if no stream gets opened
  • remove unnecessary log spam when waiting for permit via websocket
  • fix URL matcher
  • rephrase log messages
  • reformat existing code

#4153

  1. Login is completely untested. The login logic which is based on cookies didn't get changed though.
  2. Not sure about the previously implemented send_watching method and the dedicated scheduler thread. The watchinginterval command doesn't seem to be sent anymore on their website, so I dropped the watching message stuff entirely. It also tried reading the self.broadcast_id attribute which didn't exist in the plugin, meaning it was sending the watching command without any data.
  3. The currentstream command on the watch response type doesn't seem to exist anymore either. This looked like a second response type for getting the HLS stream URL.
  4. The website seems to request low latency streams via the {"protocol": "hls+fmp4", "latency": "low"} parameters. I didn't change it because I'm not sure if it's supported everywhere. If it is, then this change is trivial and can be done later.
  5. I removed the reconnect-on-error logic because the requested HLS streams have a randomized access token attached. It's possible that reconnecting the websocket without querying the stream data works, so that the keepalive frames can continue to be sent, but I'm not sure. If that's the case, then this error handling logic could be added back. I haven't seen any issues so far though.
  6. While it's not important for streamlink_cli as it immediately terminates, I've added logic for closing the websocket thread gracefully when no stream gets opened after a short while (for listing stream qualities via the API). This means there's a double Event.wait call here, one for acquiring the HLS URL on the main thread and one for opening the stream on the websocket thread.

I'm not 100% confident with these changes, so please only merge if fully reviewed and tested.


$ streamlink 'https://live.nicovideo.jp/watch/lv334406090' best -l debug
[cli][debug] OS:         Linux-5.15.0-1-git-x86_64-with-glibc2.33
[cli][debug] Python:     3.9.7
[cli][debug] Streamlink: 2.4.0+76.gcdf3b09
[cli][debug] Requests(2.26.0), Socks(1.7.1), Websocket(1.2.1)
[cli][debug] Arguments:
[cli][debug]  url=https://live.nicovideo.jp/watch/lv334406090
[cli][debug]  stream=['best']
[cli][debug]  --loglevel=debug
[cli][debug]  --player=mpv
[cli][info] Found matching plugin nicolive for URL https://live.nicovideo.jp/watch/lv334406090
[plugins.nicolive][debug] Waiting for permit (for at most 6 seconds)...
[plugin.api.websocket][debug] Connected: wss://a.live2.nicovideo.jp/unama/wsapi/v2/watch/46039356670564?audience_token=46039356670564_anonymous-user-73061e1b-d8e1-412d-a798-4f6fa67512df_1636302644_1bd92f613f15010cd947216700f2070ef055403e&frontend_id=9
[plugins.nicolive][debug] Received: {"type":"serverTime","data":{"currentMs":"2021-11-07T01:30:46.126+09:00"}}
[plugins.nicolive][debug] Received: {"type":"seat","data":{"keepIntervalSec":30}}
[plugins.nicolive][debug] Received: {"type":"stream","data":{"uri":"https://vodedge723.dmc.nico/hlslive/ht2_nicolive/nicolive-production-pg46039356670564_0a82deee69e3df796d911aafe32474fa5b7c5b1c36d91fb6766e25ffb423c8f5/master.m3u8?ht2_nicolive=anonymous-user-73061e1b-d8e1-412d-a798-4f6fa67512df.s18l8vshik_r25sja_3a5upjrlcd1gy","syncUri":"https://vodedge723.dmc.nico/hlslive/ht2_nicolive/nicolive-production-pg46039356670564_0a82deee69e3df796d911aafe32474fa5b7c5b1c36d91fb6766e25ffb423c8f5/stream_sync.json?ht2_nicolive=anonymous-user-73061e1b-d8e1-412d-a798-4f6fa67512df.s18l8vshik_r25sja_3a5upjrlcd1gy","quality":"abr","availableQualities":["abr","normal","low","super_low","audio_high"],"protocol":"hls"}}
[utils.l10n][debug] Language code: en_US
[cli][info] Available streams: 350k (worst), 690k, 1800k (best)
[cli][info] Opening stream: 1800k (hls)
[plugins.nicolive][debug] Stream opened, keeping websocket connection alive
[stream.hls][debug] Reloading playlist
[cli][debug] Pre-buffering 8192 bytes
[plugins.nicolive][debug] Received: {"type":"room","data":{"name":"アリーナ","messageServer":{"uri":"wss://msgd.live2.nicovideo.jp/websocket","type":"niwavided"},"threadId":"M.x6KXYc9yP3dhC_Xaet2UfQ","isFirst":true,"waybackkey":"waybackkey","vposBaseTime":"2021-11-07T00:33:24+09:00"}}
[plugins.nicolive][debug] Received: {"type":"schedule","data":{"begin":"2021-11-07T00:35:29+09:00","end":"2021-11-07T02:05:29+09:00"}}
[plugins.nicolive][debug] Received: {"type":"akashic","data":{"playId":"46614204","contentUrl":"https://ak.cdn.nimg.jp/coe/contents/aufeiR7C/nicocas/4.0.0/content.json","logServerUrl":"wss://ap-msg26.coe.nicovideo.jp/4013/","status":"ready","token":"b89fb3b2c4d5a6005ee542ed6e1988c58b759d24f80b5769ea6f0f2f1b29d96e","playerId":"anonymous-user-73061e1b-d8e1-412d-a798-4f6fa67512df"}}
[plugins.nicolive][debug] Received: {"type":"statistics","data":{"viewers":1302,"comments":1395,"adPoints":103100,"giftPoints":150}}
[stream.hls][debug] First Sequence: 2288; Last Sequence: 2290
[stream.hls][debug] Start offset: 0; Duration: None; Start Sequence: 2288; End Sequence: None
[stream.hls][debug] Adding segment 2288 to queue
[stream.hls][debug] Adding segment 2289 to queue
[stream.hls][debug] Adding segment 2290 to queue
[cli][info] Starting player: mpv
[cli.output][debug] Opening subprocess: mpv --force-media-title=https://live.nicovideo.jp/watch/lv334406090 -
[cli][debug] Writing stream to output
[stream.hls][debug] Segment 2288 complete
[stream.hls][debug] Reloading playlist
...
[stream.hls][debug] Adding segment 2295 to queue
[stream.hls][debug] Adding segment 2296 to queue
[stream.hls][debug] Segment 2295 complete
[plugins.nicolive][debug] Received: {"type":"ping"}
[stream.hls][debug] Segment 2296 complete
[stream.hls][debug] Reloading playlist
....
[stream.hls][debug] Adding segment 2306 to queue
[stream.hls][debug] Adding segment 2307 to queue
[cli][info] Player closed
[stream.segmented][debug] Closing worker thread
[stream.segmented][debug] Closing writer thread
[plugin.api.websocket][debug] Closed: wss://a.live2.nicovideo.jp/unama/wsapi/v2/watch/46039356670564?audience_token=46039356670564_anonymous-user-73061e1b-d8e1-412d-a798-4f6fa67512df_1636302644_1bd92f613f15010cd947216700f2070ef055403e&frontend_id=9
[cli][info] Stream ended
[cli][info] Closing currently open stream...

- re-implement websocket client
  - remove watchinginterval message and scheduler logic
  - remove currentstream command handler
- rewrite login and parse response using a validation schema
- rewrite websocket API URL parser using a validation schema
- rewrite custom HLSStream which needs the websocket client reference
  - close websocket when stream closes
  - close websocket if no stream gets opened
- remove unnecessary log spam when waiting for permit via websocket
- fix URL matcher
- rephrase log messages
- reformat existing code
@bastimeyer bastimeyer added the plugin enhancement A new feature for a working Plugin label Nov 6, 2021
@back-to back-to merged commit 2e6deca into streamlink:master Nov 6, 2021
@bastimeyer bastimeyer deleted the plugins/nicolive/rewrite branch November 7, 2021 04:48
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Nov 9, 2021
- re-implement websocket client
  - remove watchinginterval message and scheduler logic
  - remove currentstream command handler
- rewrite login and parse response using a validation schema
- rewrite websocket API URL parser using a validation schema
- rewrite custom HLSStream which needs the websocket client reference
  - close websocket when stream closes
  - close websocket if no stream gets opened
- remove unnecessary log spam when waiting for permit via websocket
- fix URL matcher
- rephrase log messages
- reformat existing code
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Nov 10, 2021
- re-implement websocket client
  - remove watchinginterval message and scheduler logic
  - remove currentstream command handler
- rewrite login and parse response using a validation schema
- rewrite websocket API URL parser using a validation schema
- rewrite custom HLSStream which needs the websocket client reference
  - close websocket when stream closes
  - close websocket if no stream gets opened
- remove unnecessary log spam when waiting for permit via websocket
- fix URL matcher
- rephrase log messages
- reformat existing code
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Nov 10, 2021
- re-implement websocket client
  - remove watchinginterval message and scheduler logic
  - remove currentstream command handler
- rewrite login and parse response using a validation schema
- rewrite websocket API URL parser using a validation schema
- rewrite custom HLSStream which needs the websocket client reference
  - close websocket when stream closes
  - close websocket if no stream gets opened
- remove unnecessary log spam when waiting for permit via websocket
- fix URL matcher
- rephrase log messages
- reformat existing code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin enhancement A new feature for a working Plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants