Swiftpack.co -  adamayoung/TMDb as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
adamayoung/TMDb
The Movie Database Swift Package
.package(url: "https://github.com/adamayoung/TMDb.git", from: "4.2.0")

TMDb - The Movie Database

CI Coverage Quality Gate Status Security Rating

Swift Package Manager compatible platforms

A Swift Package for The Movie Database (TMDb) https://www.themoviedb.org

Requirements

  • Swift 5.2+

Installation

Swift Package Manager

Add the TMDb package as a dependency to your Package.swift file, and add it as a dependency to your target.

// swift-tools-version:5.2

import PackageDescription

let package = Package(
  name: "MyProject",
  dependencies: [
    .package(url: "https://github.com/adamayoung/TMDb.git", from: "4.1.0")
  ],
  targets: [
    .target(name: "MyProject", dependencies: ["TMDb"])
  ]
)

Setup

Get an API Key

Create an API Key from The Movie Database web site https://www.themoviedb.org/documentation/api.

Set you API Key

Set your API key before making any calls

TMDbAPI.setAPIKey("ahb4334n43nj34jk43nklkg4")

API Areas

Certifications

Get an up to date list of the officially supported movie certifications on TMDB.

Configuration

System wide configuration information.

Discover

Discover movies by different types of data like average rating, number of votes, genres and certifications.

Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates.

Movies

Get information about movies.

People

Get information about people.

Search

Search for movies, TV shows and people.

Trending

Get the daily or weekly trending items. The daily trending list tracks items over the period of a day while items have a 24 hour half life. The weekly list tracks items over a 7 day period, with a 7 day half life.

TV Shows

Get information about TV shows.

TV Show Seasons

Get information about TV show seasons.

Examples

TMDbAPI.setAPIKey("ahb4334n43nj34jk43nklkg4")
let tmdb = TMDbAPI.shared

Discover Movies

// With Combine
tmdb.discover.moviesPublisher()
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.movies, on: self)
    .store(in: &cancellables)

// With a completion handler
tmdb.discover.fetchMovies { result in
    let movies = (try? result.get())?.results
    ...
}

Trending TV Shows this week, 2nd page

// With Combine
tmdb.trending.tvShowsPublisher(inTimeWindow: .week, page: 2)
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.tvShows, on: self)
    .store(in: &cancellables)

// With a completion handler
tmdb.trending.fetchTVShows(inTimeWindow: .week, page: 2) { result in
    let tvShows = (try? result.get())?.results
    ...
}

Popular People

// With Combine
tmdb.person.popularPublisher()
    .map(\.results)
    .replaceError(with: [])
    .assign(to: \.people, on: self)
    .store(in: &cancellables)

// With a completion handler
tmdb.person.fetchPopular { result in
    let people = (try? result.get())?.results
}

References

GitHub

link
Stars: 4
Last commit: 21 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

4.2.0
21 hours ago

Now Playing, Top Rated and Upcoming Movies

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API