Browse Source

#1

pull/5/head
みてるぞ 1 year ago
commit
1b7ebf8744
2 changed files with 26 additions and 0 deletions
  1. +1
    -0
      __init__.py
  2. +25
    -0
      module.py

+ 1
- 0
__init__.py View File

@@ -0,0 +1 @@
from .module.py import fetch_comments

+ 25
- 0
module.py View File

@@ -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 }


Loading…
Cancel
Save