Skip to content

Commit 448e495

Browse files
committed
fix: fix MoreVideoInfosResponse not having any recommended video without using RecommendedVideosContinuation
1 parent cd24dfc commit 448e495

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

Sources/YouTubeKit/YouTubeResponseTypes/VideoInfos/MoreVideoInfosResponse.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,20 @@ public struct MoreVideoInfosResponse: YouTubeResponse {
265265
}
266266

267267
for recommendation in json["contents", "twoColumnWatchNextResults", "secondaryResults", "secondaryResults", "results"].arrayValue {
268-
if recommendation["itemSectionRenderer", "contents"].exists() {
268+
if recommendation["lockupViewModel"].exists() {
269+
if let decodedVideo = YTVideo.decodeLockupJSON(json: recommendation["lockupViewModel"]) {
270+
toReturn.recommendedVideos.append(decodedVideo)
271+
}
272+
} else if recommendation["itemSectionRenderer", "contents"].exists() {
269273
for element in recommendation["itemSectionRenderer", "contents"].arrayValue {
270-
if element["compactVideoRenderer", "videoId"].exists(), let decodedVideo = YTVideo.decodeJSON(json: element["compactVideoRenderer"]) {
271-
toReturn.recommendedVideos.append(decodedVideo)
274+
if element["lockupViewModel"].exists() {
275+
if let decodedVideo = YTVideo.decodeLockupJSON(json: element["lockupViewModel"]) {
276+
toReturn.recommendedVideos.append(decodedVideo)
277+
}
278+
} else if element["compactVideoRenderer", "videoId"].exists() {
279+
if let decodedVideo = YTVideo.decodeJSON(json: element["compactVideoRenderer"]) {
280+
toReturn.recommendedVideos.append(decodedVideo)
281+
}
272282
} else if let continuationToken = element["continuationItemRenderer", "continuationEndpoint", "continuationCommand", "token"].string {
273283
toReturn.recommendedVideosContinuationToken = continuationToken
274284
}

Tests/YouTubeKitTests/YouTubeKitTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ final class YouTubeKitTests: XCTestCase {
10651065
XCTAssertNotNil(moreVideoInfosResponse.channel, TEST_NAME + "Checking if the channel has been extracted.")
10661066
XCTAssertNotNil(moreVideoInfosResponse.commentsCount, TEST_NAME + "Checking if the commentsCount has been extracted.")
10671067
XCTAssertNotNil(moreVideoInfosResponse.likesCount.defaultState, TEST_NAME + "Checking if the likesCount has been extracted.")
1068+
XCTAssertNotEqual(moreVideoInfosResponse.recommendedVideos.count, 0, TEST_NAME + "Checking if some recommended videos are present.")
10681069
XCTAssertNotNil(moreVideoInfosResponse.recommendedVideosContinuationToken, TEST_NAME + "Checking if the recommendedVideosContinuationToken has been extracted.")
10691070
XCTAssertNotNil(moreVideoInfosResponse.timePosted.postedDate, TEST_NAME + "Checking if the timePosted.postedDate has been extracted.")
10701071
XCTAssertNotNil(moreVideoInfosResponse.timePosted.relativePostedDate, TEST_NAME + "Checking if the timePosted.relativePostedDate has been extracted.")

0 commit comments

Comments
 (0)