Eisa01 / mpv-scripts

This repository contain scripts I have made for mpv media player...
BSD 2-Clause "Simplified" License
517 stars 35 forks source link

SmartCopyPaste Compatibility with MacOS X #1

Closed gbstan closed 4 years ago

gbstan commented 5 years ago

Good script. Would be really cool to get SmartCopyPaste to also work on MacOS X. Access to the clipboard on MacOS X from the command line can be done with pbcopy and pbpaste. This should allow you to adapt your script for MacOS X too.

gbstan commented 5 years ago

Here are some links that might help for this: https://github.com/mpv-player/mpv/issues/4653#issuecomment-317411382 https://github.com/rossy/mpv-repl/blob/master/repl.lua#L507-L546

Eisa01 commented 5 years ago

@gbstan Thanks for sharing the links. It sure is helpful.

However, currently I do not own mac to test adding compatibility.

Perhaps in future.

Eisa01 commented 4 years ago

@gbstan I have added initial compatibility for supporting multiple platforms in SmartCopyPaste 1.9. MAC OS X requires pbpaste, Linux requires xclip

Currently only pasting should work in MAC OS X and Linux, copying for both platforms is still not supported. Once I support copying I will notify you ^ ^

I have attached the script, please do let me know if pasting works so I add it as an offical release. SmartCopyPaste-1.9.lua.zip

Side note: SmartCopyPaste-II wont feature multiple platforms until I find a method for the way I am creating logfiles (will probably take ages due to my lazyness and the fact that I dont have MAC OS X).

gbstan commented 4 years ago

Thank you! On MacOS and Linux, I would use/create the log files within ~/.config/mpv (i.e. one directory above where the script itself is stored). This is also where history.log for mpv is located. I guess the content and writing of information in the file mpvClipboard.log is the same for all platforms.

Eisa01 commented 4 years ago

You are welcome!

Guess it means it worked for you, however for mpvClipboard.log, (the II version), I'll see what can be done in the future.

When I have free time I'll first focus in enhancing the initial support and getting the copy feature to work.

Issue is closed since initial support is done.

gbstan commented 4 years ago

Unfortunately the paste (ctrl+v) didn't work. Here is the error message

[SmartCopyPaste_1_9] 
[SmartCopyPaste_1_9] stack traceback:
[SmartCopyPaste_1_9]    ...-bartstan/.config/mpv/scripts/SmartCopyPaste-1.9.lua:30: in function <...-bartstan/.config/mpv/scripts/SmartCopyPaste-1.9.lua:25>
[SmartCopyPaste_1_9]    (tail call): ?
[SmartCopyPaste_1_9]    ...-bartstan/.config/mpv/scripts/SmartCopyPaste-1.9.lua:159: in function 'fn'
[SmartCopyPaste_1_9]    mp.defaults:202: in function 'fn'
[SmartCopyPaste_1_9]    mp.defaults:60: in function 'handler'
[SmartCopyPaste_1_9]    mp.defaults:339: in function 'handler'
[SmartCopyPaste_1_9]    mp.defaults:460: in function 'call_event_handlers'
[SmartCopyPaste_1_9]    mp.defaults:494: in function 'dispatch_events'
[SmartCopyPaste_1_9]    mp.defaults:453: in function <mp.defaults:452>
[SmartCopyPaste_1_9]    [C]: ?
[SmartCopyPaste_1_9]    [C]: ?
[SmartCopyPaste_1_9] Lua error: ...-bartstan/.config/mpv/scripts/SmartCopyPaste-1.9.lua:30: attempt to call global 'paste' (a nil value)
Eisa01 commented 4 years ago

Hmm, can you try this SmartCopyPaste-1.91.lua.zip

If it did not work, try typing 'macos' instead of nil inside the script and let me know. so it will be local platform = 'macos'

gbstan commented 4 years ago

Just tried it. It seems the script identifies linux instead of macOS when I press ctrl+v

[SmartCopyPaste_1_91] There was an error getting linux clipboard:  
[SmartCopyPaste_1_91]   Status: -1 
[SmartCopyPaste_1_91]   Error: init 
[SmartCopyPaste_1_91]   stdout:  
[SmartCopyPaste_1_91] args: {"xclip", "-selection", "primary", "-out"} 
AV: 00:00:05 / 00:01:11 (7%) A-V:  0.000 Dropped: 4
[SmartCopyPaste_1_91] There was an error getting linux clipboard:  
[SmartCopyPaste_1_91]   Status: -1 
[SmartCopyPaste_1_91]   Error: init 
[SmartCopyPaste_1_91]   stdout:  
[SmartCopyPaste_1_91] args: {"xclip", "-selection", "primary", "-out"} 
Eisa01 commented 4 years ago

