Skip to content

Commit

Permalink
swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
jhays committed Aug 16, 2023
1 parent c03b66f commit c357891
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,31 @@ extension BaseItemDto {

return try matchingMediaSource.videoPlayerViewModel(with: self, playSessionID: response.value.playSessionID!)
}

func liveVideoPlayerViewModel(with mediaSource: MediaSourceInfo) async throws -> VideoPlayerViewModel {

let builder = DeviceProfileBuilder()
// TODO: fix bitrate settings
let tempOverkillBitrate = 360_000_000
builder.setMaxBitrate(bitrate: tempOverkillBitrate)
let profile = builder.buildProfile()

let userSession = Container.userSession.callAsFunction()

let playbackInfo = PlaybackInfoDto(deviceProfile: profile)
let playbackInfoParameters = Paths.GetPostedPlaybackInfoParameters(
userID: userSession.user.id,
maxStreamingBitrate: tempOverkillBitrate
)

let request = Paths.getPostedPlaybackInfo(
itemID: self.id!,
parameters: playbackInfoParameters,
playbackInfo
)

let response = try await userSession.client.send(request)

var matchingMediaSource: MediaSourceInfo? = nil
if let responseMediaSources = response.value.mediaSources {
for responseMediaSource in responseMediaSources {
Expand All @@ -85,7 +85,7 @@ extension BaseItemDto {
guard let matchingMediaSource else {
throw JellyfinAPIError("Matching media source not in playback info")
}

return try matchingMediaSource.liveVideoPlayerViewModel(
with: self,
playSessionID: response.value.playSessionID!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,39 @@ extension MediaSourceInfo {
streamType: streamType
)
}

func liveVideoPlayerViewModel(with item: BaseItemDto, playSessionID: String) throws -> VideoPlayerViewModel {
let userSession = Container.userSession.callAsFunction()
let playbackURL: URL
let streamType: StreamType

if let transcodingURL, !Defaults[.Experimental.liveTVForceDirectPlay] {
guard let fullTranscodeURL = URL(string: transcodingURL, relativeTo: userSession.server.currentURL)
else { throw JellyfinAPIError("Unable to construct transcoded url") }
playbackURL = fullTranscodeURL
streamType = .transcode
} else {

let videoStreamParameters = Paths.GetVideoStreamParameters(
isStatic: true,
tag: item.etag,
playSessionID: playSessionID,
mediaSourceID: id
)

let videoStreamRequest = Paths.getVideoStream(
itemID: item.id!,
parameters: videoStreamParameters
)

playbackURL = userSession.client.fullURL(with: videoStreamRequest)
streamType = .direct
}

let videoStreams = mediaStreams?.filter { $0.type == .video } ?? []
let audioStreams = mediaStreams?.filter { $0.type == .audio } ?? []
let subtitleStreams = mediaStreams?.filter { $0.type == .subtitle } ?? []

return .init(
playbackURL: playbackURL,
item: item,
Expand Down
6 changes: 3 additions & 3 deletions Shared/ViewModels/LiveVideoPlayerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Foundation
import JellyfinAPI

class LiveVideoPlayerManager: VideoPlayerManager {

init(item: BaseItemDto, mediaSource: MediaSourceInfo) {
super.init()

Task {
let viewModel = try await item.liveVideoPlayerViewModel(with: mediaSource)

await MainActor.run {
self.currentViewModel = viewModel
}
Expand Down

0 comments on commit c357891

Please sign in to comment.