-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
145692a
commit 785391d
Showing
9 changed files
with
99 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as instagramdl } from './src/instagramdl-v1.js' | ||
export { default as instagramdl } from './src/instagramdl-v1.js' | ||
export { default as instagramStory } from './src/instagramstory-v1.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import got from 'got' | ||
import cheerio from 'cheerio' | ||
import { DEFAULT_HEADERS } from './constant.js' | ||
import { | ||
InstagramStory, | ||
InstagramStoryArgsSchema, | ||
InstagramStoryItem, | ||
InstagramStorySchema | ||
} from '../types/instagramstory-v1.js' | ||
|
||
export default async function instagramStory (username: string) { | ||
InstagramStoryArgsSchema.parse(arguments) | ||
|
||
const form = { | ||
url: `https://www.instagram.com/${username}/`, | ||
lang_code: 'en', | ||
token: '' | ||
} | ||
const data = await got.post('https://fastdl.app/c/', { | ||
headers: { | ||
...DEFAULT_HEADERS, | ||
'content-type': 'application/x-www-form-urlencoded', | ||
origin: 'https://fastdl.app', | ||
'referer': 'https://fastdl.app/en/story-saver' | ||
}, | ||
form | ||
}).text() | ||
const $ = cheerio.load(data) | ||
const results: InstagramStory = [] | ||
$('div.max-w-md').each(function () { | ||
const $el = $(this) | ||
const thumbnail = $el.find('img.w-full').attr('src')! | ||
const $a = $el.find('a') | ||
const url = $a.attr('href')! | ||
const type = $a.attr('data-mediatype')!.toLowerCase() as InstagramStoryItem['type'] | ||
results.push({ | ||
thumbnail, | ||
url, | ||
type | ||
}) | ||
}) | ||
return InstagramStorySchema.parse(results) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { instagramStory } from '../index.js' | ||
import { test } from 'node:test' | ||
import assert from 'node:assert' | ||
import got from 'got' | ||
import { InstagramStory } from '../types/instagramstory-v1.js' | ||
|
||
const USERNAME = 'raffinagita1717' | ||
|
||
test('Instagram Story Downloader', async (t) => { | ||
let stories: InstagramStory | ||
await t.test('Getting Metadata', async () => { | ||
stories = await instagramStory(USERNAME) | ||
assert.strictEqual(stories.length > 0, true) | ||
}) | ||
|
||
await t.test('Download Story', async () => { | ||
if (!stories.length) | ||
return t.skip('Test skipped -- error in getting metadata!') | ||
const [{ url }] = stories | ||
const buffer = await got(url).buffer() | ||
assert.strictEqual(buffer.byteLength > 0, true) | ||
}) | ||
|
||
await t.test('Download Story Thumbnail', async () => { | ||
if (!stories.length) | ||
return t.skip('Test skipped -- error in getting metadata!') | ||
const [{ thumbnail }] = stories | ||
const buffer = await got(thumbnail).buffer() | ||
assert.strictEqual(buffer.byteLength > 0, true) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod' | ||
|
||
export const InstagramStoryArgsSchema = z.object({ | ||
0: z.string() | ||
}) | ||
export const InstagramStoryItemSchema = z.object({ | ||
thumbnail: z.string().url(), | ||
url: z.string().url(), | ||
type: z.literal('image').or(z.literal('video')) | ||
}) | ||
export type InstagramStoryItem = z.infer<typeof InstagramStoryItemSchema> | ||
export const InstagramStorySchema = z.array(InstagramStoryItemSchema) | ||
export type InstagramStory = z.infer<typeof InstagramStorySchema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters