From 172e091776e9f02815aa5402c1366825c8965f5c Mon Sep 17 00:00:00 2001 From: Hechen Li Date: Thu, 27 Jun 2024 20:22:09 -0400 Subject: [PATCH 1/2] Fix conflicting constraints in subtitle sidebar, #5027 --- iina/Base.lproj/QuickSettingViewController.xib | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iina/Base.lproj/QuickSettingViewController.xib b/iina/Base.lproj/QuickSettingViewController.xib index 051da89ccf..a50039d045 100644 --- a/iina/Base.lproj/QuickSettingViewController.xib +++ b/iina/Base.lproj/QuickSettingViewController.xib @@ -1982,9 +1982,9 @@ - + - + @@ -2019,7 +2019,7 @@ - + @@ -2027,7 +2027,7 @@ - + @@ -2042,7 +2042,7 @@ - + @@ -2050,7 +2050,7 @@ - + From 2362e7d4829b62931850dce1f1766278b21e6a5d Mon Sep 17 00:00:00 2001 From: Matt Svoboda Date: Fri, 28 Jun 2024 17:21:19 -0700 Subject: [PATCH 2/2] Enhancements to online subtitle download OSD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Details: • Improve text size of sub-heading and table items slightly • Improve table style & border • Remove time from upload date • Remove rating from displayed attributes • Add release year in parentheses • Add up to 2 fraction digits to fps attribute's displayed value • Add osd.sub_downloading ("Downloading %d subtitles") & reference it while downloading instead of osd.sub_found • Remove " Downloading…" from osd.sub_found to make it more appropriate as a table heading --- iina/Base.lproj/Localizable.strings | 3 +- iina/Base.lproj/SubChooseViewController.xib | 102 +++++++++++--------- iina/Extensions.swift | 15 +++ iina/OSDMessage.swift | 7 +- iina/OnlineSubtitle.swift | 4 +- iina/OpenSubClient.swift | 2 - iina/OpenSubSubtitle.swift | 31 +++--- iina/SubChooseViewController.swift | 5 + iina/en.lproj/Localizable.strings | 3 +- 9 files changed, 105 insertions(+), 67 deletions(-) diff --git a/iina/Base.lproj/Localizable.strings b/iina/Base.lproj/Localizable.strings index f54513af15..4a982b0159 100644 --- a/iina/Base.lproj/Localizable.strings +++ b/iina/Base.lproj/Localizable.strings @@ -88,7 +88,8 @@ "osd.find_online_sub" = "Finding online subtitles…"; "osd.find_online_sub.source" = "from"; "osd.sub_not_found" = "No subtitles found"; -"osd.sub_found" = "%d subtitles found. Downloading…"; +"osd.sub_found" = "%d subtitles found."; +"osd.sub_downloading" = "Downloading %d subtitles"; "osd.sub_downloaded" = "Subtitle downloaded"; "osd.sub_saved" = "Subtitle saved"; "osd.network_error" = "Network error"; diff --git a/iina/Base.lproj/SubChooseViewController.xib b/iina/Base.lproj/SubChooseViewController.xib index c7ebb990d0..6b4680c22d 100644 --- a/iina/Base.lproj/SubChooseViewController.xib +++ b/iina/Base.lproj/SubChooseViewController.xib @@ -16,30 +16,28 @@ - + - - - - + + + + - - - - - + + + + - - - + + - + @@ -52,53 +50,53 @@ - + - - - + + + - + - + - - - - + + + + - + - - - - - + + + + + - + - + - + - - - - - + + + + + @@ -109,9 +107,20 @@ + + + + + + + + + + + - + - + - + - - + + + diff --git a/iina/Extensions.swift b/iina/Extensions.swift index b0011ad884..606f10bfe9 100644 --- a/iina/Extensions.swift +++ b/iina/Extensions.swift @@ -281,6 +281,15 @@ extension BinaryInteger { } } +// Formats a number to max 2 digits after the decimal, rounded, but will omit trailing zeroes, and no commas or other formatting for large numbers +fileprivate let fmtDecimalMaxFractionDigits2: NumberFormatter = { + let fmt = NumberFormatter() + fmt.numberStyle = .decimal + fmt.usesGroupingSeparator = false + fmt.maximumFractionDigits = 2 + return fmt +}() + extension FloatingPoint { func clamped(to range: Range) -> Self { if self < range.lowerBound { @@ -291,6 +300,12 @@ extension FloatingPoint { return self } } + + /// Formats as String, rounding the number to 2 digits after the decimal + var stringWithMaxFractionDigits2: String { + return fmtDecimalMaxFractionDigits2.string(for: self)! + } + } extension NSColor { diff --git a/iina/OSDMessage.swift b/iina/OSDMessage.swift index 72d47a62cf..5aec0827cc 100644 --- a/iina/OSDMessage.swift +++ b/iina/OSDMessage.swift @@ -73,6 +73,7 @@ enum OSDMessage { case startFindingSub(String) // sub source case foundSub(Int) + case downloadingSub(Int, String) // download count, sub source case downloadedSub(String) // filename case savedSub case cannotLogin @@ -336,9 +337,13 @@ enum OSDMessage { case .foundSub(let count): let str = count == 0 ? NSLocalizedString("osd.sub_not_found", comment: "No subtitles found.") : - String(format: NSLocalizedString("osd.sub_found", comment: "%d subtitle(s) found. Downloading..."), count) + String(format: NSLocalizedString("osd.sub_found", comment: "%d subtitle(s) found."), count) return (str, .normal) + case .downloadingSub(let count, let source): + let str = String(format: NSLocalizedString("osd.sub_downloading", comment: "Downloading %d subtitles"), count) + return (str, .withText(NSLocalizedString("osd.find_online_sub.source", comment: "from") + " " + source)) + case .downloadedSub(let filename): return ( NSLocalizedString("osd.sub_downloaded", comment: "Subtitle downloaded"), diff --git a/iina/OnlineSubtitle.swift b/iina/OnlineSubtitle.swift index 1832acf822..fa150b7c63 100644 --- a/iina/OnlineSubtitle.swift +++ b/iina/OnlineSubtitle.swift @@ -145,11 +145,11 @@ class OnlineSubtitle: NSObject { func fetchSubtitles(url: URL, player: PlayerCore) -> Promise<[URL]> { return getFetcher().fetch(from: url, withProviderID: providerID, playerCore: player) - .get { subtitles in + .get { [self] subtitles in if subtitles.isEmpty { throw OnlineSubtitle.CommonError.noResult } else { - player.sendOSD(.foundSub(subtitles.count)) + player.sendOSD(.downloadingSub(subtitles.count, name)) } }.thenFlatMap { subtitle in subtitle.download() diff --git a/iina/OpenSubClient.swift b/iina/OpenSubClient.swift index 7135bbaaac..10d2816829 100644 --- a/iina/OpenSubClient.swift +++ b/iina/OpenSubClient.swift @@ -805,9 +805,7 @@ class OpenSubClient { var comments: String? #endif var downloadCount: Int -#if DEBUG var featureDetails: SubtitleFeatureDetails -#endif var files: [SubtitleFile] #if DEBUG var foreignPartsOnly: Bool? diff --git a/iina/OpenSubSubtitle.swift b/iina/OpenSubSubtitle.swift index 884faf104a..3a0823ca16 100644 --- a/iina/OpenSubSubtitle.swift +++ b/iina/OpenSubSubtitle.swift @@ -19,7 +19,7 @@ class OpenSub { private static let dateFormatter: DateFormatter = { let dateFormatter = DateFormatter() dateFormatter.dateStyle = .medium - dateFormatter.timeStyle = .medium + dateFormatter.timeStyle = .none return dateFormatter }() @@ -72,22 +72,25 @@ class OpenSub { /// view displayed to the user for choosing the subtitle files to download. override func getDescription() -> (name: String, left: String, right: String) { let attributes = subtitle.attributes - let downloadCount = String(attributes.downloadCount) - let filename = attributes.files[0].fileName - let framesPerSecond: String + var tokens: [String] = [] + + tokens.append(attributes.language) + + if let releaseYear = attributes.featureDetails.year, releaseYear > 0 { + tokens.append("(\(releaseYear))") + } + if let fps = attributes.fps, fps != 0 { - framesPerSecond = " \(String(Int(fps.rounded(.up)))) fps" - } else { - framesPerSecond = "" + tokens.append("\(fps.stringWithMaxFractionDigits2) fps") } - let language = attributes.language - let rating = String(attributes.ratings) + + let downloadCount = "\u{2b07}\(attributes.downloadCount)" + tokens.append(downloadCount) + + let fileName = attributes.files[0].fileName + let description = tokens.joined(separator: " ") let uploadDate = OpenSub.Subtitle.dateFormatter.string(from: attributes.uploadDate) - return ( - filename, - "\(language)\(framesPerSecond) \u{2b07}\(downloadCount) \u{2605}\(rating)", - uploadDate - ) + return (fileName, description, uploadDate) } } diff --git a/iina/SubChooseViewController.swift b/iina/SubChooseViewController.swift index 7901d120ff..a625cb502d 100644 --- a/iina/SubChooseViewController.swift +++ b/iina/SubChooseViewController.swift @@ -26,6 +26,11 @@ class SubChooseViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() + if let scrollView = tableView.enclosingScrollView { + scrollView.wantsLayer = true + scrollView.layer?.cornerRadius = 6 + } + tableView.delegate = self tableView.dataSource = self diff --git a/iina/en.lproj/Localizable.strings b/iina/en.lproj/Localizable.strings index 7cbd44e524..e053a025ab 100644 --- a/iina/en.lproj/Localizable.strings +++ b/iina/en.lproj/Localizable.strings @@ -88,7 +88,8 @@ "osd.find_online_sub" = "Finding online subtitles…"; "osd.find_online_sub.source" = "from"; "osd.sub_not_found" = "No subtitles found"; -"osd.sub_found" = "%d subtitles found. Downloading…"; +"osd.sub_found" = "%d subtitles found."; +"osd.sub_downloading" = "Downloading %d subtitles"; "osd.sub_downloaded" = "Subtitle downloaded"; "osd.sub_saved" = "Subtitle saved"; "osd.network_error" = "Network error";