diff --git a/cli/import-organizer/instagram.ts b/cli/import-organizer/instagram.ts new file mode 100644 index 00000000..58d29f5a --- /dev/null +++ b/cli/import-organizer/instagram.ts @@ -0,0 +1,52 @@ +import { IgApiClient } from 'instagram-private-api' + +export type InstagramProfileData = { + username: string + fullName: string + biography: string + photoUrl?: string + externalUrl?: string + followerCount: number + isVerified: boolean +} + +export async function getInstagramProfile( + instagramUrl: string +): Promise { + const username = instagramUrl + .replace('https://', '') + .replace('http://', '') + .replace('www.', '') + .replace('instagram.com/', '') + .replace('instagr.am/', '') + .replace(/\/$/, '') + .split('/')[0] + .split('?')[0] + + if (!username) { + throw new Error('Invalid Instagram URL: could not extract valid username') + } + console.log(`Fetching instagram profile for ${username}`) + const instagram = new IgApiClient() + + const IG_USER = process.env.INSTAGRAM_USERNAME + const IG_PASS = process.env.INSTAGRAM_PASSWORD + if (!IG_USER || !IG_PASS) { + throw new Error('INSTAGRAM_USERNAME and INSTAGRAM_PASSWORD must be set') + } + + instagram.state.generateDevice(IG_USER) + await instagram.account.login(IG_USER, IG_PASS) + const userInfo = await instagram.user.usernameinfo(username) + + console.log(`Successfully fetched data for @${username}`) + return { + username: userInfo.username, + fullName: userInfo.full_name || username, + biography: userInfo.biography || '', + photoUrl: userInfo.profile_pic_url || '', + externalUrl: userInfo.external_url || '', + followerCount: userInfo.follower_count || 0, + isVerified: userInfo.is_verified || false, + } +} diff --git a/components/inputs/ProfileInput.vue b/components/inputs/ProfileInput.vue index a738fecd..ed06b21d 100644 --- a/components/inputs/ProfileInput.vue +++ b/components/inputs/ProfileInput.vue @@ -1,16 +1,74 @@