Skip to content
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

[YouTube] Drop support for removed dislikes #7410

Merged
merged 4 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions services/youtube/youtube-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const schema = Joi.object({
Joi.object({
viewCount: nonNegativeInteger,
subscriberCount: nonNegativeInteger,
}),
Joi.object({
viewCount: nonNegativeInteger,
likeCount: nonNegativeInteger,
commentCount: nonNegativeInteger,
favoriteCount: nonNegativeInteger,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know we don't actually need the favoriteCount value for any of our badges, so instead of adding what is essentially a duplicate schema for statistics, let's instead make the dislikeCount field optional by changing from nonNegativeInteger to optionalNonNegativeInteger (which can be imported from the same validators module)

})
),
})
Expand Down
9 changes: 6 additions & 3 deletions services/youtube/youtube-likes.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ export default class YouTubeLikes extends YouTubeVideoBase {
id,
})
if (queryParams && typeof queryParams.withDislikes !== 'undefined') {
const likes = `${metric(statistics.likeCount)} 👍`
const dislikes =
statistics.dislikeCount !== undefined
? `${metric(statistics.dislikeCount)} 👎`
: ''
renderedBadge = {
...renderedBadge,
message: `${metric(statistics.likeCount)} 👍 ${metric(
statistics.dislikeCount
)} 👎`,
message: `${likes} ${dislikes}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have the withDislikes query parameter that allows the user to control whether or not the dislikes are included on their badge. If we hit this block then the user has explicitly asked for the dislike portion to be included as well, and as such we should instead display 0 👎.

Perhaps ${metric(statistics.dislikeCount || 0)} 👎 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But 0 👎 looks like there is no 👎, while in fact this is unknown. I was choosing between not presenting this piece or using ? 👎. I'm against using 0 for the case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while in fact this is unknown.

What is your evidence for this? Do you have some documentation to the API or an example target that includes a "dislikeCount": 0 in the response?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, https://techcrunch.com/2021/11/10/youtube-is-removing-the-dislike-count-on-all-videos-across-its-platform/

Youtube has dropped the dislike count from public view altogether, and that's not something we'll ever be able to see. I think we should actually remove dislikes across the board

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather like this PR to only restore YT stats.
I think total dislikes removal could be the subject for the next one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a feature that was based on an attribute in the API response that no longer exists, which in turn has broken badges. I don't understand what you're suggesting be split, could you elaborate?

We need a resolution to the actual issue, i.e. our badge needs to account for the upstream change. Splitting that into multiple PRs with ~5 line diffs is unnecessary overhead for us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting that into multiple PRs with ~5 line diffs is unnecessary overhead for us

Understood.

Removed code IMO related to the dislikes.
Locally tested that the old links, with (now unused) parameter withDislikes render the no-parameterized version fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks so much! Will give this a final pass here shortly

}
}
return renderedBadge
Expand Down
2 changes: 1 addition & 1 deletion services/youtube/youtube-likes.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ t.create('video vote count')
.expectBadge({
label: 'likes',
message: Joi.string().regex(
/^([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👍 ([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👎$/
/^([1-9][0-9]*[kMGTPEZY]?|[1-9]\.[1-9][kMGTPEZY]) 👍$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at the tests but as noted above we need to change the behavior a bit.

Additionally, we should instead add a new test for the scenario described in #7373. Given the specific use case of a missing dislikeCount field, it would probably be better for that to be a mocked test (https://github.com/badges/shields/blob/master/doc/service-tests.md#5-mocking-responses) given the likelihood for the upstream target to change/receive dislikes

),
color: 'red',
link: ['https://www.youtube.com/video/pU9Q6oiQNd0'],
Expand Down