Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expand IINA screenshot functionality to screenshot flags #4853

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

svobs
Copy link
Contributor

@svobs svobs commented Mar 19, 2024


Description:

Current functionality

IINA's Playback > Take a Screenshot menu item (I'll call it "IINA's screenshot") utilizes mpv's screenshot command (i.e. "mpv's screenshot") as its backbone, but differs in the following ways:

  1. Displays a screenshot thumbnail using the OSD (if configured in prefs).
  2. Uses the value of screenshotIncludeSubtitle pref (bool) to decide between subtitles or video flags to send to screenshot.
  3. Can be configured to store to clipboard instead of file, or in addition to file, or...disabled entirely (is this good...?).

If a key binding's is mapped to screenshot with no flags, then it is matched to the menu item, and so it will call IINA's screenshot. However, if any flags are supplied (e.g., screenshot subtitles), it will not match and will end up calling mpv's screenshot.

PR functional changes

  • Expands functionality of PlayerCore.screenshot() to take an optional key binding argument, and adds a call to it from PlayerWindowController.handleKeyBinding so it can handle screenshot actions.
  • Adds logic so that if flags are specified by the key binding, they will be used (if possible - see caveat 1 below). If no flags are specified, then the value for pref key screenshotIncludeSubtitle will be used to determine the flags.

Caveats

  1. Does not add IINA screenshot support for each-frame flag. If this flag is present, mpv's screenshot will be used instead (sorry - maybe some future PR).
  2. It does add handling for screenshot window, although the feature itself will continue to error out until the fix for Ctrl-s (screenshot window) does not work #4822 is merged.
  3. IINA's screenshot deviates slightly from the spec for mpv's screenshot, and by its nature this PR will make this unavoidable for more screenshot cases. As noted in the code comments:
    i. If the stored values for Preference.Key.screenshotSaveToFile and Preference.Key.screenshotCopyToClipboard are set to false, all screenshot commands will be ignored. It may not be obvious to the end user why their screenshot seems to be getting ignored. Although no one seems to have filed any issues about it.
    ii. When no flags are given with screenshot, the mpv spec says that default is subtitles flag. But IINA will use either subtitles or video, depending on the value for Preference.Key.screenshotIncludeSubtitle.

@svobs svobs changed the title Integrate mpv 'screenshot' key binding & its flags with IINA command Expand IINA screenshot functionality to screenshot flags Mar 19, 2024
Summary:
• Applies IINA screenshot OSD & other enhancements to screenshot
  commands which have flags (except for "each-frame" flag)
• Expand functionality of PlayerCore.screenshot() to handle screenshot
  command from a key binding
• Add logic so that if any flags are found in the screenshot command,
  they will be used
• Else if no flags are specified, then the value for pref key
  "screenshotIncludeSubtitle" will be used to determine the flags
@svobs svobs force-pushed the pr-screenshot-opts-integration branch from 594faf2 to 1c72e06 Compare March 19, 2024 08:27
@low-batt
Copy link
Contributor

I'm busy on Tuesdays, so I only had a chance to read through the description and peek at the code. Seems like the right approach. I will take a closer look soon.

Copy link
Contributor

@low-batt low-batt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That guard statement that is checking vid needs to be moved to the start of the method. Also it is confusing that the s key is not treated as a key binding.

Otherwise, it worked fine in my tests.

/// 1. As noted above, if the stored values for `Preference.Key.screenshotSaveToFile` and `Preference.Key.screenshotCopyToClipboard` are
/// set to false, all screenshot commands will be ignored.
/// 2. When no flags are given with `screenshot`: instead of defaulting to `subtitles` as mpv does, IINA will use the value for
/// `Preference.Key.screenshotIncludeSubtitle` to decide between `subtitles` or `video`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation comment is very helpful!

If you highlight the function name and then under the Xcode Editor menu open the Structure sub-menu and click on Add Documentation then Xcode will add a template with the appropriate documentation tags. In the case of screenshot method it will add:

  /// <#Description#>
  /// - Parameter keyBinding: <#keyBinding description#>
  /// - Returns: <#description#>

@discardableResult
func screenshot(fromKeyBinding keyBinding: KeyMapping? = nil) -> Bool {
guard isScreenshotEnabled() else {
Logger.log("Ignoring screenshot request\(keyBinding == nil ? "" : " from key binding") because all forms of screenshots are disabled in prefs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message is not entirely correct. If you disable the screenshots settings and then press s key the log message will not indicate the request was triggered "from key binding".

}
}

guard let vid = info.vid, vid > 0 else { return false } // TODO: why this is needed?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always good to emit a log message when ignoring input from the user like was done at the start of the method indicating screenshots are disabled. If that had been done in the past for this statement not only would it be possible to tell what happened from the log file, it also would have made obvious what this code is for. I suggest changing this code to something like this:

    let fromKey = keyBinding == nil ? "" : " from key binding"
    guard let vid = info.vid, vid > 0 else {
      Logger.log("Ignoring screenshot request\(fromKey) because no video stream is being played")
      return false
    }

And moving it right to the start of the method.

I believe the thinking was that it is better to ignore the request than interrupt the user with the alert that says "Cannot take a screenshot".

To trigger this play a mp3 and press the s key.

@svobs
Copy link
Contributor Author

svobs commented Apr 3, 2024

I believe the thinking was that it is better to ignore the request than interrupt the user with the alert that says "Cannot take a screenshot".

That makes sense.

I pushed another commit with the suggestions, although I removed the talk about key bindings from the error messages (weren't really useful) but added a couple extra lines of logging to facilitate future troubleshooting.

Copy link
Contributor

@low-batt low-batt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled latest commits, built and tested.
Changes look good to me.

@low-batt low-batt requested a review from uiryuu April 3, 2024 20:54
Copy link
Member

@uiryuu uiryuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and looks good.

I think we should prevent Preference.Key.screenshotSaveToFile and Preference.Key.screenshotCopyToClipboard from both being false. I will consider making a PR to make these 2 options radio buttons so that only one of them can be selected. And also combining these 2 preference keys into 1 so that the user cannot set them both to false in via commands either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants