Skip to content

Commit 17df74f

Browse files
committed
Added community as a child of group, as YouTube seem to do it this way. See: https://www.youtube.com/feeds/videos.xml?channel_i=UCnCikd0s4i9KoDtaHPlK-JA
1 parent 0a95017 commit 17df74f

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Sources/FeedKit/Namespaces/Media/MediaGroup.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ public struct MediaGroup {
3737
category: MediaCategory? = nil,
3838
rating: MediaRating? = nil,
3939
description: MediaDescription? = nil,
40-
thumbnails: [MediaThumbnail]? = nil
40+
thumbnails: [MediaThumbnail]? = nil,
41+
community: MediaCommunity? = nil
4142
) {
4243
self.contents = contents
4344
self.credits = credits
4445
self.category = category
4546
self.rating = rating
4647
self.description = description
4748
self.thumbnails = thumbnails
49+
self.community = community
4850
}
4951

5052
// MARK: Public
@@ -82,6 +84,11 @@ public struct MediaGroup {
8284
/// at play, it is assumed that the images are in order of importance. It has
8385
/// one required attribute and three optional attributes.
8486
public var thumbnails: [MediaThumbnail]?
87+
88+
/// This element stands for the community related content. This allows
89+
/// inclusion of the user perception about a media object in the form of view
90+
/// count, ratings and tags.
91+
public var community: MediaCommunity?
8592
}
8693

8794
// MARK: - Sendable
@@ -106,6 +113,7 @@ extension MediaGroup: Codable {
106113
case rating = "media:rating"
107114
case description = "media:description"
108115
case thumbnails = "media:thumbnail"
116+
case community = "media:community"
109117
}
110118

111119
public init(from decoder: any Decoder) throws {
@@ -117,6 +125,7 @@ extension MediaGroup: Codable {
117125
rating = try container.decodeIfPresent(MediaRating.self, forKey: MediaGroup.CodingKeys.rating)
118126
description = try container.decodeIfPresent(MediaDescription.self, forKey: MediaGroup.CodingKeys.description)
119127
thumbnails = try container.decodeIfPresent([MediaThumbnail].self, forKey: MediaGroup.CodingKeys.thumbnails)
128+
community = try container.decodeIfPresent(MediaCommunity.self, forKey: MediaGroup.CodingKeys.community)
120129
}
121130

122131
public func encode(to encoder: any Encoder) throws {
@@ -128,5 +137,6 @@ extension MediaGroup: Codable {
128137
try container.encodeIfPresent(rating, forKey: MediaGroup.CodingKeys.rating)
129138
try container.encodeIfPresent(description, forKey: MediaGroup.CodingKeys.description)
130139
try container.encodeIfPresent(thumbnails, forKey: MediaGroup.CodingKeys.thumbnails)
140+
try container.encodeIfPresent(community, forKey: MediaGroup.CodingKeys.community)
131141
}
132142
}

Tests/FeedKitTests/Resources/xml/Media.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<media:rating scheme="urn:mpaa">nonadult</media:rating>
1313
<media:description>What a wonderful description he found</media:description>
1414
<media:thumbnail url="http://www.foo.com/keyframe3.jpg" width="480" height="360" time="12:05:01.123" />
15+
<media:community>
16+
<media:starRating average="3.5" count="20" min="1" max="10" />
17+
<media:statistics views="5" favorites="5" />
18+
<media:tags>news: 5, abc:3, reuters</media:tags>
19+
</media:community>
1520
</media:group>
1621
<media:content url="http://www.foo.com/video.mov" fileSize="12216320" type="video/quicktime" medium="video" isDefault="true" expression="full" bitrate="128" framerate="25" samplingrate="44.1" channels="2" duration="185" height="300" width="200" lang="en">
1722
</media:content>

Tests/FeedKitTests/Tests/MediaTests + Mocks.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,39 @@ extension MediaTests {
333333
href: "http://www.foo.org/subtitle.smil"
334334
)
335335
)
336+
337+
media.group?.community = .init(
338+
starRating: .init(
339+
text: nil,
340+
attributes: .init(
341+
average: 3.5,
342+
count: 20,
343+
min: 1,
344+
max: 10
345+
)
346+
),
347+
statistics: .init(
348+
text: nil,
349+
attributes: .init(
350+
views: 5,
351+
favorites: 5
352+
)
353+
),
354+
tags: [
355+
.init(
356+
tag: "news",
357+
weight: 5
358+
),
359+
.init(
360+
tag: "abc",
361+
weight: 3
362+
),
363+
.init(
364+
tag: "reuters",
365+
weight: 1
366+
)
367+
]
368+
)
336369

337370
media.community = .init(
338371
starRating: .init(

0 commit comments

Comments
 (0)