mirror of
https://github.com/wukko/cobalt.git
synced 2025-06-12 13:17:45 +02:00
5.4: instagram support
This commit is contained in:
@ -15,6 +15,7 @@ import tiktok from "./services/tiktok.js";
|
||||
import tumblr from "./services/tumblr.js";
|
||||
import vimeo from "./services/vimeo.js";
|
||||
import soundcloud from "./services/soundcloud.js";
|
||||
import instagram from "./services/instagram.js";
|
||||
|
||||
export default async function (host, patternMatch, url, lang, obj) {
|
||||
try {
|
||||
@ -102,6 +103,9 @@ export default async function (host, patternMatch, url, lang, obj) {
|
||||
format: obj.aFormat
|
||||
});
|
||||
break;
|
||||
case "instagram":
|
||||
r = await instagram({ id: patternMatch["id"] ? patternMatch["id"] : false });
|
||||
break;
|
||||
default:
|
||||
return apiJSON(0, { t: errorUnsupported(lang) });
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMute
|
||||
params = { type: "bridge" };
|
||||
break;
|
||||
|
||||
case "instagram":
|
||||
case "tumblr":
|
||||
case "twitter":
|
||||
responseType = 1;
|
||||
@ -72,6 +73,7 @@ export default function(r, host, ip, audioFormat, isAudioOnly, lang, isAudioMute
|
||||
case "picker":
|
||||
responseType = 5;
|
||||
switch (host) {
|
||||
case "instagram":
|
||||
case "twitter":
|
||||
params = { picker: r.picker };
|
||||
break;
|
||||
|
36
src/modules/processing/services/instagram.js
Normal file
36
src/modules/processing/services/instagram.js
Normal file
@ -0,0 +1,36 @@
|
||||
import got from "got";
|
||||
|
||||
export default async function(obj) {
|
||||
// i hate this implementation but fetch doesn't work here for some reason (i personally blame facebook)
|
||||
let html;
|
||||
try {
|
||||
html = await got.get(`https://www.instagram.com/p/${obj.id}/`)
|
||||
html.on('error', () => {
|
||||
html = false;
|
||||
});
|
||||
html = html ? html.body : false;
|
||||
} catch (e) {
|
||||
html = false;
|
||||
}
|
||||
|
||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||
if (!html.includes('application/ld+json')) return { error: 'ErrorEmptyDownload' };
|
||||
|
||||
let single, multiple = [], postInfo = JSON.parse(html.split('script type="application/ld+json"')[1].split('">')[1].split('</script>')[0]);
|
||||
|
||||
if (postInfo.video.length > 1) {
|
||||
for (let i in postInfo.video) { multiple.push({type: "video", thumb: postInfo.video[i]["thumbnailUrl"], url: postInfo.video[i]["contentUrl"]}) }
|
||||
} else if (postInfo.video.length === 1) {
|
||||
single = postInfo.video[0]["contentUrl"]
|
||||
} else {
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
|
||||
if (single) {
|
||||
return { urls: single, filename: `instagram_${obj.id}.mp4`, audioFilename: `instagram_${obj.id}_audio` }
|
||||
} else if (multiple) {
|
||||
return { picker: multiple }
|
||||
} else {
|
||||
return { error: 'ErrorEmptyDownload' }
|
||||
}
|
||||
}
|
@ -36,12 +36,13 @@ async function findClientID() {
|
||||
export default async function(obj) {
|
||||
let html;
|
||||
if (!obj.author && !obj.song && obj.shortLink) {
|
||||
html = await fetch(`https://soundcloud.app.goo.gl/${obj.shortLink}/`).then((r) => { return r.text() }).catch(() => { return false });
|
||||
html = await fetch(`https://soundcloud.app.goo.gl/${obj.shortLink}/`).then((r) => { return r.status === 404 ? false : r.text() }).catch(() => { return false });
|
||||
if (!html) html = await fetch(`https://on.soundcloud.com/${obj.shortLink}/`).then((r) => { return r.status === 404 ? false : r.text() }).catch(() => { return false })
|
||||
}
|
||||
if (obj.author && obj.song) {
|
||||
html = await fetch(`https://soundcloud.com/${obj.author}/${obj.song}${obj.accessKey ? `/s-${obj.accessKey}` : ''}`).then((r) => { return r.text() }).catch(() => { return false });
|
||||
}
|
||||
if (!html) return { error: 'ErrorCouldntFetch'};
|
||||
if (!html) return { error: 'ErrorCouldntFetch' };
|
||||
if (!(html.includes('<script>window.__sc_hydration = ')
|
||||
&& html.includes('"format":{"protocol":"progressive","mime_type":"audio/mpeg"},')
|
||||
&& html.includes('{"hydratable":"sound","data":'))) {
|
||||
|
@ -51,6 +51,11 @@
|
||||
"patterns": [":author/:song/s-:accessKey", ":author/:song", ":shortLink"],
|
||||
"bestAudio": "none",
|
||||
"enabled": true
|
||||
},
|
||||
"instagram": {
|
||||
"alias": "instagram reels & video posts",
|
||||
"patterns": ["reels/:id", "reel/:id", "p/:id"],
|
||||
"enabled": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,9 @@ export const testers = {
|
||||
"vk": (patternMatch) => (patternMatch["userId"] && patternMatch["videoId"]
|
||||
&& patternMatch["userId"].length <= 10 && patternMatch["videoId"].length === 9),
|
||||
|
||||
"bilibili": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length >= 12),
|
||||
"bilibili": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12),
|
||||
|
||||
"youtube": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length >= 11),
|
||||
"youtube": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 11),
|
||||
|
||||
"reddit": (patternMatch) => (patternMatch["sub"] && patternMatch["id"] && patternMatch["title"]
|
||||
&& patternMatch["sub"].length <= 22 && patternMatch["id"].length <= 10 && patternMatch["title"].length <= 96),
|
||||
@ -24,5 +24,7 @@ export const testers = {
|
||||
"vimeo": (patternMatch) => ((patternMatch["id"] && patternMatch["id"].length <= 11)),
|
||||
|
||||
"soundcloud": (patternMatch) => ((patternMatch["author"] && patternMatch["song"]
|
||||
&& (patternMatch["author"].length + patternMatch["song"].length) <= 96) || (patternMatch["shortLink"] && patternMatch["shortLink"].length <= 32))
|
||||
&& (patternMatch["author"].length + patternMatch["song"].length) <= 96) || (patternMatch["shortLink"] && patternMatch["shortLink"].length <= 32)),
|
||||
|
||||
"instagram": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length <= 12)
|
||||
}
|
||||
|
Reference in New Issue
Block a user