feat: add ability to scrape youtube video
This commit is contained in:
@@ -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(/^\//, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user