feat: add ability to scrape youtube video

This commit is contained in:
2023-08-02 15:56:33 +02:00
parent cebbb8af2b
commit ba853342bd
10 changed files with 193 additions and 36 deletions

View File

@@ -30,3 +30,26 @@ export function extractHashTags(inputString: string) {
return hashtags;
}
export const isYoutubeLink = (link: string) => {
try {
const url = new URL(link);
return ["youtu.be", "youtube.com","www.youtube.com" ].includes(url.hostname);
} catch (err) {
console.log(err);
return false;
}
};
export function extractYoutubeId(link: string) {
const url = new URL(link);
if (url.searchParams.has("v")) {
const id = url.searchParams.get("v");
if (id?.length && id.length > 4) {
return id;
}
}
return url.pathname.replace(/^\//, "");
}