Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
import AVFoundation
|
2021-10-16 22:48:58 +00:00
|
|
|
import Foundation
|
|
|
|
import Siesta
|
2021-10-18 21:53:02 +00:00
|
|
|
import SwiftUI
|
2021-10-16 22:48:58 +00:00
|
|
|
|
|
|
|
extension PlayerModel {
|
|
|
|
var isLoadingAvailableStreams: Bool {
|
|
|
|
streamSelection.isNil || availableStreams.isEmpty
|
|
|
|
}
|
|
|
|
|
|
|
|
var isLoadingStream: Bool {
|
|
|
|
!stream.isNil && stream != streamSelection
|
|
|
|
}
|
|
|
|
|
2021-10-17 21:49:56 +00:00
|
|
|
var availableStreamsSorted: [Stream] {
|
|
|
|
availableStreams.sorted(by: streamsSorter)
|
|
|
|
}
|
|
|
|
|
2022-12-18 12:11:06 +00:00
|
|
|
func loadAvailableStreams(_ video: Video, onCompletion: @escaping (ResponseInfo) -> Void = { _ in }) {
|
2022-12-21 20:16:47 +00:00
|
|
|
captions = nil
|
2021-10-16 22:48:58 +00:00
|
|
|
availableStreams = []
|
2021-12-19 16:56:47 +00:00
|
|
|
|
2022-09-28 14:27:01 +00:00
|
|
|
guard let playerInstance else { return }
|
2021-10-16 22:48:58 +00:00
|
|
|
|
2022-12-21 17:13:41 +00:00
|
|
|
guard let api = playerAPI(video) else { return }
|
2022-06-18 12:39:49 +00:00
|
|
|
logger.info("loading streams from \(playerInstance.description)")
|
2022-12-21 17:13:41 +00:00
|
|
|
fetchStreams(api.video(video.videoID), instance: playerInstance, video: video, onCompletion: onCompletion)
|
2021-10-16 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
private func fetchStreams(
|
|
|
|
_ resource: Resource,
|
|
|
|
instance: Instance,
|
2021-10-16 22:48:58 +00:00
|
|
|
video: Video,
|
|
|
|
onCompletion: @escaping (ResponseInfo) -> Void = { _ in }
|
|
|
|
) {
|
2021-10-20 22:21:50 +00:00
|
|
|
resource
|
2021-10-16 22:48:58 +00:00
|
|
|
.load()
|
|
|
|
.onSuccess { response in
|
|
|
|
if let video: Video = response.typedContent() {
|
2022-12-10 00:23:13 +00:00
|
|
|
VideosCacheModel.shared.storeVideo(video)
|
2022-11-11 19:34:37 +00:00
|
|
|
guard video.videoID == self.currentVideo?.videoID else {
|
2021-12-29 18:55:41 +00:00
|
|
|
self.logger.info("ignoring loaded streams from \(instance.description) as current video has changed")
|
|
|
|
return
|
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
self.streamsWithInstance(instance: instance, streams: video.streams) { processedStreams in
|
|
|
|
self.availableStreams = processedStreams
|
|
|
|
}
|
2021-12-19 16:56:47 +00:00
|
|
|
} else {
|
|
|
|
self.logger.critical("no streams available from \(instance.description)")
|
2021-10-16 22:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.onCompletion(onCompletion)
|
2022-06-29 22:44:32 +00:00
|
|
|
.onFailure { [weak self] responseError in
|
|
|
|
self?.navigation.presentAlert(title: "Could not load streams", message: responseError.userMessage)
|
|
|
|
self?.videoBeingOpened = nil
|
|
|
|
}
|
2021-10-16 22:48:58 +00:00
|
|
|
}
|
|
|
|
|
2024-05-22 20:20:51 +00:00
|
|
|
func streamsWithInstance(instance: Instance, streams: [Stream], completion: @escaping ([Stream]) -> Void) {
|
2024-05-17 13:29:42 +00:00
|
|
|
// Queue for stream processing
|
2024-05-22 20:20:51 +00:00
|
|
|
let streamProcessingQueue = DispatchQueue(label: "stream.yattee.streamProcessing.Queue")
|
2024-05-17 13:29:42 +00:00
|
|
|
// Queue for accessing the processedStreams array
|
|
|
|
let processedStreamsQueue = DispatchQueue(label: "stream.yattee.processedStreams.Queue")
|
|
|
|
// DispatchGroup for managing multiple tasks
|
|
|
|
let streamProcessingGroup = DispatchGroup()
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
|
2024-05-17 13:29:42 +00:00
|
|
|
var processedStreams = [Stream]()
|
2024-05-22 20:20:51 +00:00
|
|
|
let instance = instance
|
|
|
|
|
|
|
|
var hasForbiddenAsset = false
|
|
|
|
var hasAllowedAsset = false
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
|
2024-05-17 13:29:42 +00:00
|
|
|
for stream in streams {
|
|
|
|
streamProcessingQueue.async(group: streamProcessingGroup) {
|
|
|
|
let forbiddenAssetTestGroup = DispatchGroup()
|
2024-05-22 20:20:51 +00:00
|
|
|
if !hasAllowedAsset, !hasForbiddenAsset, !instance.proxiesVideos, stream.format != Stream.Format.unknown {
|
|
|
|
let (nonHLSAssets, hlsURLs) = self.getAssets(from: [stream])
|
|
|
|
if let firstStream = nonHLSAssets.first {
|
|
|
|
let asset = firstStream.0
|
|
|
|
let url = firstStream.1
|
|
|
|
let requestRange = firstStream.2
|
2024-05-17 13:29:42 +00:00
|
|
|
|
|
|
|
if instance.app == .invidious {
|
2024-05-22 20:20:51 +00:00
|
|
|
self.testAsset(url: url, range: requestRange, isHLS: false, forbiddenAssetTestGroup: forbiddenAssetTestGroup) { status in
|
|
|
|
switch status {
|
|
|
|
case HTTPStatus.Forbidden:
|
|
|
|
hasForbiddenAsset = true
|
|
|
|
case HTTPStatus.PartialContent:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
case HTTPStatus.OK:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
}
|
|
|
|
} else if instance.app == .piped {
|
2024-05-22 20:20:51 +00:00
|
|
|
self.testPipedAssets(asset: asset!, requestRange: requestRange, isHLS: false, forbiddenAssetTestGroup: forbiddenAssetTestGroup) { status in
|
|
|
|
switch status {
|
|
|
|
case HTTPStatus.Forbidden:
|
|
|
|
hasForbiddenAsset = true
|
|
|
|
case HTTPStatus.PartialContent:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
case HTTPStatus.OK:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 20:20:51 +00:00
|
|
|
} else if let firstHLS = hlsURLs.first {
|
|
|
|
let asset = AVURLAsset(url: firstHLS)
|
|
|
|
if instance.app == .piped {
|
|
|
|
self.testPipedAssets(asset: asset, requestRange: nil, isHLS: true, forbiddenAssetTestGroup: forbiddenAssetTestGroup) { status in
|
|
|
|
switch status {
|
|
|
|
case HTTPStatus.Forbidden:
|
|
|
|
hasForbiddenAsset = true
|
|
|
|
case HTTPStatus.PartialContent:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
case HTTPStatus.OK:
|
|
|
|
hasAllowedAsset = true
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
forbiddenAssetTestGroup.wait()
|
|
|
|
|
|
|
|
// Post-processing code
|
2024-05-22 20:20:51 +00:00
|
|
|
if instance.app == .invidious, hasForbiddenAsset || instance.proxiesVideos {
|
|
|
|
if let audio = stream.audioAsset {
|
|
|
|
stream.audioAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: audio)
|
|
|
|
}
|
|
|
|
if let video = stream.videoAsset {
|
|
|
|
stream.videoAsset = InvidiousAPI.proxiedAsset(instance: instance, asset: video)
|
|
|
|
}
|
|
|
|
} else if instance.app == .piped, !instance.proxiesVideos, !hasForbiddenAsset {
|
|
|
|
if let hlsURL = stream.hlsURL {
|
|
|
|
PipedAPI.nonProxiedAsset(url: hlsURL) { possibleNonProxiedURL in
|
|
|
|
if let nonProxiedURL = possibleNonProxiedURL {
|
|
|
|
stream.hlsURL = nonProxiedURL.url
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-22 20:20:51 +00:00
|
|
|
} else {
|
|
|
|
if let audio = stream.audioAsset {
|
|
|
|
PipedAPI.nonProxiedAsset(asset: audio) { nonProxiedAudioAsset in
|
|
|
|
stream.audioAsset = nonProxiedAudioAsset
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
2024-05-22 20:20:51 +00:00
|
|
|
}
|
|
|
|
if let video = stream.videoAsset {
|
|
|
|
PipedAPI.nonProxiedAsset(asset: video) { nonProxiedVideoAsset in
|
|
|
|
stream.videoAsset = nonProxiedVideoAsset
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
|
|
|
|
// Append to processedStreams within the processedStreamsQueue
|
|
|
|
processedStreamsQueue.sync {
|
|
|
|
processedStreams.append(stream)
|
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
2024-05-17 13:29:42 +00:00
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
|
2024-05-17 13:29:42 +00:00
|
|
|
streamProcessingGroup.notify(queue: .main) {
|
|
|
|
// Access and pass processedStreams within the processedStreamsQueue block
|
|
|
|
processedStreamsQueue.sync {
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
completion(processedStreams)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 20:20:51 +00:00
|
|
|
private func getAssets(from streams: [Stream]) -> (nonHLSAssets: [(AVURLAsset?, URL, String?)], hlsURLs: [URL]) {
|
|
|
|
var nonHLSAssets = [(AVURLAsset?, URL, String?)]()
|
|
|
|
var hlsURLs = [URL]()
|
2021-10-21 23:29:10 +00:00
|
|
|
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
for stream in streams {
|
|
|
|
if stream.isHLS {
|
|
|
|
if let url = stream.hlsURL?.url {
|
2024-05-22 20:20:51 +00:00
|
|
|
hlsURLs.append(url)
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if let asset = stream.audioAsset {
|
2024-05-22 20:20:51 +00:00
|
|
|
nonHLSAssets.append((asset, asset.url, stream.requestRange))
|
2022-06-18 12:39:49 +00:00
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
if let asset = stream.videoAsset {
|
2024-05-22 20:20:51 +00:00
|
|
|
nonHLSAssets.append((asset, asset.url, stream.requestRange))
|
2022-06-18 12:39:49 +00:00
|
|
|
}
|
2021-10-21 23:29:10 +00:00
|
|
|
}
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
2021-10-22 15:00:09 +00:00
|
|
|
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
return (nonHLSAssets, hlsURLs)
|
|
|
|
}
|
|
|
|
|
2024-05-22 20:20:51 +00:00
|
|
|
private func testAsset(url: URL, range: String?, isHLS: Bool, forbiddenAssetTestGroup: DispatchGroup, completion: @escaping (Int) -> Void) {
|
2024-05-17 13:29:42 +00:00
|
|
|
// In case the range is nil, generate a random one.
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
let randomEnd = Int.random(in: 200 ... 800)
|
|
|
|
let requestRange = range ?? "0-\(randomEnd)"
|
|
|
|
|
|
|
|
forbiddenAssetTestGroup.enter()
|
|
|
|
URLTester.testURLResponse(url: url, range: requestRange, isHLS: isHLS) { statusCode in
|
2024-05-22 20:20:51 +00:00
|
|
|
completion(statusCode)
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
forbiddenAssetTestGroup.leave()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-22 20:20:51 +00:00
|
|
|
private func testPipedAssets(asset: AVURLAsset, requestRange: String?, isHLS: Bool, forbiddenAssetTestGroup: DispatchGroup, completion: @escaping (Int) -> Void) {
|
2024-05-17 13:29:42 +00:00
|
|
|
PipedAPI.nonProxiedAsset(asset: asset) { possibleNonProxiedAsset in
|
|
|
|
if let nonProxiedAsset = possibleNonProxiedAsset {
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
self.testAsset(url: nonProxiedAsset.url, range: requestRange, isHLS: isHLS, forbiddenAssetTestGroup: forbiddenAssetTestGroup, completion: completion)
|
2024-05-17 13:29:42 +00:00
|
|
|
} else {
|
2024-05-22 20:20:51 +00:00
|
|
|
completion(0)
|
Conditional proxying
I added a new feature. When instances are not proxied, Yattee first checks the URL to make sure it is not a restricted video. Usually, music videos and sports content can only be played back by the same IP address that requested the URL in the first place. That is why some videos do not play when the proxy is disabled.
This approach has multiple advantages. First and foremost, It reduced the load on Invidious/Piped instances, since users can now directly access the videos without going through the instance, which might be severely bandwidth limited. Secondly, users don't need to manually turn on the proxy when they want to watch IP address bound content, since Yattee automatically proxies such content.
Furthermore, adding the proxy option allows mitigating some severe playback issues with invidious instances. Invidious by default returns proxied URLs for videos, and due to some bug in the Invidious proxy, scrubbing or continuing playback at a random timestamp can lead to severe wait times for the users.
This should fix numerous playback issues: #666, #626, #590, #585, #498, #457, #400
2024-05-09 18:07:55 +00:00
|
|
|
}
|
2021-10-16 22:48:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-19 10:39:47 +00:00
|
|
|
func streamsSorter(lhs: Stream, rhs: Stream) -> Bool {
|
|
|
|
// Use optional chaining to simplify nil handling
|
|
|
|
guard let lhsRes = lhs.resolution?.height, let rhsRes = rhs.resolution?.height else {
|
2021-10-22 20:49:31 +00:00
|
|
|
return lhs.kind < rhs.kind
|
|
|
|
}
|
|
|
|
|
2024-05-19 10:39:47 +00:00
|
|
|
// Compare either kind or resolution based on conditions
|
|
|
|
return lhs.kind == rhs.kind ? (lhsRes > rhsRes) : (lhs.kind < rhs.kind)
|
2021-10-17 21:49:56 +00:00
|
|
|
}
|
2021-10-16 22:48:58 +00:00
|
|
|
}
|