Skip to content

Instantly share code, notes, and snippets.

@alexkuang0
Last active November 5, 2021 14:31
Show Gist options
  • Save alexkuang0/396cf780926eb8caf195bfb5559ec708 to your computer and use it in GitHub Desktop.
Save alexkuang0/396cf780926eb8caf195bfb5559ec708 to your computer and use it in GitHub Desktop.
Scriptable iOS 14 Widget - Bilibili latest video in your subcription feed 哔哩哔哩动态最新视频
const UID = 00000000 // 改为你的用户 ID
const COOKIE = "" // (可选,推荐设置)改为你的 cookie
let { title, user, image, videoUrl } = await getVideo(UID, COOKIE)
let widget = createWidget(title, user, videoUrl, image)
if (!config.runsInWidget) {
await widget.presentMedium()
}
Script.setWidget(widget)
Script.complete()
async function getVideo(uid, cookie) {
try {
let r = new Request("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=" + uid +"&type_list=8&from=&platform=web")
r.headers = {
'cookie': cookie,
'user-agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36",
}
let res = await r.loadJSON()
let card = JSON.parse(res.data.cards[0].card)
return {
title: card.title,
user: card.owner.name,
image: await getImage(card.pic),
videoUrl: card.jump_url,
}
} catch {
return {
title: '获取视频信息失败',
user: '哔哩哔哩弹幕网',
image: null,
videoUrl: 'https://www.bilibili.com/'
}
}
}
async function getImage(url) {
let r = new Request(url)
return await r.loadImage()
}
function createWidget(title, user, videoUrl, image) {
let w = new ListWidget()
w.url = videoUrl
if (image) {
w.backgroundImage = image
let gradient = new LinearGradient()
gradient.locations = [0, 1]
gradient.colors = [
new Color('#00000000'),
new Color('#000000CC'),
]
w.backgroundGradient = gradient
} else {
w.backgroundColor = new Color('#000')
}
w.addSpacer()
let titleText = w.addText(title)
titleText.font = Font.mediumSystemFont(15)
titleText.textColor = new Color('#FFF')
w.addSpacer(2)
let userText = w.addText(user)
userText.font = Font.regularSystemFont(12)
userText.textColor = new Color('#EEE')
return w
}
@alexkuang0
Copy link
Author

alexkuang0 commented Oct 4, 2020

本 Gist 已经停止维护,请前往 Gitee 代码仓库 查看后续更新。
This gist is not maintained here any more, please go to my Gitee repo for future updates.


Instructions 使用说明

🧰 Install 安装

🛠 Configuration 配置

  1. 编辑第 1 行中的用户 ID ,填入你的哔哩哔哩 UID
  2. 编辑第 2 行,填入你的 bilibili.com 的 Cookie (⚠️ 注意: 这是重要隐私,请勿泄漏)

🎬 Video Instructions 视频说明

https://www.bilibili.com/video/BV1654y1178Z

Changelog 更新日志

0.1.0 09/26/2020

  • 创建

0.1.1 10/04/2020

  • 更改背景渐变层颜色

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment