Browse Source

サムネ取得ミス修正

main
みてるぞ 2 weeks ago
parent
commit
4ebe43dd05
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      main.py

+ 8
- 3
main.py View File

@@ -95,13 +95,14 @@ def main (


uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }" uri = f"https://www.nicovideo.jp/watch/{ datum['contentId'] }"
(title, description, thumbnail) = get_embed_info (uri) (title, description, thumbnail) = get_embed_info (uri)
upload = client.com.atproto.repo.upload_blob (
io.BytesIO (requests.get (thumbnail).content))


embed_external = models.AppBskyEmbedExternal.Main ( embed_external = models.AppBskyEmbedExternal.Main (
external = models.AppBskyEmbedExternal.External ( external = models.AppBskyEmbedExternal.External (
title = title, title = title,
description = description, description = description,
thumb = client.com.atproto.repo.upload_blob (
io.BytesIO (requests.get (thumbnail).content)),
thumb = upload.blob,
uri = uri)) uri = uri))
client.post (Talk.main (f""" client.post (Talk.main (f"""
ニコニコに『{ datum['title'] }』という動画がアップされました。 ニコニコに『{ datum['title'] }』という動画がアップされました。
@@ -185,6 +186,10 @@ def get_nico_deerjika ():
def get_embed_info ( def get_embed_info (
url: str url: str
) -> (str, str, str): ) -> (str, str, str):
title: str = ''
description: str = ''
thumbnail: str = ''

try: try:
res = requests.get (url, timeout = 60) res = requests.get (url, timeout = 60)
except Exception: except Exception:
@@ -205,7 +210,7 @@ def get_embed_info (


tmp = soup.find ('meta', attrs = { 'name': 'thumbnail' }) tmp = soup.find ('meta', attrs = { 'name': 'thumbnail' })
if tmp is not None: if tmp is not None:
thumbnail = tmp.get (' content')
thumbnail = tmp.get ('content')


return (title, description, thumbnail) return (title, description, thumbnail)




Loading…
Cancel
Save