Skip to content

Commit 86d69f4

Browse files
committed
feat: add support for member-only videos
1 parent 16c338f commit 86d69f4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/YouTubeKit/BaseStructs/YTVideo.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
/// Struct representing a video.
1111
public struct YTVideo: YTSearchResult, YouTubeVideo, Codable, Sendable {
12-
public init(id: Int? = nil, videoId: String, title: String? = nil, channel: YTLittleChannelInfos? = nil, viewCount: String? = nil, timePosted: String? = nil, timeLength: String? = nil, thumbnails: [YTThumbnail] = []) {
12+
public init(id: Int? = nil, videoId: String, title: String? = nil, channel: YTLittleChannelInfos? = nil, viewCount: String? = nil, timePosted: String? = nil, timeLength: String? = nil, thumbnails: [YTThumbnail] = [], memberOnly: Bool? = nil) {
1313
self.id = id
1414
self.videoId = videoId
1515
self.title = title
@@ -18,10 +18,11 @@ public struct YTVideo: YTSearchResult, YouTubeVideo, Codable, Sendable {
1818
self.timePosted = timePosted
1919
self.timeLength = timeLength
2020
self.thumbnails = thumbnails
21+
self.memberOnly = memberOnly
2122
}
2223

2324
public static func == (lhs: YTVideo, rhs: YTVideo) -> Bool {
24-
return lhs.channel?.channelId == rhs.channel?.channelId && lhs.channel?.name == rhs.channel?.name && lhs.thumbnails == rhs.thumbnails && lhs.timeLength == rhs.timeLength && lhs.timePosted == rhs.timePosted && lhs.title == rhs.title && lhs.videoId == rhs.videoId && lhs.viewCount == rhs.viewCount
25+
return lhs.channel?.channelId == rhs.channel?.channelId && lhs.channel?.name == rhs.channel?.name && lhs.thumbnails == rhs.thumbnails && lhs.timeLength == rhs.timeLength && lhs.timePosted == rhs.timePosted && lhs.title == rhs.title && lhs.videoId == rhs.videoId && lhs.viewCount == rhs.viewCount && lhs.memberOnly == rhs.memberOnly
2526
}
2627

2728
public static func canBeDecoded(json: JSON) -> Bool {
@@ -66,6 +67,10 @@ public struct YTVideo: YTSearchResult, YouTubeVideo, Codable, Sendable {
6667
video.channel = channel
6768
}
6869

70+
if let badges = json["badges"].array {
71+
video.memberOnly = badges.contains(where: { $0["metadataBadgeRenderer", "style"].string == "BADGE_STYLE_TYPE_MEMBERS_ONLY" })
72+
}
73+
6974
if let viewCount = json["shortViewCountText", "simpleText"].string {
7075
video.viewCount = viewCount
7176
} else {
@@ -138,6 +143,9 @@ public struct YTVideo: YTSearchResult, YouTubeVideo, Codable, Sendable {
138143
/// Possibly not defined when reading in ``YTPlaylist/frontVideos`` properties.
139144
public var channel: YTLittleChannelInfos?
140145

146+
/// A boolean inidicating whether the video is a member-only one. If it's true, you won't be able to request the streaming info of the video except if you provide the cookies of an account that's a member of the channel.
147+
public var memberOnly: Bool?
148+
141149
/// Count of views of the video, in a shortened string.
142150
///
143151
/// Possibly not defined when reading in ``YTPlaylist/frontVideos`` properties.

0 commit comments

Comments
 (0)