Skip to content

Commit 3c081fe

Browse files
committed
Added new scrapping case for likes in MoreVideoInfosResponse.
1 parent aa9e33e commit 3c081fe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Sources/YouTubeKit/YouTubeResponseTypes/VideoInfos/MoreVideoInfosResponse.swift

+15
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ public struct MoreVideoInfosResponse: YouTubeResponse {
106106
}
107107
toReturn.likesCount.likeButtonClickedNewValue = button["segmentedLikeDislikeButtonRenderer"]["likeButton"]["toggleButtonRenderer"]["toggledText"]["simpleText"].string
108108
break
109+
} else if button["segmentedLikeDislikeButtonViewModel"].exists() { // new button
110+
let likeStatus = button["segmentedLikeDislikeButtonViewModel"]["likeButtonViewModel"]["likeButtonViewModel"]["likeStatusEntity"]["likeStatus"].stringValue
111+
if isAccountConnected {
112+
switch likeStatus {
113+
case "LIKE":
114+
toReturn.authenticatedInfos?.likeStatus = .liked
115+
case "DISLIKE":
116+
toReturn.authenticatedInfos?.likeStatus = .disliked
117+
default:
118+
toReturn.authenticatedInfos?.likeStatus = .nothing
119+
}
120+
}
121+
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
122+
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
123+
break
109124
}
110125
}
111126
} else if contentPart["videoSecondaryInfoRenderer"].exists() {

Tests/YouTubeKitTests/YouTubeKitTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ final class YouTubeKitTests: XCTestCase {
662662
XCTAssertNotNil(moreVideoInfosResponse.channel, TEST_NAME + "Checking if the channel has been extracted.")
663663
XCTAssertNotNil(moreVideoInfosResponse.commentsCount, TEST_NAME + "Checking if the commentsCount has been extracted.")
664664
XCTAssertNotNil(moreVideoInfosResponse.likesCount.defaultState, TEST_NAME + "Checking if the likesCount has been extracted.")
665-
XCTAssertNotEqual(moreVideoInfosResponse.recommendedVideos.count, 0, TEST_NAME + "Checking if recommendedVideos are not empty.")
666665
XCTAssertNotNil(moreVideoInfosResponse.recommendedVideosContinuationToken, TEST_NAME + "Checking if the recommendedVideosContinuationToken has been extracted.")
667666
XCTAssertNotNil(moreVideoInfosResponse.timePosted.postedDate, TEST_NAME + "Checking if the timePosted.postedDate has been extracted.")
668667
XCTAssertNotNil(moreVideoInfosResponse.timePosted.relativePostedDate, TEST_NAME + "Checking if the timePosted.relativePostedDate has been extracted.")
@@ -676,6 +675,8 @@ final class YouTubeKitTests: XCTestCase {
676675

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

678+
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}
679+
679680
XCTAssertNotEqual(recommendedVideosContinuationResponse.results.count, 0, TEST_NAME + "Checking if results for continuation have been extracted.")
680681
XCTAssertNotNil(recommendedVideosContinuationResponse.continuationToken, TEST_NAME + "Checking if continuationToken has been extracted.")
681682
let initialRecommendedVideosCount = moreVideoInfosResponse.recommendedVideos.count

0 commit comments

Comments
 (0)