From 4e5e5a527986e6aa1c7a7762f1d935d20772a7d3 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Fri, 14 Nov 2025 21:09:59 -0500 Subject: [PATCH 1/3] fallback username with getUsernameFromProfileUrl --- lib/apify/scrapeProfileUrl.ts | 5 ++++- lib/socials/getUsernameFromProfileUrl.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/socials/getUsernameFromProfileUrl.ts diff --git a/lib/apify/scrapeProfileUrl.ts b/lib/apify/scrapeProfileUrl.ts index b786dd6..89e7448 100644 --- a/lib/apify/scrapeProfileUrl.ts +++ b/lib/apify/scrapeProfileUrl.ts @@ -4,6 +4,7 @@ import startTwitterProfileScraping from "../twitter/startTwitterProfileScraping" import startThreadsProfileScraping from "../threads/startThreadsProfileScraping"; import startYoutubeProfileScraping from "../youtube/startYoutubeProfileScraping"; import startFacebookProfileScraping from "../facebook/startFacebookProfileScraping"; +import { getUsernameFromProfileUrl } from "../socials/getUsernameFromProfileUrl"; type ScrapeRunner = (handle: string) => Promise<{ runId: string; @@ -71,8 +72,10 @@ export const scrapeProfileUrl = async ( return null; } + const finalUsername = username || getUsernameFromProfileUrl(profileUrl); + try { - const result = await platform.scraper(username); + const result = await platform.scraper(finalUsername ?? ""); if (!result) { return { diff --git a/lib/socials/getUsernameFromProfileUrl.ts b/lib/socials/getUsernameFromProfileUrl.ts new file mode 100644 index 0000000..e5029c0 --- /dev/null +++ b/lib/socials/getUsernameFromProfileUrl.ts @@ -0,0 +1,21 @@ +/** + * Extracts username from a profile URL by pulling text after .com/ or .net/ until ? or / + * @param profileUrl - The profile URL to extract username from + * @returns The username or null if unable to extract + */ +export const getUsernameFromProfileUrl = ( + profileUrl: string | null | undefined +): string | null => { + if (!profileUrl) { + return null; + } + + try { + const normalizedUrl = profileUrl.toLowerCase().trim(); + const match = normalizedUrl.match(/(?:\.com|\.net)\/([^/?]+)/); + return match ? match[1] : null; + } catch (error) { + console.error("[ERROR] Error extracting username from profile URL:", error); + return null; + } +}; From bdd703fe6840435a33e4d5d5de62e36503588054 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Fri, 14 Nov 2025 21:15:21 -0500 Subject: [PATCH 2/3] always return string. --- lib/apify/scrapeProfileUrl.ts | 2 +- lib/socials/getUsernameFromProfileUrl.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/apify/scrapeProfileUrl.ts b/lib/apify/scrapeProfileUrl.ts index 89e7448..2ca5934 100644 --- a/lib/apify/scrapeProfileUrl.ts +++ b/lib/apify/scrapeProfileUrl.ts @@ -75,7 +75,7 @@ export const scrapeProfileUrl = async ( const finalUsername = username || getUsernameFromProfileUrl(profileUrl); try { - const result = await platform.scraper(finalUsername ?? ""); + const result = await platform.scraper(finalUsername); if (!result) { return { diff --git a/lib/socials/getUsernameFromProfileUrl.ts b/lib/socials/getUsernameFromProfileUrl.ts index e5029c0..ae82cc8 100644 --- a/lib/socials/getUsernameFromProfileUrl.ts +++ b/lib/socials/getUsernameFromProfileUrl.ts @@ -5,17 +5,17 @@ */ export const getUsernameFromProfileUrl = ( profileUrl: string | null | undefined -): string | null => { +): string => { if (!profileUrl) { - return null; + return ""; } try { const normalizedUrl = profileUrl.toLowerCase().trim(); const match = normalizedUrl.match(/(?:\.com|\.net)\/([^/?]+)/); - return match ? match[1] : null; + return match ? match[1] : ""; } catch (error) { console.error("[ERROR] Error extracting username from profile URL:", error); - return null; + return ""; } }; From ff4111d17ac81c732a1dd9e16b9f5697e26d2cd7 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Fri, 14 Nov 2025 21:25:43 -0500 Subject: [PATCH 3/3] fix docs --- lib/socials/getUsernameFromProfileUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/socials/getUsernameFromProfileUrl.ts b/lib/socials/getUsernameFromProfileUrl.ts index ae82cc8..c416728 100644 --- a/lib/socials/getUsernameFromProfileUrl.ts +++ b/lib/socials/getUsernameFromProfileUrl.ts @@ -1,7 +1,7 @@ /** * Extracts username from a profile URL by pulling text after .com/ or .net/ until ? or / * @param profileUrl - The profile URL to extract username from - * @returns The username or null if unable to extract + * @returns The username or empty string if unable to extract */ export const getUsernameFromProfileUrl = ( profileUrl: string | null | undefined