Skip to content

Commit

Permalink
Break osd.sub_found into osd.sub_found and osd.sub_downloading, for m…
Browse files Browse the repository at this point in the history
…ore appropriately specific messages. SubChooseView: fix table border bezel, increase font size slightly and set preferred width to 600. Modify OpenSubtitles details: add release year, remove rating, add max 2 fraction digits to fps, remove time from upload date, increase spacing to make attribute separation more clear
  • Loading branch information
svobs committed Feb 24, 2024
1 parent d1029cb commit 424445f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 66 deletions.
3 changes: 2 additions & 1 deletion iina/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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";
Expand Down
102 changes: 56 additions & 46 deletions iina/Base.lproj/SubChooseViewController.xib

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions iina/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,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>) -> Self {
if self < range.lowerBound {
Expand All @@ -290,6 +299,12 @@ extension FloatingPoint {
return self
}
}

/// Formats as String, rounding the number to 2 digits after the decimal
var stringMaxFrac2: String {
return fmtDecimalMaxFractionDigits2.string(for: self)!
}

}

extension NSColor {
Expand Down
7 changes: 6 additions & 1 deletion iina/OSDMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum OSDMessage {

case startFindingSub(String) // sub source
case foundSub(Int)
case downloadingSub(Int, String) // download count, ssub source
case downloadedSub(String) // filename
case savedSub
case cannotLogin
Expand Down Expand Up @@ -289,9 +290,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"),
Expand Down
4 changes: 2 additions & 2 deletions iina/OnlineSubtitle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,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()
Expand Down
2 changes: 0 additions & 2 deletions iina/OpenSubClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
31 changes: 17 additions & 14 deletions iina/OpenSubSubtitle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()

Expand Down Expand Up @@ -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.stringMaxFrac2) 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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions iina/SubChooseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 424445f

Please sign in to comment.