NPOKit is a Swift 4 framework for interfacing with Dutch Public Broadcaster’s (Nederlandse Publieke Omroep - NPO) APIs. It supports fetching programs, episodes and video steams for playback.
Note: This project is in active development so method signatures might change between versions without notice! Consider this in alpha stage… Changes that are likely coming are removing the failure closure in favor of an error argument. Note that this has currently only been tested on tvOS!
Installation
Cocoapods
Using cocoapods is the most common way of installing frameworks. Add something similar to the following lines to your Podfile. You may need to adjust based on your platform, version/branch etc.
As NPOKit is a true Swift application and supports the Swift Package Manager, you can create command line or server side (e.g. Vapor, Perfect, Kitura, etc) applications with it. Please refer to the Command Line HOWTO on how to get started.
Basic Usage
Fetching programs
Below you’ll find some sample code on how to implement some paginated fetching of programs. Unfortunately the API currently does not support sorting in alphabetical order, so the result will be based by the sort order the NPO returns (which is by most used).
Item bases resources (like Program and Episode) may provide images for different usages. The most common way you would use those images on tvOS are for populating collection view cells, or by showing a header:
Fetching the (Dutch) SRT subtitle contents for an episode:
public func fetchSubtitleContents(for episode: Episode, completionHandler: @escaping (Result<String>) -> Void)
Alternatively it is possiblr to fetch parsed subtitles:
public func fetchSubtitle(for item: Item, completionHandler: @escaping (Result<[SubtitleLine]>) -> Void)
Where SubtitleLine is a tuple:
public typealias SubtitleLine = (number: Int, from: TimeInterval, to: TimeInterval, text: String)
Fetching live (and themed) broadcasts
public func fetchLiveBroadcasts(completionHandler: @escaping (Result<[LiveBroadcast]>) -> Void)
Logging
NPOKit relies on its host application for logging using a logging wrapper. This allows NPOKit to not have any dependencies and to enforce or make assumptions on the logging framework your host application uses. Below is an example of how to inject Dave Wood’s (Swift 4) XCGLogger to NPOKit by creating a LoggerWrapper:
LoggerWrapper
First, you need to set up the LoggerWrapper which inherits from NPOKitLogger. It basically normalizes the logging calls to your logging framework of choice, in this case XCGLogger:
In your AppDelegate‘s application:didFinishLaunchingWithOptions: you need to bind your LoggerWrapper to NPOKit, and logging will work. Set the loglevel to debug to get debug information or verbose to more elaborate information like GET and POST requests.
See the accompanying LICENSE and NOTICE files for more information.
Copyright 2018 Jeroen Wesbeek
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
NPOKit
NPOKit
is aSwift 4
framework for interfacing with Dutch Public Broadcaster’s (Nederlandse Publieke Omroep - NPO) APIs. It supports fetching programs, episodes and video steams for playback.Note: This project is in active development so method signatures might change between versions without notice! Consider this in alpha stage… Changes that are likely coming are removing the failure closure in favor of an error argument. Note that this has currently only been tested on tvOS!
Installation
Cocoapods
Using cocoapods is the most common way of installing frameworks. Add something similar to the following lines to your
Podfile
. You may need to adjust based on your platform, version/branch etc.Swift Package Manager
Add the following entry to your package’s dependencies:
Command Line & Server Side usage
As
NPOKit
is a true Swift application and supports theSwift Package Manager
, you can create command line or server side (e.g. Vapor, Perfect, Kitura, etc) applications with it. Please refer to the Command Line HOWTO on how to get started.Basic Usage
Fetching programs
Below you’ll find some sample code on how to implement some paginated fetching of programs. Unfortunately the API currently does not support sorting in alphabetical order, so the result will be based by the sort order the NPO returns (which is by most used).
Example:
This code assumes you use a scroll view in your user interface, so something like a table view or a collection view.
Fetching episodes
Fetching episodes works very much like fetching programs (see above), it just requires a
program
argument when setting up the paginator:Fetching images
Item
bases resources (likeProgram
andEpisode
) may provide images for different usages. The most common way you would use those images ontvOS
are for populating collection view cells, or by showing a header:Fetching (srt) subtitles
Fetching the (Dutch) SRT subtitle contents for an episode:
Alternatively it is possiblr to fetch parsed subtitles:
Where
SubtitleLine
is atuple
:Fetching live (and themed) broadcasts
Logging
NPOKit
relies on its host application for logging using alogging wrapper
. This allowsNPOKit
to not have any dependencies and to enforce or make assumptions on the logging framework your host application uses. Below is an example of how to inject Dave Wood’s (Swift 4) XCGLogger toNPOKit
by creating aLoggerWrapper
:LoggerWrapper
First, you need to set up the
LoggerWrapper
which inherits fromNPOKitLogger
. It basically normalizes the logging calls to your logging framework of choice, in this caseXCGLogger
:AppDelegate
In your
AppDelegate
‘sapplication:didFinishLaunchingWithOptions:
you need to bind yourLoggerWrapper
toNPOKit
, and logging will work. Set the loglevel todebug
to get debug information orverbose
to more elaborate information likeGET
andPOST
requests.License
See the accompanying LICENSE and NOTICE files for more information.