You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
790 B

  1. def fetch_video_info (
  2. video_code: str,
  3. ) -> VideoInfo | None:
  4. bs = _create_bs_from_url (f"https://www.nicovideo.jp/watch/{ video_code }")
  5. if bs is None:
  6. return None
  7. try:
  8. title = bs.find ('title')
  9. if title is None:
  10. return None
  11. title = '-'.join (title.text.split ('-')[:(-1)])[:(-1)]
  12. tags_str: str = bs.find ('meta', attrs = { 'name': 'keywords' }).get ('content') # type: ignore
  13. tags = tags_str.split (',')
  14. description = bs.find ('meta', attrs = { 'name': 'description' }).get ('content') # type: ignore
  15. except Exception:
  16. return None
  17. return { 'contentId': video_code,
  18. 'title': title,
  19. 'tags': tags,
  20. 'description': description }