Skip to content

Commit

Permalink
型ヒント強化
Browse files Browse the repository at this point in the history
  • Loading branch information
okaits committed Jun 24, 2023
1 parent 7c752f9 commit 4a0caf9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions nicovideo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
""" nicovideo.py (video) """
from __future__ import annotations

__version__ = '0.0.3'

import datetime
import pprint
import urllib.request
from html import unescape
import datetime
from typing import Type

import json5
from bs4 import BeautifulSoup as bs

__version__ = '0.0.3'

class Video():
""" Video """
def __init__(self, videoid: str):
def __init__(self, videoid: str) -> Video:
self.videoid = videoid
self.rawdict: dict = {}

Expand All @@ -22,20 +23,21 @@ class Metadata():

class User():
""" User data """
def __init__(self, nickname: str, userid: str):
def __init__(self, nickname: str, userid: str) -> Video.Metadata.User:
self.nickname: str = nickname
self.id : str = userid #pylint: disable=C0103
def __str__(self):
def __str__(self) -> str:
return f'{self.nickname} [ID: {self.id}]'

class Counts():
""" Counts data """
def __init__(self, comments: int, likes: int, mylists: int, views: int):
def __init__(self, comments: int, likes: int, mylists: int, views: int)\
-> Video.Metadata.Counts:
self.comments: int = comments
self.likes : int = likes
self.mylists : int = mylists
self.views : int = views
def __str__(self):
def __str__(self) -> str:
returndata = f'Views: {self.views}\n'
returndata += f'Comments: {self.comments}\n'
returndata += f'Mylists: {self.mylists}\n'
Expand All @@ -44,15 +46,15 @@ def __str__(self):

class Genre():
""" Genre data """
def __init__(self, label, key):
def __init__(self, label: str, key: str) -> Video.Metadata.Genre:
self.label : str = label
self.key : str = key
def __str__(self):
return self.label

class Tag():
""" Tag data """
def __init__(self, name: str, locked: bool):
def __init__(self, name: str, locked: bool) -> Video.Metadata.Tag:
self.name : str = name
self.locked: bool = locked
def __str__(self):
Expand All @@ -68,7 +70,7 @@ def __init__(
postdate: datetime.datetime,
genre : Genre,
tags : list[Tag]
):
) -> Video.Metadata:
self.videoid : str = videoid #pylint: disable=C0103
self.title : str = title
self.owner : self.User = owner
Expand All @@ -78,7 +80,7 @@ def __init__(
self.genre : self.Genre = genre
self.tags : list[self.Tag] = tags

def get_metadata(self):
def get_metadata(self) -> Video.Metadata:
""" Get video's metadata """
watch_url = f"https://www.nicovideo.jp/watch/{self.videoid}"
with urllib.request.urlopen(watch_url) as response:
Expand Down

0 comments on commit 4a0caf9

Please sign in to comment.