AlexAplin / nndownload

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

Owner field in video parameters can be null #17

Closed wlerin closed 6 years ago

wlerin commented 6 years ago

On at least one video, the script is throwing an error when trying to get uploader and uploader_id here:

        template_params["uploader"] = params["owner"]["nickname"].strip(" さん")
        template_params["uploader_id"] = int(params["owner"]["id"])

It appears that the video has no "owner".

I've modified the script so that section reads:

        if params["owner"]:
            template_params["uploader"] = params["owner"]["nickname"].strip(" さん")
            template_params["uploader_id"] = int(params["owner"]["id"])
        else:
            template_params["uploader"] = ""
            template_params["uploader_id"] = 0

Which seems to solve the issue. Not sure if this can occur in videoDetail (why is that not mutually exclusive with video?)

Also, that strip() is potentially destructive if the nickname has さ or ん at the beginning or end of their real nickname.

AlexAplin commented 6 years ago

Can you provide an example? Regardless, this is a messy extraction and we should ignore parameters that are not present. One possibility is chaining get(), like params.get("video", {}).get("owner", {}).get("id").

rstrip() will make nickname extraction safer.