-
Notifications
You must be signed in to change notification settings - Fork 0
/
videoHelper.js
131 lines (124 loc) · 4.3 KB
/
videoHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// always-run-in-app: true; icon-color: purple;
// icon-glyph: download; share-sheet-inputs: plain-text;
const _info = {
name: 'videoHelper',
version: '1.3',
updated_at: '2023-12-04 17:45:00',
author: 'raoyc',
description: 'download video from Chinese pop short-video apps, such as douyin, kuaishou, weibo and so on',
repo_file_url: 'https://github.com/ycrao/scripts-for-scriptable/blob/main/app/videoHelper.js',
raw_file_url: ' https://raw.githubusercontent.com/ycrao/scripts-for-scriptable/main/app/videoHelper.js'
}
const $http = importModule("http.module")
// 特别注意: 需要更新 `http.module` 类库
// 当前可用,但仅支持 `抖音` 与 `tiktok` 2个平台无水印视频下载
async function fetchVideo(clip) {
const re = /(http|https):\/\/([a-zA-Z0-9.:?=&-/%#]+)/g
const result = clip.match(re)
console.log(result)
if (result != null && result[0] !== undefined) {
const dyUrl = result[0]
const apiUrl = "https://www.tikdd.cc/g1.php"
let param = {
url: dyUrl,
count: 12,
cursor: 0,
web:1,
hd:1
}
json = await $http.postForm(apiUrl, param).loadJSON()
console.log(json)
if (json.code == 0) {
let videoUrl = json.data.play
const cb = new CallbackURL("shortcuts://x-callback-url/run-shortcut")
cb.addParameter("name", "下载文件")
cb.addParameter("input", "text")
cb.addParameter("text", videoUrl)
cb.open()
notify("VideoHelper", "Please select file path to download/请选择路径下载")
return
}
}
}
// 该接口已也失效,并改名为 _fetchVideo2
/*
async function _fetchVideo2(clip) {
const re = /(http|https):\/\/([a-zA-Z0-9.:?=&-/%#]+)/g
const result = clip.match(re)
console.log(result)
if (result != null && result[0] !== undefined) {
const dyUrl = result[0]
const apiUrl = "https://api.iculture.cc/api/video/"
json = await $http.req("get", apiUrl, {url: dyUrl}).loadJSON()
console.log(json)
if (json.code === 200) {
let videoUrl = json.url
if (videoUrl.startsWith("//")) {
videoUrl = "https:" + videoUrl
}
const cb = new CallbackURL("shortcuts://x-callback-url/run-shortcut")
cb.addParameter("name", "下载文件")
cb.addParameter("input", "text")
cb.addParameter("text", videoUrl)
cb.open()
notify("VideoHelper", "Please select file path to download/请选择路径下载")
// Safari.open(videoUrl)
return
}
} else {
notify("VideoHelper", "Invalid URL/无效URL")
}
}
*/
// 该接口已失效 抖音/快手/火山/微博/虎牙/轻视频/梨视频/皮皮虾/皮皮搞笑/微视/最右/VUE Vlog/新片场/度小视/六间房/acfun
/*
async function _fetchVideo(clip) {
const re = /(http|https):\/\/([a-zA-Z0-9.:?=&-/%#]+)/g
const result = clip.match(re)
console.log(result)
if (result != null && result[0] !== undefined) {
const dyUrl = result[0]
const apiUrl = "https://api.xcboke.cn/api/juhe"
json = await $http.req("get", apiUrl, {url: dyUrl}).loadJSON()
console.log(json)
if (json.code === 200) {
let videoUrl = json.data.url
if (videoUrl.startsWith("//")) {
videoUrl = "https:" + videoUrl
}
const cb = new CallbackURL("shortcuts://x-callback-url/run-shortcut")
cb.addParameter("name", "下载文件")
cb.addParameter("input", "text")
cb.addParameter("text", videoUrl)
cb.open()
notify("VideoHelper", "Please select file path to download/请选择路径下载")
// Safari.open(videoUrl)
return
}
} else {
notify("VideoHelper", "Invalid URL/无效URL")
}
}
*/
async function notify(title, body, url) {
let notification = new Notification()
notification.title = title
notification.body = body
if (url) {
notification.openURL = url
}
return await notification.schedule()
}
let clip = Pasteboard.pasteString()
if (clip == null) {
const texts = args.plainTexts
if (texts.length > 0) {
clip = texts[0]
} else {
notify("VideoHelper", "Invalid source/无效来源")
}
}
await fetchVideo(clip + "")
Script.complete()