mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Fix selecting quality
This commit is contained in:
parent
06bae05a66
commit
26f672ff4f
@ -454,11 +454,12 @@ final class PlayerModel: ObservableObject {
|
||||
}
|
||||
|
||||
fileprivate func updateNowPlayingInfo() {
|
||||
let duration: Int? = currentItem.video.live ? nil : Int(currentItem.videoDuration ?? 0)
|
||||
let nowPlayingInfo: [String: AnyObject] = [
|
||||
MPMediaItemPropertyTitle: currentItem.video.title as AnyObject,
|
||||
MPMediaItemPropertyArtist: currentItem.video.author as AnyObject,
|
||||
MPMediaItemPropertyArtwork: currentArtwork as AnyObject,
|
||||
MPMediaItemPropertyPlaybackDuration: (currentItem.video.live ? nil : Int(currentItem.videoDuration ?? 0)) as AnyObject,
|
||||
MPMediaItemPropertyPlaybackDuration: duration as AnyObject,
|
||||
MPNowPlayingInfoPropertyIsLiveStream: currentItem.video.live as AnyObject,
|
||||
MPNowPlayingInfoPropertyElapsedPlaybackTime: player.currentTime().seconds as AnyObject,
|
||||
MPNowPlayingInfoPropertyPlaybackQueueCount: queue.count as AnyObject,
|
||||
|
@ -66,10 +66,19 @@ extension PlayerModel {
|
||||
}
|
||||
|
||||
private func preferredStream(_ streams: [Stream]) -> Stream? {
|
||||
let quality = Defaults[.quality]
|
||||
var streams = streams
|
||||
|
||||
if let id = Defaults[.playerInstanceID] {
|
||||
return streams.first { $0.instance.id == id }
|
||||
} else {
|
||||
return streams.first
|
||||
streams = streams.filter { $0.instance.id == id }
|
||||
}
|
||||
|
||||
switch quality {
|
||||
case .best:
|
||||
return streams.first { $0.kind == .hls } ?? streams.first
|
||||
default:
|
||||
let sorted = streams.filter { $0.kind != .hls }.sorted { $0.resolution > $1.resolution }
|
||||
return sorted.first(where: { $0.resolution.height <= quality.value.height })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,28 +4,6 @@ import Foundation
|
||||
|
||||
// swiftlint:disable:next final_class
|
||||
class Stream: Equatable, Hashable, Identifiable {
|
||||
enum ResolutionSetting: String, Defaults.Serializable, CaseIterable {
|
||||
case hd720pFirstThenBest, hd1080p, hd720p, sd480p, sd360p, sd240p, sd144p
|
||||
|
||||
var value: Stream.Resolution {
|
||||
switch self {
|
||||
case .hd720pFirstThenBest:
|
||||
return .hd720p
|
||||
default:
|
||||
return Stream.Resolution(rawValue: rawValue)!
|
||||
}
|
||||
}
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .hd720pFirstThenBest:
|
||||
return "Default: adaptive"
|
||||
default:
|
||||
return value.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Resolution: String, CaseIterable, Comparable, Defaults.Serializable {
|
||||
case hd1440p60, hd1440p, hd1080p60, hd1080p, hd720p60, hd720p, sd480p, sd360p, sd240p, sd144p, unknown
|
||||
|
||||
|
@ -1,18 +1,6 @@
|
||||
import Defaults
|
||||
import Foundation
|
||||
|
||||
enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
|
||||
case always, whenFits, never
|
||||
|
||||
static var defaultValue: Self {
|
||||
#if os(macOS)
|
||||
.always
|
||||
#else
|
||||
.whenFits
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extension Defaults.Keys {
|
||||
static let invidiousInstanceID = "default-invidious-instance"
|
||||
static let pipedInstanceID = "default-piped-instance"
|
||||
@ -54,7 +42,7 @@ extension Defaults.Keys {
|
||||
static let channelOnThumbnail = Key<Bool>("channelOnThumbnail", default: true)
|
||||
static let timeOnThumbnail = Key<Bool>("timeOnThumbnail", default: true)
|
||||
|
||||
static let quality = Key<Stream.ResolutionSetting>("quality", default: .hd720pFirstThenBest)
|
||||
static let quality = Key<ResolutionSetting>("quality", default: .best)
|
||||
static let playerSidebar = Key<PlayerSidebarSetting>("playerSidebar", default: PlayerSidebarSetting.defaultValue)
|
||||
static let playerInstanceID = Key<Instance.ID?>("playerInstance")
|
||||
static let showKeywords = Key<Bool>("showKeywords", default: false)
|
||||
@ -68,3 +56,37 @@ extension Defaults.Keys {
|
||||
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
|
||||
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
|
||||
}
|
||||
|
||||
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {
|
||||
case best, hd720p, sd480p, sd360p, sd240p, sd144p
|
||||
|
||||
var value: Stream.Resolution {
|
||||
switch self {
|
||||
case .best:
|
||||
return .hd720p
|
||||
default:
|
||||
return Stream.Resolution(rawValue: rawValue)!
|
||||
}
|
||||
}
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .best:
|
||||
return "Best available"
|
||||
default:
|
||||
return value.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
|
||||
case always, whenFits, never
|
||||
|
||||
static var defaultValue: Self {
|
||||
#if os(macOS)
|
||||
.always
|
||||
#else
|
||||
.whenFits
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ struct PlaybackSettings: View {
|
||||
|
||||
private var qualityPicker: some View {
|
||||
Picker("Quality", selection: $quality) {
|
||||
ForEach(Stream.ResolutionSetting.allCases, id: \.self) { resolution in
|
||||
ForEach(ResolutionSetting.allCases, id: \.self) { resolution in
|
||||
Text(resolution.description).tag(resolution)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user