im going to kill myself
This commit is contained in:
parent
ad4c255c9f
commit
7e5c4c6408
|
@ -21,8 +21,7 @@
|
||||||
"readable-to-ms": "^1.0.3",
|
"readable-to-ms": "^1.0.3",
|
||||||
"rolling-rate-limiter": "^0.4.2",
|
"rolling-rate-limiter": "^0.4.2",
|
||||||
"wget-improved": "^3.4.0",
|
"wget-improved": "^3.4.0",
|
||||||
"winston": "^3.8.2",
|
"winston": "^3.8.2"
|
||||||
"youtubei.js": "^9.2.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"prisma": "4.9.0"
|
"prisma": "4.9.0"
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
const { Innertube } = require('youtubei.js');
|
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
const maxRetries = 5
|
const maxRetries = 5
|
||||||
const platforms = ['YTSTUDIO_ANDROID', 'WEB', 'iOS', 'YTMUSIC_ANDROID', 'YTMUSIC', 'TV_EMBEDDED']
|
|
||||||
|
|
||||||
async function getPipedInstance() {
|
async function getPipedInstance() {
|
||||||
const instances = await (await fetch('https://piped-instances.kavin.rocks/', {
|
const instances = await (await fetch('https://piped-instances.kavin.rocks/', {
|
||||||
|
@ -14,87 +11,15 @@ async function getPipedInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVideoMetadata(id) {
|
async function getVideoMetadata(id) {
|
||||||
let error = ''
|
return await (await fetch(`${process.env.METADATA}/video/${id}`)).json()
|
||||||
|
|
||||||
for (let retries = 0; retries < maxRetries; retries++) {
|
|
||||||
try {
|
|
||||||
const platform = platforms[retries % platforms.length];
|
|
||||||
const yt = await Innertube.create();
|
|
||||||
const info = await yt.getInfo(id, platform);
|
|
||||||
|
|
||||||
if (!info) {
|
|
||||||
error = 'ErrorCantConnectToServiceAPI'
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (info.playability_status.status !== 'OK') {
|
|
||||||
error = 'ErrorYTUnavailable'
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (info.basic_info.is_live) {
|
|
||||||
error = 'ErrorLiveVideo'
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (info.basic_info.title == 'Video Not Available') {
|
|
||||||
error = 'YoutubeIsFuckingWithMe'
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
} catch (error) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { error: error || 'ErrorUnknown' }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannel(id) {
|
async function getChannel(id) {
|
||||||
let error = ''
|
return await (await fetch(`${process.env.METADATA}/channel/${id}`)).json()
|
||||||
|
|
||||||
for (let retries = 0; retries < maxRetries; retries++) {
|
|
||||||
try {
|
|
||||||
const platform = platforms[retries % platforms.length];
|
|
||||||
const yt = await Innertube.create();
|
|
||||||
const info = await yt.getChannel(id, platform);
|
|
||||||
|
|
||||||
if (!info) {
|
|
||||||
error = 'ErrorCantConnectToServiceAPI'
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
} catch (error) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { error: error || 'ErrorUnknown' }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannelVideos(id) {
|
async function getChannelVideos(id) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return await (await fetch(`${process.env.METADATA}/videos/${id}`)).json()
|
||||||
try {
|
|
||||||
const videos = [];
|
|
||||||
const yt = await Innertube.create();
|
|
||||||
const channel = await yt.getChannel(id);
|
|
||||||
let json = await channel.getVideos();
|
|
||||||
|
|
||||||
videos.push(...json.videos);
|
|
||||||
|
|
||||||
while (json.has_continuation && videos.length < 60) {
|
|
||||||
json = await getNextPage(json);
|
|
||||||
videos.push(...json.videos);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(videos);
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
resolve(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function getNextPage(json) {
|
|
||||||
const page = await json.getContinuation();
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPlaylistVideos(id) {
|
async function getPlaylistVideos(id) {
|
||||||
|
|
38
yarn.lock
38
yarn.lock
|
@ -16,11 +16,6 @@
|
||||||
enabled "2.0.x"
|
enabled "2.0.x"
|
||||||
kuler "^2.0.0"
|
kuler "^2.0.0"
|
||||||
|
|
||||||
"@fastify/busboy@^2.0.0":
|
|
||||||
version "2.1.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
|
|
||||||
integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==
|
|
||||||
|
|
||||||
"@ioredis/commands@^1.1.1":
|
"@ioredis/commands@^1.1.1":
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"
|
resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"
|
||||||
|
@ -155,11 +150,6 @@ acorn@^8.1.0, acorn@^8.8.1:
|
||||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
|
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.2.tgz#1b2f25db02af965399b9776b0c2c391276d37c4a"
|
||||||
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
|
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
|
||||||
|
|
||||||
acorn@^8.8.0:
|
|
||||||
version "8.11.3"
|
|
||||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a"
|
|
||||||
integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==
|
|
||||||
|
|
||||||
agent-base@6:
|
agent-base@6:
|
||||||
version "6.0.2"
|
version "6.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
|
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77"
|
||||||
|
@ -746,13 +736,6 @@ isomorphic-dompurify@^1.0.0:
|
||||||
dompurify "^3.0.0"
|
dompurify "^3.0.0"
|
||||||
jsdom "^21.1.0"
|
jsdom "^21.1.0"
|
||||||
|
|
||||||
jintr@^1.1.0:
|
|
||||||
version "1.1.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/jintr/-/jintr-1.1.0.tgz#223a3b07f5e03d410cec6e715c537c8ad1e714c3"
|
|
||||||
integrity sha512-Tu9wk3BpN2v+kb8yT6YBtue+/nbjeLFv4vvVC4PJ7oCidHKbifWhvORrAbQfxVIQZG+67am/mDagpiGSVtvrZg==
|
|
||||||
dependencies:
|
|
||||||
acorn "^8.8.0"
|
|
||||||
|
|
||||||
jmespath@0.16.0:
|
jmespath@0.16.0:
|
||||||
version "0.16.0"
|
version "0.16.0"
|
||||||
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076"
|
resolved "https://registry.yarnpkg.com/jmespath/-/jmespath-0.16.0.tgz#b15b0a85dfd4d930d43e69ed605943c802785076"
|
||||||
|
@ -1248,11 +1231,6 @@ triple-beam@^1.3.0:
|
||||||
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
|
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
|
||||||
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==
|
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==
|
||||||
|
|
||||||
tslib@^2.5.0:
|
|
||||||
version "2.6.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
|
|
||||||
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
|
|
||||||
|
|
||||||
tunnel@0.0.6:
|
tunnel@0.0.6:
|
||||||
version "0.0.6"
|
version "0.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
|
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c"
|
||||||
|
@ -1273,13 +1251,6 @@ type-is@~1.6.18:
|
||||||
media-typer "0.3.0"
|
media-typer "0.3.0"
|
||||||
mime-types "~2.1.24"
|
mime-types "~2.1.24"
|
||||||
|
|
||||||
undici@^5.19.1:
|
|
||||||
version "5.28.4"
|
|
||||||
resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068"
|
|
||||||
integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==
|
|
||||||
dependencies:
|
|
||||||
"@fastify/busboy" "^2.0.0"
|
|
||||||
|
|
||||||
universalify@^0.2.0:
|
universalify@^0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
|
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
|
||||||
|
@ -1447,12 +1418,3 @@ xmlchars@^2.2.0:
|
||||||
version "2.2.0"
|
version "2.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
|
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"
|
||||||
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==
|
integrity sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==
|
||||||
|
|
||||||
youtubei.js@^9.2.0:
|
|
||||||
version "9.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/youtubei.js/-/youtubei.js-9.2.0.tgz#26d521a0803ddd3ab5059a7b7eb5970514d883a4"
|
|
||||||
integrity sha512-Q157iNPlyB32477xU+1/+Pyz/Bxy9zLJ1sXLjn96qhBZ03wWHVwh2azeyz7jk13UvcrxZXtIYv9HHn2dFngGnQ==
|
|
||||||
dependencies:
|
|
||||||
jintr "^1.1.0"
|
|
||||||
tslib "^2.5.0"
|
|
||||||
undici "^5.19.1"
|
|
||||||
|
|
Loading…
Reference in New Issue