2024-06-19 18:29:26 +01:00
|
|
|
import { get } from 'svelte/store';
|
|
|
|
import settings from "$lib/settings";
|
2024-06-16 13:53:45 +01:00
|
|
|
import type { CobaltAPIResponse } from "$lib/types/api";
|
|
|
|
|
2024-06-16 13:22:44 +01:00
|
|
|
const apiURL = "https://api.cobalt.tools";
|
|
|
|
|
|
|
|
const request = async (url: string) => {
|
2024-06-19 18:29:26 +01:00
|
|
|
const saveSettings = get(settings).save;
|
|
|
|
|
2024-06-16 13:22:44 +01:00
|
|
|
const request = {
|
2024-06-19 18:29:26 +01:00
|
|
|
url,
|
|
|
|
|
|
|
|
isAudioOnly: saveSettings.downloadMode === "audio",
|
|
|
|
isAudioMuted: saveSettings.downloadMode === "mute",
|
|
|
|
aFormat: saveSettings.audioFormat,
|
|
|
|
isTTFullAudio: saveSettings.tiktokFullAudio,
|
|
|
|
dubLang: saveSettings.youtubeDubBrowserLang,
|
|
|
|
|
|
|
|
vCodec: saveSettings.youtubeVideoCodec,
|
|
|
|
vQuality: saveSettings.videoQuality,
|
|
|
|
|
|
|
|
filenamePattern: saveSettings.filenameStyle,
|
|
|
|
disableMetadata: saveSettings.disableMetadata,
|
|
|
|
|
|
|
|
twitterGif: saveSettings.twitterGif,
|
|
|
|
tiktokH265: saveSettings.tiktokH265,
|
2024-06-16 13:22:44 +01:00
|
|
|
}
|
|
|
|
|
2024-06-16 13:53:45 +01:00
|
|
|
const response: CobaltAPIResponse | undefined = await fetch(`${apiURL}/api/json`, {
|
2024-06-16 13:22:44 +01:00
|
|
|
method: "POST",
|
2024-07-07 13:52:06 +01:00
|
|
|
redirect: "manual",
|
2024-06-16 13:22:44 +01:00
|
|
|
body: JSON.stringify(request),
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}).then(r => r.json()).catch(() => {});
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
const probeCobaltStream = async (url: string) => {
|
|
|
|
const request = await fetch(`${url}&p=1`).catch(() => {});
|
|
|
|
if (request?.status === 200) {
|
|
|
|
return request?.status;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
request,
|
|
|
|
probeCobaltStream,
|
|
|
|
}
|