Seems that the detect platform I forked is not working properly, you can manually select the platform. Open the script with any text editor, replace local platform = nil With local platform = 'macos'

Let me know what happens

gbstan commented 4 years ago

Yes, this works if I press ctrl+v (tried with a youtube URL) and then Enter. It does not work without pressing Enter after ctrl+v

Eisa01 commented 4 years ago

Are you pasting in mpv gui or the terminal? Can you provide me with a screenshot so I see what is happening?

gbstan commented 4 years ago

It actually works without pressing enter. It just takes ~2 seconds to start playing the video, which I probably didn't realise until now.

Eisa01 commented 4 years ago

Glad to see it finally working.

I still don't understand the cause for the delay, this could have to do with pbpaste. Or sometimes scripts just don't function properly and experience slow-downs for some reason.

The delay might get fixed by itself. However, I'll try to enhance the cross-platform support further in the near future.

gbstan commented 4 years ago

Might be due to the time it takes to load the video from youtube? I have not tried yet with a local link.

Eisa01 commented 4 years ago

Does the message of pasting show quickly? YouTube generally will have delay because it needs to find the actual video link from the pasted YouTube URL

gbstan commented 4 years ago

Yes, the message of pasting is immediate.

Eisa01 commented 4 years ago

Seems like initial support is done, will close the issue for now and improve the support gradually.

Eisa01 commented 4 years ago

@gbstan I have made an update, it should automatically know you are using MAC OS X. Also, it should be able to copy now and paste.

Let me know if the above works for you without problems :) https://github.com/Eisa01/mpv-scripts/blob/master/scripts/SmartCopyPaste-1.93.lua

If things work, I think I might proceed and support my other scripts to work for MAC OS X and Linux.

gbstan commented 4 years ago

Yes, this seems to work now.

Eisa01 commented 4 years ago

Thanks for testing. I have updated all of my scripts. All scripts now support MAC OS and Linux.

You can use now SmartHistory and SmartCopyPaste-II also.

gbstan commented 4 years ago

Thank you so much! Very appreciated and very useful scripts

noctuid commented 4 years ago

@Eisa01 I'm on linux, but the auto-detection thinks I'm on osx. os.execute returns a number (the exit code) not nil or true for whatever version of lua mpv uses, so the osx check always succeeds even though I don't have either of those directories. Is this not the case for you?

Eisa01 commented 4 years ago

@noctuid Can you let me know which flavor of linux you are using so I check?

noctuid commented 4 years ago

Arch, but I don't think it should matter. Does os.execute behave differently for you?

Eisa01 commented 4 years ago

@noctuid Tested on Ubuntu the check for directory fails and it successfully detects Linux. I will need to see what ur returns in order to handle the detection issue.

noctuid commented 4 years ago

In Ubuntu, if you run luajit and then print(os.execute("false")) do you get nil? I get a number. Lua 5.3 returns nil, but only 5.1 and 5.2 are supported by mpv.

noctuid commented 4 years ago

Okay, it looks like this is actually a difference between 5.1 and 5.2. 5.1 returns a non-zero number and 5.2 returns nil on failure. Could you make the check to see if the result is 0 or true instead of whether the result is truthy?

Eisa01 commented 4 years ago

@noctuid I have made the check as you have mentioned above, so that it checks for 0 and true. Can you test and let me know if this fixed auto detection for you? SmartCopyPaste-II-2.1#2.txt Rename it to .lua

@gbstan I have also made it so the MAC uses command button instead of ctrl,I just found out that everything there uses command instead of ctrl for some reason.

noctuid commented 4 years ago

That works, but I think it should be something like (unsimplified) os.execute '[ -d "/Applications" ]' == 0 and os.execute '[ -d "/Library" ]' == 0 or os.execute '[ -d "/Applications" ]' == true and os.execute '[ -d "/Library" ]' == true otherwise the check for /Applications doesn't have any effect on lua 5.1.

Eisa01 commented 4 years ago

@noctuid Thanks, it makes sense. Will modify it as you have mentioned and will release it tomorrow in 2.1. ^ ^