no need for closest quality btw
This commit is contained in:
wukko 2023-10-14 23:48:06 +06:00
parent 1504a8bae9
commit 866792c8d5

View file

@ -56,24 +56,23 @@ async function getPost(id) {
const sidecar = data?.shortcode_media?.edge_sidecar_to_children; const sidecar = data?.shortcode_media?.edge_sidecar_to_children;
if (sidecar) { if (sidecar) {
const picker = sidecar.edges const picker = sidecar.edges.filter(e => e.node?.display_url)
.filter(e => e.node?.display_url) .map(e => {
.map(e => { const type = e.node?.is_video ? "video" : "photo";
const type = e.node?.is_video ? "video" : "photo"; const url = type === "video" ? e.node?.video_url : e.node?.display_url;
const url = type === "video" ? e.node?.video_url : e.node?.display_url;
return { return {
type, url, type, url,
/* thumbnails have `Cross-Origin-Resource-Policy` /* thumbnails have `Cross-Origin-Resource-Policy`
** set to `same-origin`, so we need to proxy them */ ** set to `same-origin`, so we need to proxy them */
thumb: createStream({ thumb: createStream({
service: "instagram", service: "instagram",
type: "default", type: "default",
u: e.node?.display_url, u: e.node?.display_url,
filename: "image.jpg" filename: "image.jpg"
}) })
} }
}); });
if (picker.length) return { picker } if (picker.length) return { picker }
} else if (data?.shortcode_media?.video_url) { } else if (data?.shortcode_media?.video_url) {
@ -94,7 +93,7 @@ async function getPost(id) {
async function usernameToId(username, cookie) { async function usernameToId(username, cookie) {
const url = new URL('https://www.instagram.com/api/v1/users/web_profile_info/'); const url = new URL('https://www.instagram.com/api/v1/users/web_profile_info/');
url.searchParams.set('username', username); url.searchParams.set('username', username);
try { try {
const data = await request(url, cookie); const data = await request(url, cookie);
@ -123,11 +122,7 @@ async function getStory(username, id) {
if (!item) return { error: 'ErrorEmptyDownload' }; if (!item) return { error: 'ErrorEmptyDownload' };
if (item.video_versions) { if (item.video_versions) {
// todo: closest quality? const video = item.video_versions.reduce((a, b) => a.width * a.height < b.width * b.height ? b : a)
const video = item.video_versions.reduce(
(a, b) => a.width * a.height < b.width * b.height ? b : a
)
return { return {
urls: video.url, urls: video.url,
filename: `instagram_${id}.mp4`, filename: `instagram_${id}.mp4`,