-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get username #24
Comments
Hey, you can get the username from the meta elements like so by making these changes in function getUsernameFromPostHtml(postHtml: CheerioAPI){
const titleMetaContent = postHtml("meta[name='twitter:title']").attr("content") ?? ""
if(titleMetaContent.length === 0){
return null;
}
return titleMetaContent.split("@")[1].split(")")[0]
} and you can add it here: export const formatPageJson = (postHtml: CheerioAPI) => {
const videoElement = postHtml("meta[property='og:video']");
if (videoElement.length === 0) {
return null;
}
const videoUrl = videoElement.attr("content");
if (!videoUrl) return null;
const width =
postHtml("meta[property='og:video:width']").attr("content") ?? "";
const height =
postHtml("meta[property='og:video:height']").attr("content") ?? "";
const filename = getIGVideoFileName();
const username = getUsernameFromPostHtml(postHtml)
const videoJson: VideoInfo = {
filename,
username.
width,
height,
videoUrl,
};
return videoJson;
}; as for the graphal you can simply: export const formatGraphqlJson = (data: MediaData) => {
const filename = getIGVideoFileName();
const username = data.owner.username ?? null;
const width = data.dimensions.width.toString();
const height = data.dimensions.height.toString();
const videoUrl = data.video_url;
const videoJson: VideoInfo = {
filename,
username
width,
height,
videoUrl,
};
return videoJson;
}; and of course dont forget to update the export type VideoInfo = {
filename: string;
username: string | null;
width: string;
height: string;
videoUrl: string;
}; |
@riad-azz is there a way to get caption or description of the video ? |
you can do the same as the username one, scrape in the postHtml side and get it from the graphql on the API |
@riad-azz what is the element name for caption ? |
would appreciate if you can write with full code like above. thanks |
Hey, I would be happy to try and help |
function getCaptionFromPostHtml(postHtml: CheerioAPI) {
const captionEleOne = postHtml("[role=presentation] ul li h2+div");
if (captionEleOne.length !== 0) {
return captionEleOne.text();
}
const captionEleTwo = postHtml(
"[role=main] hr + div div:not([class]) span > div > span"
);
if (captionEleTwo.length !== 0) {
return captionEleTwo.text();
}
return null;
} |
Is there any way to get the username of the owner in the api?
The text was updated successfully, but these errors were encountered: