-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,53 @@ | ||
import { getComments } from "."; | ||
import { csc } from "../protobuf/assembler"; | ||
import assert from "assert"; | ||
import { getComment, getComments } from "."; | ||
import { YTCommentThreadRenderer } from ".."; | ||
import { stringify } from "../utils"; | ||
|
||
it("can fetch comments", async () => { | ||
const videoId = "q5ctC_sWU4g"; | ||
const commentId = "UgzNuL5flAW9vygeE9V4AaABAg"; | ||
|
||
const res = await getComments(videoId, { | ||
highlightedCommentId: commentId, | ||
}); | ||
const res = await getComments(videoId, { top: true }); | ||
const first = res.comments[0]; | ||
prettyPrint(first); | ||
}); | ||
|
||
it("can fetch comment by id", async () => { | ||
const videoId = "q5ctC_sWU4g"; | ||
const commentId = "UgzNuL5flAW9vygeE9V4AaABAg"; | ||
|
||
const comment = await getComment(videoId, commentId); | ||
assert(comment); | ||
|
||
prettyPrint(comment); | ||
const fetchedId = comment.comment.commentRenderer.commentId; | ||
|
||
expect(fetchedId).toEqual(commentId); | ||
}); | ||
|
||
it("return undefined if wrong id specified", async () => { | ||
const videoId = "q5ctC_sWU4g"; | ||
const commentId = "UgzNuL5flAW9vygeE9V4AaABAgwrong"; | ||
|
||
const comment = await getComment(videoId, commentId); | ||
expect(comment).toBeUndefined(); | ||
}); | ||
|
||
function prettyPrint(comment: YTCommentThreadRenderer) { | ||
const id = comment.comment.commentRenderer.commentId; | ||
const membership = | ||
first.comment.commentRenderer.sponsorCommentBadge | ||
comment.comment.commentRenderer.sponsorCommentBadge | ||
?.sponsorCommentBadgeRenderer.tooltip; | ||
const authorName = first.comment.commentRenderer.authorText.simpleText; | ||
console.log("Membership status for comment id:", commentId, "is", membership); | ||
}); | ||
const authorName = comment.comment.commentRenderer.authorText.simpleText; | ||
const message = stringify(comment.comment.commentRenderer.contentText); | ||
|
||
console.log( | ||
"id:", | ||
id, | ||
"membership:", | ||
membership, | ||
"author:", | ||
authorName, | ||
"message:", | ||
message | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters