From 1b7ebf8744b6a2cb4ce92326be6bb4878d901e3d Mon Sep 17 00:00:00 2001 From: miteruzo Date: Fri, 10 Jan 2025 10:10:57 +0000 Subject: [PATCH] #1 --- __init__.py | 1 + module.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 __init__.py create mode 100644 module.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..d8e1cd7 --- /dev/null +++ b/__init__.py @@ -0,0 +1 @@ +from .module.py import fetch_comments diff --git a/module.py b/module.py new file mode 100644 index 0000000..a912d8b --- /dev/null +++ b/module.py @@ -0,0 +1,25 @@ +def fetch_video_info ( + video_code: str, +) -> VideoInfo | None: + bs = _create_bs_from_url (f"https://www.nicovideo.jp/watch/{ video_code }") + if bs is None: + return None + + try: + title = bs.find ('title') + if title is None: + return None + title = '-'.join (title.text.split ('-')[:(-1)])[:(-1)] + + tags_str: str = bs.find ('meta', attrs = { 'name': 'keywords' }).get ('content') # type: ignore + tags = tags_str.split (',') + + description = bs.find ('meta', attrs = { 'name': 'description' }).get ('content') # type: ignore + except Exception: + return None + + return { 'contentId': video_code, + 'title': title, + 'tags': tags, + 'description': description } +