Last active
November 5, 2021 14:31
-
-
Save alexkuang0/396cf780926eb8caf195bfb5559ec708 to your computer and use it in GitHub Desktop.
Scriptable iOS 14 Widget - Bilibili latest video in your subcription feed 哔哩哔哩动态最新视频
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
本 Gist 已经停止维护,请前往 Gitee 代码仓库 查看后续更新。
This gist is not maintained here any more, please go to my Gitee repo for future updates.
Instructions 使用说明
🧰 Install 安装
🛠 Configuration 配置
🎬 Video Instructions 视频说明
https://www.bilibili.com/video/BV1654y1178Z
Changelog 更新日志
0.1.0
09/26/20200.1.1
10/04/2020