mirror of
https://github.com/Xtao-Labs/iShotaBot.git
synced 2024-11-22 07:07:52 +00:00
feat: bsky support video
This commit is contained in:
parent
70369ad436
commit
c2f6c1255c
10
defs/bsky.py
10
defs/bsky.py
@ -100,6 +100,16 @@ class Timeline:
|
|||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
reply_markup=Timeline.get_button(post),
|
reply_markup=Timeline.get_button(post),
|
||||||
)
|
)
|
||||||
|
elif post.video:
|
||||||
|
return await bot.send_video(
|
||||||
|
reply.cid,
|
||||||
|
post.video,
|
||||||
|
caption=text,
|
||||||
|
thumb=post.video_thumbnail,
|
||||||
|
reply_to_message_id=reply.mid,
|
||||||
|
parse_mode=ParseMode.HTML,
|
||||||
|
reply_markup=Timeline.get_button(post),
|
||||||
|
)
|
||||||
elif not post.images:
|
elif not post.images:
|
||||||
return await bot.send_message(
|
return await bot.send_message(
|
||||||
reply.cid,
|
reply.cid,
|
||||||
|
@ -27,6 +27,7 @@ if TYPE_CHECKING:
|
|||||||
)
|
)
|
||||||
|
|
||||||
TZ = pytz.timezone("Asia/Shanghai")
|
TZ = pytz.timezone("Asia/Shanghai")
|
||||||
|
XRPC_DOMAIN = "bsky.social"
|
||||||
|
|
||||||
|
|
||||||
class HumanAuthor(BaseModel):
|
class HumanAuthor(BaseModel):
|
||||||
@ -99,6 +100,7 @@ class HumanPost(BaseModel, frozen=False):
|
|||||||
images: Optional[list[str]] = None
|
images: Optional[list[str]] = None
|
||||||
gif: Optional[str] = None
|
gif: Optional[str] = None
|
||||||
video: Optional[str] = None
|
video: Optional[str] = None
|
||||||
|
video_thumbnail: Optional[str] = None
|
||||||
external: Optional[str] = None
|
external: Optional[str] = None
|
||||||
created_at: datetime
|
created_at: datetime
|
||||||
|
|
||||||
@ -138,12 +140,18 @@ class HumanPost(BaseModel, frozen=False):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_view(post: Union["PostView", "BskyViewRecordRecord"]) -> "HumanPost":
|
def parse_view(post: Union["PostView", "BskyViewRecordRecord"]) -> "HumanPost":
|
||||||
record = post.value if isinstance(post, BskyViewRecordRecord) else post.record
|
record = post.value if isinstance(post, BskyViewRecordRecord) else post.record
|
||||||
|
# author
|
||||||
|
author = HumanAuthor.parse(post.author)
|
||||||
embed = (
|
embed = (
|
||||||
(post.embeds[0] if post.embeds else None)
|
(post.embeds[0] if post.embeds else None)
|
||||||
if isinstance(post, BskyViewRecordRecord)
|
if isinstance(post, BskyViewRecordRecord)
|
||||||
else post.embed
|
else post.embed
|
||||||
)
|
)
|
||||||
content = bsky_html_parser.unparse(record.text, record.facets) if record.facets else record.text
|
content = (
|
||||||
|
bsky_html_parser.unparse(record.text, record.facets)
|
||||||
|
if record.facets
|
||||||
|
else record.text
|
||||||
|
)
|
||||||
created_at = record.created_at
|
created_at = record.created_at
|
||||||
# images
|
# images
|
||||||
images = []
|
images = []
|
||||||
@ -151,9 +159,10 @@ class HumanPost(BaseModel, frozen=False):
|
|||||||
for image in embed.images:
|
for image in embed.images:
|
||||||
images.append(image.fullsize)
|
images.append(image.fullsize)
|
||||||
# video
|
# video
|
||||||
video = None
|
video, video_thumbnail = None, None
|
||||||
if isinstance(embed, BskyViewVideo):
|
if isinstance(embed, BskyViewVideo):
|
||||||
video = embed.playlist # m3u8
|
video = f"https://{XRPC_DOMAIN}/xrpc/com.atproto.sync.getBlob?did={author.did}&cid={embed.cid}"
|
||||||
|
video_thumbnail = embed.thumbnail
|
||||||
# gif
|
# gif
|
||||||
gif, extra = None, None
|
gif, extra = None, None
|
||||||
if isinstance(embed, BskyViewExternal):
|
if isinstance(embed, BskyViewExternal):
|
||||||
@ -162,14 +171,13 @@ class HumanPost(BaseModel, frozen=False):
|
|||||||
gif = uri
|
gif = uri
|
||||||
else:
|
else:
|
||||||
extra = uri
|
extra = uri
|
||||||
# author
|
|
||||||
author = HumanAuthor.parse(post.author)
|
|
||||||
return HumanPost(
|
return HumanPost(
|
||||||
cid=post.cid,
|
cid=post.cid,
|
||||||
content=content,
|
content=content,
|
||||||
images=images,
|
images=images,
|
||||||
gif=gif,
|
gif=gif,
|
||||||
video=video,
|
video=video,
|
||||||
|
video_thumbnail=video_thumbnail,
|
||||||
external=extra,
|
external=extra,
|
||||||
created_at=created_at,
|
created_at=created_at,
|
||||||
like_count=post.like_count,
|
like_count=post.like_count,
|
||||||
|
Loading…
Reference in New Issue
Block a user