niconicolibs / niconico.py

niconico.py is a Python library for retrieving Niconico video content and information, and is compatible with the latest version of Niconico.
MIT License
42 stars 5 forks source link

[Bug] Cannot download video. TypeError: 'NoneType' object is not subscriptable #53

Closed joshvictor1024 closed 3 weeks ago

joshvictor1024 commented 4 months ago

概要

niconico video <url> download does not work for certain videos.

現象・ログ

See below.

再現手順

$ python3 ../niconico video https://www.nicovideo.jp/watch/sm43452874 download
[INFO] セッションIDを取得中... (<Video Title=トラップで冒険者を狩るあかりちゃんのDungeon Warfare 2 #15 Heartbeat=False>)
Exception in thread Thread-1 (_heartbeat):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/home/josh/apps/niconico.py-1.2.3/downloads/../niconico/video.py", line 260, in _heartbeat
    headers=HEADERS["heartbeat"], json=self._make_session_data(
                                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/josh/apps/niconico.py-1.2.3/downloads/../niconico/video.py", line 295, in _make_session_data
    session = self.__data__["media"]["delivery"]["movie"]["session"].copy()
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

期待動作

It should download the video normally.

niconico.pyのバージョン

1.2.3 and 1.2.4

OSの種類/ディストリ/バージョン

Linux Debian 12 64bit

$ uname -a
Linux framework13 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64 GNU/Linux
$ python3 --version
Python 3.11.2

その他

None.

joshvictor1024 commented 3 weeks ago

Please don't close an issue on a persisting breaking bug without explanation. To my knowledge, this is still present in 2.0.1.

For those who are having the same problem, you can fix this by editing niconico/video/watch.py. Some dict type variables are incorrectly accessed with the dot syntax instead of the bracket syntax. Please correct me if I am missing something obvious.

Doing the following for every error point solves the issue for me.

# e.g. line 44
#           return res_cls_data.data.response
            return res_cls_data.data["response"]

Note that the keys are in camelCase instead of snake_case. You may want to print and check for yourself.

Negima1072 commented 3 weeks ago

Thank you for letting us know about the issue, and I apologize for closing it without a reply.

Since version 2, the internal structure of niconico.py has changed significantly due to multiple factors, so console commands were not implemented in version 2.0.1. This has been implemented in version 2.0.2, which was just released, and it now becomes possible to obtain video information, obtain available quality levels, and download mp4 files from the console. Please refer to niconico -h as some command usage has changed.

Internally, since version 2 we have been using pydantic for type annotations, which allows access using dot syntax instead of parentheses syntax. There should be no dict type variables remaining.

I hope this resolves the problem. I will close this issue as soon as I can confirm that it has been resolved.