fix: undefined response
This commit is contained in:
parent
c53f80141f
commit
8f5ddd814c
@ -13,14 +13,12 @@ export type MusicalDownResponse = {
|
|||||||
result?: {
|
result?: {
|
||||||
type: "video" | "image"
|
type: "video" | "image"
|
||||||
desc?: string
|
desc?: string
|
||||||
author: {
|
author?: {
|
||||||
avatar?: string
|
avatar?: string
|
||||||
nickname: string
|
nickname?: string
|
||||||
}
|
}
|
||||||
music?: string
|
music?: string
|
||||||
images?: string[]
|
images?: string[]
|
||||||
video1?: string
|
|
||||||
video2?: string
|
|
||||||
videoHD?: string
|
videoHD?: string
|
||||||
videoWatermark?: string
|
videoWatermark?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ export type SSSTikResponse = {
|
|||||||
message?: string
|
message?: string
|
||||||
result?: {
|
result?: {
|
||||||
type: "image" | "video"
|
type: "image" | "video"
|
||||||
desc: string
|
desc?: string
|
||||||
author: Author
|
author: Author
|
||||||
statistics: Statistics
|
statistics: Statistics
|
||||||
images?: string[]
|
images?: string[]
|
||||||
|
|||||||
@ -64,32 +64,32 @@ const getRequest = (url: string, proxy?: string) =>
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const getMusic = (cookie: string, proxy?: string) =>
|
// const getMusic = (cookie: string, proxy?: string) =>
|
||||||
new Promise<getMusic>((resolve) => {
|
// new Promise<getMusic>((resolve) => {
|
||||||
Axios(_musicaldownmusicapi, {
|
// Axios(_musicaldownmusicapi, {
|
||||||
method: "GET",
|
// method: "GET",
|
||||||
headers: {
|
// headers: {
|
||||||
cookie: cookie,
|
// cookie: cookie,
|
||||||
"Upgrade-Insecure-Requests": "1",
|
// "Upgrade-Insecure-Requests": "1",
|
||||||
"User-Agent":
|
// "User-Agent":
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0"
|
// "Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0"
|
||||||
},
|
// },
|
||||||
httpsAgent:
|
// httpsAgent:
|
||||||
(proxy &&
|
// (proxy &&
|
||||||
(proxy.startsWith("http") || proxy.startsWith("https")
|
// (proxy.startsWith("http") || proxy.startsWith("https")
|
||||||
? new HttpsProxyAgent(proxy)
|
// ? new HttpsProxyAgent(proxy)
|
||||||
: proxy.startsWith("socks")
|
// : proxy.startsWith("socks")
|
||||||
? new SocksProxyAgent(proxy)
|
// ? new SocksProxyAgent(proxy)
|
||||||
: undefined)) ||
|
// : undefined)) ||
|
||||||
undefined
|
// undefined
|
||||||
})
|
// })
|
||||||
.then(({ data }) => {
|
// .then(({ data }) => {
|
||||||
const $ = load(data)
|
// const $ = load(data)
|
||||||
const music = $("audio > source").attr("src")
|
// const music = $("audio > source").attr("src")
|
||||||
resolve({ status: "success", result: music })
|
// resolve({ status: "success", result: music })
|
||||||
})
|
// })
|
||||||
.catch((e) => resolve({ status: "error" }))
|
// .catch((e) => resolve({ status: "error" }))
|
||||||
})
|
// })
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tiktok MusicalDown Downloader
|
* Tiktok MusicalDown Downloader
|
||||||
@ -138,23 +138,26 @@ export const MusicalDown = (url: string, proxy?: string) =>
|
|||||||
// Get Result Video
|
// Get Result Video
|
||||||
let i = 1
|
let i = 1
|
||||||
let videos = {}
|
let videos = {}
|
||||||
$("div[class='col s12 l8'] > a")
|
$("div.row > div")
|
||||||
|
.map((_, el) => $(el))
|
||||||
|
.get(1)
|
||||||
|
.find("a")
|
||||||
.get()
|
.get()
|
||||||
.map((v) => {
|
.map((v: any) => {
|
||||||
if ($(v).attr("href") !== "#modal2") {
|
if ($(v).attr("href") !== "#modal2") {
|
||||||
let text = $(v)
|
if (!isURL($(v).attr("href"))) return
|
||||||
.text()
|
|
||||||
.trim()
|
|
||||||
.replace(/\s/, " ")
|
|
||||||
.replace("arrow_downward", "")
|
|
||||||
.toLowerCase()
|
|
||||||
videos[
|
videos[
|
||||||
text.includes("hd")
|
$(v).attr("data-event").includes("hd")
|
||||||
? "videoHD"
|
? "videoHD"
|
||||||
: text.includes("watermark")
|
: $(v).attr("data-event").includes("mp4")
|
||||||
|
? "videoSD"
|
||||||
|
: $(v).attr("data-event").includes("watermark")
|
||||||
? "videoWatermark"
|
? "videoWatermark"
|
||||||
: `video${i}`
|
: $(v).attr("href").includes("type=mp3") && "music"
|
||||||
] = $(v).attr("href") != undefined ? $(v).attr("href") : /downloadX\('([^']+)'\)/.exec($(v).attr('onclick'))[1];
|
] =
|
||||||
|
$(v).attr("href") != undefined
|
||||||
|
? $(v).attr("href")
|
||||||
|
: /downloadX\('([^']+)'\)/.exec($(v).attr("onclick"))[1]
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -165,42 +168,26 @@ export const MusicalDown = (url: string, proxy?: string) =>
|
|||||||
status: "success",
|
status: "success",
|
||||||
result: {
|
result: {
|
||||||
type: "image",
|
type: "image",
|
||||||
author: {
|
images
|
||||||
nickname: $("h2.white-text")
|
|
||||||
.text()
|
|
||||||
.trim()
|
|
||||||
.replace("Download Now: Check out ", "")
|
|
||||||
.replace(
|
|
||||||
"’s video! #TikTok >If MusicallyDown has helped you, you can help us too",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
.replace("Download Now: ", "")
|
|
||||||
.replace(
|
|
||||||
"If MusicallyDown has helped you, you can help us too",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
},
|
|
||||||
images,
|
|
||||||
music: $("a.download").attr("href")
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Video Result
|
// Video Result
|
||||||
const music = await getMusic(request.cookie)
|
// const music = await getMusic(request.cookie)
|
||||||
|
if (Object.keys(videos).length === 0)
|
||||||
|
return resolve({
|
||||||
|
status: "success",
|
||||||
|
message: "There is an error. Can't find download link"
|
||||||
|
})
|
||||||
resolve({
|
resolve({
|
||||||
status: "success",
|
status: "success",
|
||||||
result: {
|
result: {
|
||||||
type: "video",
|
type: "video",
|
||||||
author: {
|
author: {
|
||||||
avatar: $("div.img-area > img").attr("src"),
|
avatar: $("div.img-area > img").attr("src"),
|
||||||
nickname: $("div.row > div > div > h2")
|
nickname: $("h2.video-author > b").text()
|
||||||
.map((_, el) => $(el).text())
|
|
||||||
.get(0)
|
|
||||||
},
|
},
|
||||||
desc: $("div.row > div > div > h2")
|
desc: $("p.video-desc").text(),
|
||||||
.map((_, el) => $(el).text())
|
|
||||||
.get(1),
|
|
||||||
music: music.result,
|
|
||||||
...videos
|
...videos
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -208,3 +195,14 @@ export const MusicalDown = (url: string, proxy?: string) =>
|
|||||||
})
|
})
|
||||||
.catch((e) => resolve({ status: "error", message: e.message }))
|
.catch((e) => resolve({ status: "error", message: e.message }))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isURL = (url: string) => {
|
||||||
|
let status = false
|
||||||
|
try {
|
||||||
|
new URL(url)
|
||||||
|
status = true
|
||||||
|
} catch {
|
||||||
|
status = false
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|||||||
@ -115,7 +115,6 @@ export const SSSTik = (url: string, proxy?: string) =>
|
|||||||
const $ = load(await response)
|
const $ = load(await response)
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
const desc = $("p.maintext").text().trim()
|
|
||||||
const author: Author = {
|
const author: Author = {
|
||||||
avatar: $("img.result_author").attr("src"),
|
avatar: $("img.result_author").attr("src"),
|
||||||
nickname: $("h2").text().trim()
|
nickname: $("h2").text().trim()
|
||||||
@ -148,7 +147,6 @@ export const SSSTik = (url: string, proxy?: string) =>
|
|||||||
status: "success",
|
status: "success",
|
||||||
result: {
|
result: {
|
||||||
type: "image",
|
type: "image",
|
||||||
desc,
|
|
||||||
author,
|
author,
|
||||||
statistics,
|
statistics,
|
||||||
images,
|
images,
|
||||||
@ -161,7 +159,7 @@ export const SSSTik = (url: string, proxy?: string) =>
|
|||||||
status: "success",
|
status: "success",
|
||||||
result: {
|
result: {
|
||||||
type: "video",
|
type: "video",
|
||||||
desc,
|
desc: $("p.maintext").text().trim(),
|
||||||
author,
|
author,
|
||||||
statistics,
|
statistics,
|
||||||
video,
|
video,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user