Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Show when a release was previously grabbed or failed
- Improved x265, H.266, VC1 and VVC codec replacements
- Open the exact movie on Letterboxd instead of a search
- Open and search movies and series from Shortcuts and Siri on iOS 27
- Ask Siri about the movie or series on screen

### Changed
- Faster searching in large movie and series libraries
Expand Down
1 change: 1 addition & 0 deletions Ruddarr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
Utilities/FoldedText.swift,
Utilities/Formatters.swift,
Utilities/Helpers.swift,
Utilities/Identifiers.swift,
Utilities/Networking.swift,
Utilities/Placeholder.swift,
Utilities/Privacy.swift,
Expand Down
6 changes: 6 additions & 0 deletions Ruddarr/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
}
}
},
"%@" : {
"shouldTranslate" : false
},
"%@ at %@" : {
"comment" : "(Today/Tomorrow/Yesterday) at (time)",
"localizations" : {
Expand Down Expand Up @@ -5047,6 +5050,9 @@
}
}
}
},
"Size on Disk" : {

},
"Slow Instance" : {
"localizations" : {
Expand Down
2 changes: 1 addition & 1 deletion Ruddarr/Models/Media.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ protocol Media: Identifiable, Sendable where ID: Sendable {
var remotePoster: String? { get }

var searchableHash: String { get }
func searchableItem(poster: URL?) -> CSSearchableItem
func searchableItem(poster: URL?, instance: Instance) -> CSSearchableItem
}

struct Tag: Identifiable, Equatable, Codable {
Expand Down
157 changes: 157 additions & 0 deletions Ruddarr/Models/Movies/Movie+Entity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import Foundation
import AppIntents
import CoreTransferable
import UniformTypeIdentifiers

struct MovieEntity: IndexedEntity {
static let typeDisplayRepresentation = TypeDisplayRepresentation(name: "Movie")
static let defaultQuery = MovieEntityQuery()

let id: String
let movieId: Movie.ID
let instanceId: Instance.ID
let overview: String?

@Property(title: "Title")
var title: String

@Property(title: "Year")
var year: Int

@Property(title: "Status")
var status: String

@Property(title: "Monitored")
var monitored: Bool

@Property(title: "Downloaded")
var downloaded: Bool

@Property(title: "Size on Disk")
var sizeOnDisk: Measurement<UnitInformationStorage>?

@Property(title: "In Cinemas")
var inCinemas: Date?

@Property(title: "Digital Release")
var digitalRelease: Date?

@Property(title: "Physical Release")
var physicalRelease: Date?

@Property(title: "Instance")
var instance: String

init(_ movie: Movie, _ instance: Instance) {
self.id = MediaEntityID(movie.id, instance.id).rawValue
self.movieId = movie.id
self.instanceId = instance.id
self.overview = movie.overview
self.title = movie.title
self.year = movie.year
self.status = movie.status.label
self.monitored = movie.monitored
self.downloaded = movie.isDownloaded
self.sizeOnDisk = movie.sizeOnDisk.map { Measurement(value: Double($0), unit: .bytes) }
self.inCinemas = movie.inCinemas
self.digitalRelease = movie.digitalRelease
self.physicalRelease = movie.physicalRelease
self.instance = instance.label
}

var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(
title: "\(title)",
subtitle: year > 0 ? "\(String(year))" : nil
)
}

static func entityIdentifier(_ movie: Movie) -> EntityIdentifier? {
movie.instanceId.map {
EntityIdentifier(for: Self.self, identifier: MediaEntityID(movie.id, $0).rawValue)
}
}

var summary: String {
let heading = year > 0 ? "\(title) (\(year))" : title

guard let overview, !overview.isEmpty else {
return heading
}

return "\(heading)\n\n\(overview)"
}
}

extension MovieEntity: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(exportedContentType: .plainText) { Data($0.summary.utf8) }
}
}

struct MovieEntityQuery: EntityStringQuery {
func entities(for identifiers: [MovieEntity.ID]) async throws -> [MovieEntity] {
let instances = await radarrInstances()

return await withTaskGroup(of: MovieEntity?.self, returning: [MovieEntity].self) { group in
for identifier in identifiers {
guard let parsed = MediaEntityID(rawValue: identifier),
let instance = instances.first(where: { $0.id == parsed.instanceId })
else {
continue
}

group.addTask {
let movie = try? await dependencies.api.radarr.movie(parsed.mediaId, instance)

return movie.map { MovieEntity($0, instance) }
}
}

var entities: [MovieEntity] = []

for await entity in group {
if let entity { entities.append(entity) }
}

return entities
}
}

func entities(matching string: String) async throws -> [MovieEntity] {
let query = string.trimmed()

return await library().filter { $0.title.localizedStandardContains(query) }
}

func suggestedEntities() async throws -> [MovieEntity] {
await library().sorted { $0.title.localizedStandardCompare($1.title) == .orderedAscending }
}

private func library() async -> [MovieEntity] {
let instances = await radarrInstances()

return await withTaskGroup(of: [MovieEntity].self, returning: [MovieEntity].self) { group in
for instance in instances {
group.addTask {
let movies = (try? await dependencies.api.radarr.fetch(instance)) ?? []

return movies.map { MovieEntity($0, instance) }
}
}

var entities: [MovieEntity] = []

for await batch in group {
entities += batch
}

return entities
}
}

@MainActor
private func radarrInstances() -> [Instance] {
AppSettings.shared.configuredInstances.filter { $0.type == .radarr }
}
}
11 changes: 9 additions & 2 deletions Ruddarr/Models/Movies/Movie.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import AppIntents
import CoreSpotlight

struct Movie: Media, Identifiable, Equatable, Codable {
Expand Down Expand Up @@ -251,7 +252,7 @@ struct Movie: Media, Identifiable, Equatable, Codable {
}

extension Movie {
func searchableItem(poster: URL?) -> CSSearchableItem {
func searchableItem(poster: URL?, instance: Instance) -> CSSearchableItem {
let attributes = CSSearchableItemAttributeSet(contentType: UTType.movie)
attributes.title = title
attributes.genre = genres.first
Expand All @@ -270,8 +271,14 @@ extension Movie {
.filter { $0.title == title }
.map { $0.title }

#if compiler(>=6.4)
if #available(iOS 27.0, macOS 27.0, *) {
attributes.associateAppEntity(MovieEntity(self, instance))
}
#endif

return CSSearchableItem(
uniqueIdentifier: "movie:\(id):\(instanceId?.uuidString ?? "")",
uniqueIdentifier: SpotlightItemID(.movie, id, instanceId?.uuidString).rawValue,
domainIdentifier: instanceId?.uuidString,
attributeSet: attributes
)
Expand Down
2 changes: 1 addition & 1 deletion Ruddarr/Models/Movies/Movies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Movies {
items = try await dependencies.api.radarr.fetch(instance)
itemsCount = items.count
computeAlternateTitles()
await Spotlight(instance.id).index(items, delay: .seconds(5))
await Spotlight(instance.id).index(items, from: instance, delay: .seconds(5))

leaveBreadcrumb(.info, category: "movies", message: "Fetched movies", data: ["count": items.count])

Expand Down
Loading
Loading