Skip to content

Commit b83e0d3

Browse files
committed
fix: fix channel extraction for videos with multiple collaborators
1 parent 4a094f3 commit b83e0d3

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Sources/YouTubeKit/BaseStructs/YTVideo.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public struct YTVideo: YTSearchResult, YouTubeVideo, Codable, Sendable {
5555
var channel = YTLittleChannelInfos(channelId: channelId, name: json["shortBylineText", "runs", 0, "text"].string)
5656
YTThumbnail.appendThumbnails(json: json["channelThumbnailSupportedRenderers", "channelThumbnailWithLinkRenderer", "thumbnail"], thumbnailList: &channel.thumbnails)
5757

58+
video.channel = channel
59+
} else if let channelId = json["ownerText", "runs", 0, "navigationEndpoint", "showDialogCommand", "panelLoadingStrategy", "inlineContent", "dialogViewModel", "customContent", "listViewModel", "listItems", 0, "listItemViewModel", "rendererContext", "commandContext", "onTap", "innertubeCommand", "browseEndpoint", "browseId"].string {
60+
// case where there's mutliple collaborators on a video
61+
// TODO: support mutliple channels for a video
62+
let channelContent = json["ownerText", "runs", 0, "navigationEndpoint", "showDialogCommand", "panelLoadingStrategy", "inlineContent", "dialogViewModel", "customContent", "listViewModel", "listItems", 0, "listItemViewModel"]
63+
var channel = YTLittleChannelInfos(channelId: channelId, name: channelContent["title", "content"].string)
64+
YTThumbnail.appendThumbnails(json: channelContent["leadingAccessory", "avatarViewModel"], thumbnailList: &channel.thumbnails)
65+
5866
video.channel = channel
5967
}
6068

Tests/YouTubeKitTests/YouTubeKitTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ final class YouTubeKitTests: XCTestCase {
552552
XCTAssertNotEqual(firstChannel.thumbnails.count, 0)
553553
}
554554

555-
searchResult = try await SearchResponse.sendThrowingRequest(youtubeModel: YTM, data: [.query: "fred again"])
555+
searchResult = try await SearchResponse.sendThrowingRequest(youtubeModel: YTM, data: [.query: "mrbeast"])
556556

557557
if let firstChannel = searchResult.results.first(where: {$0 as? YTChannel != nil}) as? YTChannel {
558558
XCTAssertNotNil(firstChannel.name)
@@ -568,6 +568,8 @@ final class YouTubeKitTests: XCTestCase {
568568
XCTAssertNotNil(firstVideo.timeLength)
569569
XCTAssertNotNil(firstVideo.viewCount)
570570
XCTAssertNotNil(firstVideo.timePosted)
571+
XCTAssertNotNil(firstVideo.channel?.name)
572+
XCTAssertNotEqual(firstVideo.channel?.thumbnails.count, 0)
571573
}
572574

573575
if let firstPlaylist = searchResult.results.first(where: {$0 as? YTPlaylist != nil}) as? YTPlaylist {

0 commit comments

Comments
 (0)