|
|
@@ -13,6 +13,7 @@ from bs4 import BeautifulSoup |
|
|
|
from requests.exceptions import Timeout |
|
|
|
from eloquent import DatabaseManager, Model |
|
|
|
|
|
|
|
import nicolib |
|
|
|
from db.models import Comment, Tag, Video, VideoHistory, VideoTag |
|
|
|
|
|
|
|
CONFIG: dict[str, DbConfig] = { 'mysql': { 'driver': 'mysql', |
|
|
@@ -97,31 +98,6 @@ def get_bs_from_url ( |
|
|
|
return BeautifulSoup (req.text, 'html.parser') |
|
|
|
|
|
|
|
|
|
|
|
def get_video_info ( |
|
|
|
video_code: str, |
|
|
|
) -> VideoInfo | None: |
|
|
|
video_info: dict[str, str | list[str]] = { 'contentId': video_code } |
|
|
|
|
|
|
|
bs = get_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 |
|
|
|
video_info['title'] = '-'.join (title.text.split ('-')[:(-1)])[:(-1)] |
|
|
|
|
|
|
|
tags: str = bs.find ('meta', attrs = { 'name': 'keywords' }).get ('content') # type: ignore |
|
|
|
video_info['tags'] = tags.split (',') |
|
|
|
|
|
|
|
video_info['description'] = bs.find ('meta', attrs = { 'name': 'description' }).get ('content') # type: ignore |
|
|
|
except Exception: |
|
|
|
return None |
|
|
|
|
|
|
|
return cast (VideoInfo, video_info) |
|
|
|
|
|
|
|
|
|
|
|
def get_kiriban_list ( |
|
|
|
base_date: date, |
|
|
|
) -> list[tuple[int, VideoInfo, datetime]]: |
|
|
|