Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide implement YouTube namespace for atom feed. #153

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions FeedKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@
BB394B7D223B368C00366193 /* AmpersandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB394B7C223B368C00366193 /* AmpersandTests.swift */; };
BB394B7E223B368C00366193 /* AmpersandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB394B7C223B368C00366193 /* AmpersandTests.swift */; };
BB394B7F223B368C00366193 /* AmpersandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB394B7C223B368C00366193 /* AmpersandTests.swift */; };
EA4431E12A3E2B6C00C2C7F4 /* YouTubeNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */; };
EA4431E22A3E2EE000C2C7F4 /* YouTubeNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */; };
EA4431E32A3E2EE100C2C7F4 /* YouTubeNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */; };
EA4431E42A3E2EE200C2C7F4 /* YouTubeNamespace.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */; };
EA4431E62A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */ = {isa = PBXBuildFile; fileRef = EA4431E52A3E32C000C2C7F4 /* YouTubeXMLFeed.xml */; };
EA4431E72A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */ = {isa = PBXBuildFile; fileRef = EA4431E52A3E32C000C2C7F4 /* YouTubeXMLFeed.xml */; };
EA4431E82A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */ = {isa = PBXBuildFile; fileRef = EA4431E52A3E32C000C2C7F4 /* YouTubeXMLFeed.xml */; };
EA4431EA2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E92A3E333E00C2C7F4 /* YouTubeTests.swift */; };
EA4431EB2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E92A3E333E00C2C7F4 /* YouTubeTests.swift */; };
EA4431EC2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4431E92A3E333E00C2C7F4 /* YouTubeTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -723,6 +733,9 @@
A0F79FBC1F642AE2007CFC08 /* RDFTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RDFTests.swift; sourceTree = "<group>"; };
BB394B77223B35D700366193 /* Ampersand.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Ampersand.xml; sourceTree = "<group>"; };
BB394B7C223B368C00366193 /* AmpersandTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmpersandTests.swift; sourceTree = "<group>"; };
EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YouTubeNamespace.swift; sourceTree = "<group>"; };
EA4431E52A3E32C000C2C7F4 /* YouTubeXMLFeed.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = YouTubeXMLFeed.xml; sourceTree = "<group>"; };
EA4431E92A3E333E00C2C7F4 /* YouTubeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YouTubeTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -817,6 +830,7 @@
A09AFB321EEFDFF40076ACC7 /* DublinCoreTests.swift */,
A09AFB331EEFDFF40076ACC7 /* DurationTests.swift */,
A09AFB341EEFDFF40076ACC7 /* iTunesTests.swift */,
EA4431E92A3E333E00C2C7F4 /* YouTubeTests.swift */,
A09AFB351EEFDFF40076ACC7 /* JSONTests.swift */,
A09AFB361EEFDFF40076ACC7 /* MediaTests.swift */,
A09AFB371EEFDFF40076ACC7 /* ParserErrorTests.swift */,
Expand Down Expand Up @@ -991,6 +1005,7 @@
A0F6B7E51F6E6E9600220625 /* Namespaces */ = {
isa = PBXGroup;
children = (
EA4431DF2A3E2B5E00C2C7F4 /* YouTube */,
A0F6B7E61F6E6E9600220625 /* Content */,
A0F6B7E81F6E6E9600220625 /* Dublin Core */,
A0F6B7EA1F6E6E9600220625 /* iTunes */,
Expand Down Expand Up @@ -1133,6 +1148,7 @@
A0F6B9B61F6E6FA700220625 /* RSSDC.xml */,
A0F6B9B71F6E6FA700220625 /* RSSMedia.xml */,
A0F6B9B81F6E6FA700220625 /* Syndication.xml */,
EA4431E52A3E32C000C2C7F4 /* YouTubeXMLFeed.xml */,
);
path = xml;
sourceTree = "<group>";
Expand All @@ -1155,6 +1171,14 @@
path = "View Controllers";
sourceTree = "<group>";
};
EA4431DF2A3E2B5E00C2C7F4 /* YouTube */ = {
isa = PBXGroup;
children = (
EA4431E02A3E2B6C00C2C7F4 /* YouTubeNamespace.swift */,
);
path = YouTube;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -1479,6 +1503,7 @@
A0F6B9E01F6E714400220625 /* feed.json in Resources */,
A0F6B9D61F6E713F00220625 /* AtomMedia.xml in Resources */,
A0F6B9DD1F6E713F00220625 /* RSSDC.xml in Resources */,
EA4431E62A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1499,6 +1524,7 @@
A0F6B9E11F6E714400220625 /* feed.json in Resources */,
A0F6B9CB1F6E713F00220625 /* AtomMedia.xml in Resources */,
A0F6B9D21F6E713F00220625 /* RSSDC.xml in Resources */,
EA4431E72A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -1519,6 +1545,7 @@
A0F6B9E21F6E714400220625 /* feed.json in Resources */,
A0F6B9C01F6E713E00220625 /* AtomMedia.xml in Resources */,
A0F6B9C71F6E713F00220625 /* RSSDC.xml in Resources */,
EA4431E82A3E32C000C2C7F4 /* YouTubeXMLFeed.xml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1640,6 +1667,7 @@
A0F6B8671F6E6EB800220625 /* MediaStatistics.swift in Sources */,
A0C788CB20CC6332005C2F6F /* URL + replacingScheme.swift in Sources */,
A0F6B87E1F6E6EB800220625 /* RSSFeedTextInput.swift in Sources */,
EA4431E42A3E2EE200C2C7F4 /* YouTubeNamespace.swift in Sources */,
A0F6B82E1F6E6EB800220625 /* RFC3339DateFormatter.swift in Sources */,
A0F6B8311F6E6EB800220625 /* String + toBool.swift in Sources */,
A0F6B8431F6E6EB800220625 /* AtomFeedLink.swift in Sources */,
Expand Down Expand Up @@ -1686,6 +1714,7 @@
A0F79FBD1F642AE2007CFC08 /* RDFTests.swift in Sources */,
A09AFB3A1EEFDFF40076ACC7 /* AtomTests.swift in Sources */,
A09AFB401EEFDFF40076ACC7 /* ContentTests.swift in Sources */,
EA4431EA2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */,
A09AFB491EEFDFF40076ACC7 /* DurationTests.swift in Sources */,
A09AFB431EEFDFF40076ACC7 /* DateTests.swift in Sources */,
A09AFB461EEFDFF40076ACC7 /* DublinCoreTests.swift in Sources */,
Expand All @@ -1708,6 +1737,7 @@
A0F79FBE1F642AE2007CFC08 /* RDFTests.swift in Sources */,
A09AFB3B1EEFDFF40076ACC7 /* AtomTests.swift in Sources */,
A09AFB411EEFDFF40076ACC7 /* ContentTests.swift in Sources */,
EA4431EB2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */,
A09AFB4A1EEFDFF40076ACC7 /* DurationTests.swift in Sources */,
A09AFB441EEFDFF40076ACC7 /* DateTests.swift in Sources */,
A09AFB471EEFDFF40076ACC7 /* DublinCoreTests.swift in Sources */,
Expand All @@ -1730,6 +1760,7 @@
A0F79FBF1F642AE2007CFC08 /* RDFTests.swift in Sources */,
A09AFB3C1EEFDFF40076ACC7 /* AtomTests.swift in Sources */,
A09AFB421EEFDFF40076ACC7 /* ContentTests.swift in Sources */,
EA4431EC2A3E333E00C2C7F4 /* YouTubeTests.swift in Sources */,
A09AFB4B1EEFDFF40076ACC7 /* DurationTests.swift in Sources */,
A09AFB451EEFDFF40076ACC7 /* DateTests.swift in Sources */,
A09AFB481EEFDFF40076ACC7 /* DublinCoreTests.swift in Sources */,
Expand Down Expand Up @@ -1836,6 +1867,7 @@
A0F6B91F1F6E6EBB00220625 /* MediaStatistics.swift in Sources */,
A0C788C920CC6332005C2F6F /* URL + replacingScheme.swift in Sources */,
A0F6B9361F6E6EBB00220625 /* RSSFeedTextInput.swift in Sources */,
EA4431E22A3E2EE000C2C7F4 /* YouTubeNamespace.swift in Sources */,
A0F6B8E61F6E6EBA00220625 /* RFC3339DateFormatter.swift in Sources */,
A0F6B8E91F6E6EBA00220625 /* String + toBool.swift in Sources */,
A0F6B8FB1F6E6EBB00220625 /* AtomFeedLink.swift in Sources */,
Expand Down Expand Up @@ -1936,6 +1968,7 @@
A0F6B8C31F6E6EBA00220625 /* MediaStatistics.swift in Sources */,
A0C788CA20CC6332005C2F6F /* URL + replacingScheme.swift in Sources */,
A0F6B8DA1F6E6EBA00220625 /* RSSFeedTextInput.swift in Sources */,
EA4431E32A3E2EE100C2C7F4 /* YouTubeNamespace.swift in Sources */,
A0F6B88A1F6E6EBA00220625 /* RFC3339DateFormatter.swift in Sources */,
A0F6B88D1F6E6EBA00220625 /* String + toBool.swift in Sources */,
A0F6B89F1F6E6EBA00220625 /* AtomFeedLink.swift in Sources */,
Expand Down Expand Up @@ -2036,6 +2069,7 @@
A0F6B97B1F6E6EBB00220625 /* MediaStatistics.swift in Sources */,
A0C788C820CC6332005C2F6F /* URL + replacingScheme.swift in Sources */,
A0F6B9921F6E6EBB00220625 /* RSSFeedTextInput.swift in Sources */,
EA4431E12A3E2B6C00C2C7F4 /* YouTubeNamespace.swift in Sources */,
A0F6B9421F6E6EBB00220625 /* RFC3339DateFormatter.swift in Sources */,
A0F6B9451F6E6EBB00220625 /* String + toBool.swift in Sources */,
A0F6B9571F6E6EBB00220625 /* AtomFeedLink.swift in Sources */,
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [x] [Content](http://web.resource.org/rss/1.0/modules/content/)
- [x] [Media RSS](http://www.rssboard.org/media-rss)
- [x] [iTunes Podcasting Tags](https://help.apple.com/itc/podcasts_connect/#/itcb54353390)
- [x] [YouTube](https://developers.google.com/youtube/v3/guides/push_notifications)
- [x] [Documentation](http://cocoadocs.org/docsets/FeedKit)
- [x] Unit Test Coverage

Expand Down
10 changes: 10 additions & 0 deletions Sources/FeedKit/Models/Atom/AtomFeed + mapAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ extension AtomFeed {

}

// MARK: YouTube

case
.feedEntryYouTubeChannelID,
.feedEntryYouTubeVideoID:

if self.entries?.last?.yt == nil {
self.entries?.last?.yt = YouTubeNamespace()
}

default: break

}
Expand Down
2 changes: 2 additions & 0 deletions Sources/FeedKit/Models/Atom/AtomFeed + mapCharacters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ extension AtomFeed {
case .feedEntryMediaScenesMediaSceneSceneDescription: self.entries?.last?.media?.mediaScenes?.last?.sceneDescription = self.entries?.last?.media?.mediaScenes?.last?.sceneDescription?.appending(string) ?? string
case .feedEntryMediaScenesMediaSceneSceneStartTime: self.entries?.last?.media?.mediaScenes?.last?.sceneStartTime = string.toDuration()
case .feedEntryMediaScenesMediaSceneSceneEndTime: self.entries?.last?.media?.mediaScenes?.last?.sceneEndTime = string.toDuration()
case .feedEntryYouTubeChannelID: self.entries?.last?.yt?.channelID = self.entries?.last?.yt?.channelID?.appending(string) ?? string
case .feedEntryYouTubeVideoID: self.entries?.last?.yt?.videoID = self.entries?.last?.yt?.videoID?.appending(string) ?? string
default: break
}
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/FeedKit/Models/Atom/AtomFeedEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public class AtomFeedEntry {
/// capabilities of RSS 2.0.
public var media: MediaNamespace?

public var yt: YouTubeNamespace?

public init() { }

}
Expand All @@ -185,7 +187,8 @@ extension AtomFeedEntry: Equatable {
lhs.content == rhs.content &&
lhs.published == rhs.published &&
lhs.source == rhs.source &&
lhs.rights == rhs.rights
lhs.rights == rhs.rights &&
lhs.yt == rhs.yt
}

}
5 changes: 5 additions & 0 deletions Sources/FeedKit/Models/Atom/AtomPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ enum AtomPath: String {
case feedEntryMediaGroupMediaRating = "/feed/entry/media:group/media:rating"
case feedEntryMediaGroupMediaContent = "/feed/entry/media:group/media:content"

// MARK: YouTube

case feedEntryYouTubeChannelID = "/feed/entry/yt:channelId"
case feedEntryYouTubeVideoID = "/feed/entry/yt:videoId"

}
53 changes: 53 additions & 0 deletions Sources/FeedKit/Models/Namespaces/YouTube/YouTubeNamespace.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// YouTubeNamespace.swift
//
// Copyright (c) 2023 Naufal Fachrian
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import Foundation

/// YouTube metadata contains channel ID and video ID for YouTube content.
///
/// See https://developers.google.com/youtube/v3/guides/push_notifications
public class YouTubeNamespace {

/// The <yt:channelId> element's value to identify the channel that owns that video.
public var channelID: String?

/// The <yt:videoId> element's value to identify the newly added or updated video.
public var videoID: String?

public init() { }

}


// MARK: - Equatable

extension YouTubeNamespace: Equatable {

public static func ==(lhs: YouTubeNamespace, rhs: YouTubeNamespace) -> Bool {
return
lhs.channelID == rhs.channelID &&
lhs.videoID == rhs.videoID
}

}
82 changes: 82 additions & 0 deletions Tests/YouTubeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// YouTubeTests.swift
//
// Copyright (c) 2023 Naufal Fachrian
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import XCTest
import FeedKit

class YouTubeTests: BaseTestCase {

func testYouTubeChannelID() {

let URL = fileURL("YouTubeXMLFeed", type: "xml")
let parser = FeedParser(URL: URL)

do {

let feed = try parser.parse().get().atomFeed

XCTAssertEqual(feed?.entries?.last?.yt?.channelID, "UCE_M8A5yxnLfW0KghEeajjw")

} catch {
XCTFail(error.localizedDescription)
}

}

func testYouTubeVideoID() {

let URL = fileURL("YouTubeXMLFeed", type: "xml")
let parser = FeedParser(URL: URL)

do {

let feed = try parser.parse().get().atomFeed

[
"51QO4pavK3A",
"j1HGOY32s2Y",
"rc46cO3spSE",
"0okuAwqTHs0",
"GYkq9Rgoj8E",
"TX9qSaGXFyg",
"4-7jSoINyq4",
"0mqWw5UH1qg",
"L5wx0Takylc",
"fVW8-px4Ufw",
"1S8L7t2tu0U",
"svpvEfQ1cp8",
"f1VEks-QQ4Y",
"1HWUjMjaBJI",
"oMf_i1YBuMk"
].forEach { videoID in
XCTAssertTrue(feed?.entries?.contains(where: { entry in entry.yt?.videoID == videoID }) == true)
}

} catch {
XCTFail(error.localizedDescription)
}

}

}
Loading