Ajatt-Tools / mpvacious

🍜 Adds mpv keybindings to create Anki cards from movies and TV shows.
https://tatsumoto-ren.github.io/blog/mining-from-movies-and-tv-shows.html
GNU General Public License v3.0
592 stars 51 forks source link

OSX 10.15.7 clipboard autocopy or copy subtitle not working #8

Closed sirneb closed 4 years ago

sirneb commented 4 years ago

Environment:

Describe the bug I noticed that you made a commit to use pbcopy to support OSX. But clipboard autocopy doesn't work with the latest master script. I also tried doing control + c as well (though it's hard to know if there are any OSX binding that could be colliding with the shortcut) and it didn't seem to work.

To Reproduce Steps to reproduce the behavior:

  1. Press a
  2. Press t (to enable enabled)
  3. Run video with subtitles, clipboard has nothing to paste

Expected behavior It should copy the subtitles into the clipboard.

Screenshots not applicable.

tatsumoto-ren commented 4 years ago

Thank you for reporting this. Does the version of the add-on for macOS that Matt vs Japan linked under his video work? It has almost the same changes, I simply applied them here on github.

sirneb commented 4 years ago

I tried the version you linked. Anecdotally, It seems the only difference was that autocopy is on by default with his version. It also exhibited the same issue. Though, I did discover a few new nuisances.

It seems this problem is very specific to Japanese subtitles (Asian encoding?). The autocopy does work correctly with English subtitles. But it fails to work for Japanese, specifically it tries to copy but it ends up copying nothing. For instance, if I have something in my clipboard, and autocopy would clear my clipboard. So it tried to copy, just nothing(or an empty string) was copied.

So this tells me that there is something deeper going on, perhaps a problem outside of this script. Possibly related to encoding with the strings (for OSX?)?

Just for reference, not sure if it's related, this is the mpv mpv.conf I'm using.

sub-visibility=yes
sub-auto=fuzzy
alang: jpn, jp, en
slang: jpn, jp, en
audio-file-auto=fuzzy
save-position-on-quit=yes
autofit-larger=100%x100%
geometry=50%:50%
sub-font="Osaka"
sub-font-size=45

I had the change the font from Matt's, otherwise the fonts look like boxes for Japanese.

tatsumoto-ren commented 4 years ago

the version you linked also exhibited the same issue.

The user who suggested the change and reached out to Matt to publish it apparently didn't experience any issues. If it works for him then it may be machine-specific.

Does the previous version that uses xclip work for you? I believe macOS users can install xclip by running $ brew install xclip.

sirneb commented 4 years ago

Does the previous version that uses xclip work for you? I believe macOS users can install xclip by running $ brew install xclip.

I was able to get this method to work. xquartz is also required in order for xclip to work (brew tells you this). According to original poster, xquartz was supposed to automatically open but I have to open it manually. Also, I had to modify the script to when calling xclip using an environmental variable:

 local handle = io.popen('xclip -i -selection clipboard', 'w')

Changed to:

local handle = io.popen('DISPLAY=:0 xclip -i -selection clipboard', 'w')

There's probably a different way to configure this environmental variable globally. But it was to prove out that this does work. That said, I'm not quite sure why pbcopy behaves differently from xclip. I can definitely do echo "そんăȘんじゃăȘいっど" | pbcopy and it works just fine.

Anyhow, I'm not that familiar with lua and mpv but I could probably help dig into a bit later.

sirneb commented 4 years ago

I figured it out. I got pbcopy to work by doing:

local handle = io.popen('LANG=en_US.UTF-8 pbcopy', 'w')

Not sure why this is different on different machines though my mac OS is set to Japanese as the region, that probably added some variables to this.

tatsumoto-ren commented 4 years ago

Thank you for figuring it out. I'm gonna push the change in a few minutes. Please tell me if it works.

sirneb commented 4 years ago

Thanks, checked out master. Works perfectly!

kolpav commented 3 years ago

@tatsumoto-ren Hi I am having same problem with clipboard not working at all on OSX 11.1 MPV 0.32.0 I installed mpv via brew and mpvacious via curl. After reading this issue I also tried installing xclip but I am still having the same problem. I am happy to help you debug is there a way how to see some kind of logs?

tatsumoto-ren commented 3 years ago

xclip is not needed on macOS. Before we managed to figure out how to make it work with pbcopy. Try editing init_platform_nix() function, replacing the contents of clip variable with something that would work for you.

https://github.com/Ajatt-Tools/mpvacious/blob/master/subs2srs.lua#L668