Browse Source

#1

pull/5/head
みてるぞ 4 months ago
parent
commit
cf6391d15c
1 changed files with 26 additions and 0 deletions
  1. +26
    -0
      module.py

+ 26
- 0
module.py View File

@@ -116,6 +116,32 @@ def fetch_embed_info (
return (title, description, thumbnail)


def fetch_latest_video (
tags: list[str],
) -> VideoInfo | None:
tag = ' OR '.join (tags)
url = f"https://www.nicovideo.jp/tag/{ tag }"

params = { 'sort': 'f',
'order': 'd' }

video_info = { }

bs = _create_bs_from_url (url, params)
if bs is None:
return None

try:
video = (bs.find_all ('ul', class_ = 'videoListInner')[1]
.find ('li', class_ = 'item'))

video_info['contentId'] = video['data-video-id']
except Exception:
return None

return fetch_video_info (video_info['contentId'])


def _create_bs_from_url (
url: str,
params: dict | None = None,


Loading…
Cancel
Save