Skip to content

Commit

Permalink
Added new scrapping case for likes in MoreVideoInfosResponse.
Browse files Browse the repository at this point in the history
  • Loading branch information
b5i committed Feb 1, 2024
1 parent aa9e33e commit 3c081fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public struct MoreVideoInfosResponse: YouTubeResponse {
}
toReturn.likesCount.likeButtonClickedNewValue = button["segmentedLikeDislikeButtonRenderer"]["likeButton"]["toggleButtonRenderer"]["toggledText"]["simpleText"].string
break
} else if button["segmentedLikeDislikeButtonViewModel"].exists() { // new button
let likeStatus = button["segmentedLikeDislikeButtonViewModel"]["likeButtonViewModel"]["likeButtonViewModel"]["likeStatusEntity"]["likeStatus"].stringValue
if isAccountConnected {
switch likeStatus {
case "LIKE":
toReturn.authenticatedInfos?.likeStatus = .liked
case "DISLIKE":
toReturn.authenticatedInfos?.likeStatus = .disliked
default:
toReturn.authenticatedInfos?.likeStatus = .nothing
}
}
toReturn.likesCount.defaultState = button["segmentedLikeDislikeButtonViewModel"]["likeCountEntity"]["likeCountIfIndifferent"]["content"].string ?? /* usually because there is no account connected */ button["segmentedLikeDislikeButtonViewModel"]["likeButtonViewModel"]["likeButtonViewModel"]["toggleButtonViewModel"]["toggleButtonViewModel"]["toggledButtonViewModel"]["buttonViewModel"]["title"].string
toReturn.likesCount.likeButtonClickedNewValue = button["segmentedLikeDislikeButtonViewModel"]["likeCountEntity"]["likeCountIfLiked"]["content"].string ?? /* usually because there is no account connected */ button["segmentedLikeDislikeButtonViewModel"]["likeButtonViewModel"]["likeButtonViewModel"]["toggleButtonViewModel"]["toggleButtonViewModel"]["defaultButtonViewModel"]["buttonViewModel"]["title"].string
break
}
}
} else if contentPart["videoSecondaryInfoRenderer"].exists() {
Expand Down
3 changes: 2 additions & 1 deletion Tests/YouTubeKitTests/YouTubeKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ final class YouTubeKitTests: XCTestCase {
XCTAssertNotNil(moreVideoInfosResponse.channel, TEST_NAME + "Checking if the channel has been extracted.")
XCTAssertNotNil(moreVideoInfosResponse.commentsCount, TEST_NAME + "Checking if the commentsCount has been extracted.")
XCTAssertNotNil(moreVideoInfosResponse.likesCount.defaultState, TEST_NAME + "Checking if the likesCount has been extracted.")
XCTAssertNotEqual(moreVideoInfosResponse.recommendedVideos.count, 0, TEST_NAME + "Checking if recommendedVideos are not empty.")
XCTAssertNotNil(moreVideoInfosResponse.recommendedVideosContinuationToken, TEST_NAME + "Checking if the recommendedVideosContinuationToken has been extracted.")
XCTAssertNotNil(moreVideoInfosResponse.timePosted.postedDate, TEST_NAME + "Checking if the timePosted.postedDate has been extracted.")
XCTAssertNotNil(moreVideoInfosResponse.timePosted.relativePostedDate, TEST_NAME + "Checking if the timePosted.relativePostedDate has been extracted.")
Expand All @@ -676,6 +675,8 @@ final class YouTubeKitTests: XCTestCase {

guard let recommendedVideosContinuationResponse = recommendedVideosContinuationResponse else { XCTFail(TEST_NAME + "Checking if recommendedVideosResponse is defined, error -> \(String(describing: recommendedVideosContinuationError))"); return }

guard !(moreVideoInfosResponse.recommendedVideos.isEmpty && recommendedVideosContinuationResponse.results.isEmpty) else { XCTFail(TEST_NAME + "No recommanded videos in the first place nor with the continuationResponse, error -> \(String(describing: recommendedVideosContinuationError))"); return}

XCTAssertNotEqual(recommendedVideosContinuationResponse.results.count, 0, TEST_NAME + "Checking if results for continuation have been extracted.")
XCTAssertNotNil(recommendedVideosContinuationResponse.continuationToken, TEST_NAME + "Checking if continuationToken has been extracted.")
let initialRecommendedVideosCount = moreVideoInfosResponse.recommendedVideos.count
Expand Down

0 comments on commit 3c081fe

Please sign in to comment.