Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
chickdan committed Mar 12, 2024
2 parents 0c6e618 + e28805a commit d360c8c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
14 changes: 10 additions & 4 deletions Shared/Extensions/JellyfinAPI/JellyfinClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ import JellyfinAPI

extension JellyfinClient {

func fullURL<T>(with request: Request<T>) -> URL {
let fullPath = configuration.url.appendingPathComponent(request.url?.path ?? "")
func fullURL<T>(with request: Request<T>) -> URL? {

guard let path = request.url?.path else { return configuration.url }
guard let fullPath = fullURL(with: path) else { return nil }

var components = URLComponents(string: fullPath.absoluteString)!
components.queryItems = request.query?.map { URLQueryItem(name: $0.0, value: $0.1) } ?? []

return components.url ?? fullPath
}

func fullURL(with path: String) -> URL {
URL(string: configuration.url.absoluteString + path)!
/// Appends the path to the current configuration `URL`, assuming that the path begins with a leading `/`.
/// Returns `nil` if the new `URL` is malformed.
func fullURL(with path: String) -> URL? {
guard let fullPath = URL(string: configuration.url.absoluteString.trimmingCharacters(in: ["/"]) + path)
else { return nil }
return fullPath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Foundation
import JellyfinAPI
import UIKit

// TODO: strongly type errors

extension MediaSourceInfo {

func videoPlayerViewModel(with item: BaseItemDto, playSessionID: String) throws -> VideoPlayerViewModel {
Expand All @@ -21,8 +23,8 @@ extension MediaSourceInfo {
let streamType: StreamType

if let transcodingURL, !Defaults[.Experimental.forceDirectPlay] {
guard let fullTranscodeURL = URL(string: transcodingURL, relativeTo: userSession.server.currentURL)
else { throw JellyfinAPIError("Unable to construct transcoded url") }
guard let fullTranscodeURL = userSession.client.fullURL(with: transcodingURL)
else { throw JellyfinAPIError("Unable to make transcode URL") }
playbackURL = fullTranscodeURL
streamType = .transcode
} else {
Expand All @@ -39,7 +41,10 @@ extension MediaSourceInfo {
parameters: videoStreamParameters
)

playbackURL = userSession.client.fullURL(with: videoStreamRequest)
guard let streamURL = userSession.client.fullURL(with: videoStreamRequest)
else { throw JellyfinAPIError("Unable to make stream URL") }

playbackURL = streamURL
streamType = .direct
}

Expand Down
2 changes: 1 addition & 1 deletion Shared/Extensions/JellyfinAPI/MediaStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension MediaStream {
let client = Container.userSession().client
let deliveryPath = deliveryURL.removingFirst(if: client.configuration.url.absoluteString.last == "/")

let fullURL = client.fullURL(with: deliveryPath)
guard let fullURL = client.fullURL(with: deliveryPath) else { return nil }

return .init(
url: fullURL,
Expand Down
3 changes: 2 additions & 1 deletion Shared/ViewModels/VideoPlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class VideoPlayerViewModel: ViewModel {
parameters: parameters
)

let hlsStreamComponents = URLComponents(url: userSession.client.fullURL(with: request), resolvingAgainstBaseURL: false)!
// TODO: don't force unwrap
let hlsStreamComponents = URLComponents(url: userSession.client.fullURL(with: request)!, resolvingAgainstBaseURL: false)!
.addingQueryItem(key: "api_key", value: userSession.user.accessToken)

return hlsStreamComponents.url!
Expand Down
12 changes: 10 additions & 2 deletions Swiftfin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2535,8 +2535,7 @@
E148128728C154BF003B8787 /* ItemFilter+ItemTrait.swift */,
E11B1B6B2718CD68006DA3E8 /* JellyfinAPIError.swift */,
E12A9EF729499E0100731C3A /* JellyfinClient.swift */,
E1D8428E2933F2D900D1041A /* MediaSourceInfo.swift */,
E18A8E7F28D6083700333B9A /* MediaSourceInfo+ItemVideoPlayerViewModel.swift */,
E1F5F9B12BA0200500BA5014 /* MediaSourceInfo */,
E122A9122788EAAD0060FA63 /* MediaStream.swift */,
E1AD105E26D9ADDD003E4A08 /* NameGuidPair.swift */,
E148128428C15472003B8787 /* SortOrder.swift */,
Expand Down Expand Up @@ -2821,6 +2820,15 @@
path = PagingLibraryView;
sourceTree = "<group>";
};
E1F5F9B12BA0200500BA5014 /* MediaSourceInfo */ = {
isa = PBXGroup;
children = (
E1D8428E2933F2D900D1041A /* MediaSourceInfo.swift */,
E18A8E7F28D6083700333B9A /* MediaSourceInfo+ItemVideoPlayerViewModel.swift */,
);
path = MediaSourceInfo;
sourceTree = "<group>";
};
E1FA891C289A302600176FEB /* CollectionItemView */ = {
isa = PBXGroup;
children = (
Expand Down

0 comments on commit d360c8c

Please sign in to comment.