Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[WIP] [iOS & tvOS] Internal Text Subtitle Offset #1462

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
36 changes: 28 additions & 8 deletions Shared/Extensions/JellyfinAPI/MediaStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,28 +230,48 @@ extension [MediaStream] {
var orderedInternal: [MediaStream] = []

let subtitleInternal = internalTracks.filter { $0.type == .subtitle }
let videoInternal = internalTracks.filter { $0.type == .video }
let audioInternal = internalTracks.filter { $0.type == .audio }

// TODO: Do we need this for other media types? I think movies/shows we only care about video, audio, and subtitles.
let otherInternal = internalTracks.filter { $0.type != .video && $0.type != .audio && $0.type != .subtitle }

if streamType == .transcode {
// Only include the first video and first audio track for transcode.
let videoInternal = internalTracks.filter { $0.type == .video }
let audioInternal = internalTracks.filter { $0.type == .audio }

if let firstVideo = videoInternal.first {
orderedInternal.append(firstVideo)
}
if let selectedAudio = audioInternal.first(where: { $0.index == selectedAudioStreamIndex }) {
orderedInternal.append(selectedAudio)
}

orderedInternal += subtitleInternal
let externalSubtitles = externalTracks.filter { $0.type == .subtitle }

/// Transcodes with only internal text-subtitles the first and last track switch places???
if subtitleInternal.count > 1 &&
externalSubtitles.isEmpty &&
subtitleInternal == subtitleInternal.filter({ $0.isTextSubtitleStream == true })
{
/// Remove invalid subtitles for transcodes
var reorderedSubtitleInternal = subtitleInternal.filter { $0.isSupportsExternalStream == true }

let firstDeliveryURL = subtitleInternal.first?.deliveryURL
let lastDeliveryURL = subtitleInternal.last?.deliveryURL

if var firstItem = reorderedSubtitleInternal.first, var lastItem = reorderedSubtitleInternal.last {
firstItem.deliveryURL = lastDeliveryURL
lastItem.deliveryURL = firstDeliveryURL

reorderedSubtitleInternal[0] = firstItem
reorderedSubtitleInternal[reorderedSubtitleInternal.count - 1] = lastItem
}

orderedInternal += reorderedSubtitleInternal
} else {
orderedInternal += subtitleInternal.filter { $0.isSupportsExternalStream == true }
}

orderedInternal += otherInternal
} else {
let videoInternal = internalTracks.filter { $0.type == .video }
let audioInternal = internalTracks.filter { $0.type == .audio }

orderedInternal = videoInternal + audioInternal + subtitleInternal + otherInternal
}

Expand Down