Skip to content
Open
31 changes: 31 additions & 0 deletions niconico/niconico.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from logging import Logger, getLogger
from urllib.parse import urlparse

import requests

Expand Down Expand Up @@ -85,6 +86,36 @@ def post(
return self.session.post(url, headers=req_headers, data=data)
return self.session.post(url, headers=req_headers, json=json)

def delete(
self,
url: str,
*,
headers: dict[str, str] | None = None,
) -> requests.Response:
"""Send a DELETE request to a URL.

Args:
url (str): The URL to send the request to.
headers (dict[str, str]): The headers to send with the request.

Returns:
requests.Response: The response object.
"""
parsed_url = urlparse(url)
req_headers = {
"User-Agent": "niconico.py",
"X-Frontend-Id": "6",
"X-Frontend-Version": "0",
"X-Niconico-Language": "ja-jp",
"X-Client-Os-Type": "others",
"X-Request-With": "https://www.nicovideo.jp",
"Referer": "https://www.nicovideo.jp/",
"Host": parsed_url.netloc,
}
if headers is not None:
req_headers.update(headers)
return self.session.delete(url, headers=req_headers)

def login_with_mail(self, mail: str, password: str, mfa: str | None = None) -> None:
"""Login to NicoNico with a mail and password.

Expand Down
110 changes: 110 additions & 0 deletions niconico/objects/nvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,120 @@ class UserSearchData(BaseModel):
items: list[UserSearchItem]


class FollowingMylistItem(BaseModel):
"""A class that represents a following mylist item."""

id_: int = Field(..., alias="id")
status: str
detail: UserMylistItem


class FollowingMylistsData(BaseModel):
"""A class that represents the data of following mylists response from the NvAPI.

ref: https://nvapi.nicovideo.jp/v1/users/me/following/mylists
"""

follow_limit: int = Field(..., alias="followLimit")
mylists: list[FollowingMylistItem]


class FollowingTagItem(BaseModel):
"""A class that represents a following tag item."""

name: str
followed_at: str = Field(..., alias="followedAt")
niconic_summary: str | None = Field(None, alias="nicodicSummary")


class FollowingTagsData(BaseModel):
"""A class that represents the data of following tags response from the NvAPI.

ref: https://nvapi.nicovideo.jp/v1/users/me/following/tags
"""

tags: list[FollowingTagItem]

class CreateMylistData(BaseModel):
"""A class that represents the data of a create mylist response from the NvAPI.

ref: https://nvapi.nicovideo.jp/v1/users/me/mylists
"""

mylist_id: int = Field(..., alias="mylistId")
mylist: Mylist


class ThreadKeyData(BaseModel):
"""A class that represents the data of a thread key response from the NvAPI.

ref: https://nvapi.nicovideo.jp/v1/comment/keys/thread?videoId=<video_id>
"""

thread_key: str = Field(..., alias="threadKey")


class ActivityActor(BaseModel):
"""A class that represents an actor in a feed activity."""

id_: str = Field(..., alias="id")
type_: str = Field(..., alias="type")
name: str
icon_url: str = Field(..., alias="iconUrl")
url: str
is_live: bool = Field(..., alias="isLive")


class ActivityMessage(BaseModel):
"""A class that represents a message in a feed activity."""

text: str


class ActivityLabel(BaseModel):
"""A class that represents a label in a feed activity."""

text: str


class ActivityVideoContent(BaseModel):
"""A class that represents video content in a feed activity."""

duration: int


class ActivityContent(BaseModel):
"""A class that represents content in a feed activity."""

type_: str = Field(..., alias="type")
id_: str = Field(..., alias="id")
title: str
url: str
started_at: str = Field(..., alias="startedAt")
video: ActivityVideoContent | None = None


class Activity(BaseModel):
"""A class that represents a feed activity."""

sensitive: bool
message: ActivityMessage
thumbnail_url: str = Field(..., alias="thumbnailUrl")
label: ActivityLabel
content: ActivityContent
id_: str = Field(..., alias="id")
kind: str
created_at: str = Field(..., alias="createdAt")
actor: ActivityActor


class FeedData(BaseModel):
"""A class that represents the data of a feed response from the Feed API.

ref: https://api.feed.nicovideo.jp/v1/activities/followings/publish?context=header_timeline
"""

activities: list[Activity]
code: str
impression_id: str = Field(..., alias="impressionId")
next_cursor: str | None = Field(None, alias="nextCursor")
2 changes: 1 addition & 1 deletion niconico/objects/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class UserMylistItem(BaseModel):
default_sort_order: MylistSortOrder = Field(..., alias="defaultSortOrder")
items_count: int = Field(..., alias="itemsCount")
owner: Owner
sample_items: list[MylistItem]
sample_items: list[MylistItem] = Field(..., alias="sampleItems")
follower_count: int = Field(..., alias="followerCount")
created_at: str = Field(..., alias="createdAt")
is_following: bool = Field(..., alias="isFollowing")
Expand Down
4 changes: 2 additions & 2 deletions niconico/objects/video/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class SeriesOwner(BaseModel):

type_: Literal["user", "channel"] = Field(..., alias="type")
id_: str = Field(..., alias="id")
user: EssentialUser | None
channel: EssentialChannel | None
user: EssentialUser | None = None
channel: EssentialChannel | None = None


class SeriesDetail(BaseModel):
Expand Down
Loading