SauceNAO API for Swift
- iOS 9.0+, macOS 10.12+
- Swift 4.2
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Swift-SauceNao into your Xcode project using Carthage, specify it in your Cartfile
:
github "Vinrobot/Swift-SauceNao"
Run carthage update
to build the framework and drag the built Swift_SauceNao.framework
into your Xcode project or follow Carthage: Getting started.
- Create an instance of SauceNao
import Swift_SauceNao
let saucenao = SauceNao(apiKey: "API Key from https://saucenao.com/user.php?page=search-api")
or
let saucenao = SauceNao(apiKey: "API Key", skipLimiters: false) // To skip embedded limiters
- Use one of the search methods.
- Search using an URL:
let url = URL(string: "https://saucenao.com/images/static/banner.gif")!
saucenao.search(url: url) { (result, error) in
guard let result = result else {
print(error ?? "Unknown error")
return
}
print("Long: \(result.limits.longRemaining) / \(result.limits.longLimit)")
print("Short: \(result.limits.shortRemaining) / \(result.limits.shortLimit)")
if let results = result.results {
for res in results {
print(res.thumbnail)
}
}
}
let urlAsString = "https://saucenao.com/images/static/banner.gif"
saucenao.search(url: urlAsString) { (result, error) in
...
}
- Search using File URL:
let file = URL(fileURLWithPath: "/Users/Vinrobot/Downloads/banner.gif")
saucenao.search(file: file) { (result, error) in
...
}
- Search using Data:
let file = URL(fileURLWithPath: "/Users/Vinrobot/Downloads/banner.jpg")
let imageData = try Data(contentsOf: file) // Example by reading file content
let fileName = "image.jpg"
let mimeType = "image/jpeg"
saucenao.search(data: imageData, fileName: fileName, mimeType: mimeType) { (result, error) in
...
}
- Look at SauceNaoResult.swift to see the content of the
result
variable.