Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/apify/scrapeProfileUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions lib/socials/getUsernameFromProfileUrl.ts
Original file line number Diff line number Diff line change
@@ -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 empty string if unable to extract
*/
Comment thread
sweetmantech marked this conversation as resolved.
export const getUsernameFromProfileUrl = (
profileUrl: string | null | undefined
): string => {
if (!profileUrl) {
return "";
}

try {
const normalizedUrl = profileUrl.toLowerCase().trim();
const match = normalizedUrl.match(/(?:\.com|\.net)\/([^/?]+)/);
return match ? match[1] : "";
} catch (error) {
console.error("[ERROR] Error extracting username from profile URL:", error);
return "";
}
};