Advice for copy/move file extension

Discuss your Lua playlist, album art and interface scripts.
Joeri
New Cone
New Cone
Posts: 3
Joined: 05 Nov 2019 19:17

Advice for copy/move file extension

Postby Joeri » 09 Nov 2019 18:38

I'm trying to make a vlc lua extension that can delete, move or copy the current played file. Now I'm somewhat stuck and was wondering if someone can give advice.

I have developed the delete using vlc.io.unlink. For the copy I use vlc.io.open with option wb and write the file. This works all very well.

However there are some downsides.
1. vlc.io.unlink doesn't use the recycle bin.
2. When copying a file using vlc.io.open, the created and modified timestamps are new.
3. When moving a file, a copy + delete of original works, but takes for larger files more time than a 'real move' in Windows Explorer when moved on the same disk.

Now for the solutions for these (on Windows only) I have:
1. I can live with that.
2. Using os.execute and xcopy Windows commands.
3. Using os.execute and move Windows command. Here some convoluted logic is needed to make it work for filenames with special characters, but it is possible.

However now I face another problem. Apparently, vlc crashes when os.execute takes more than about 5 seconds. For copying larger files, this problem can occur. Now I have following solutions:

i) I can start a new command prompt in os.execute or use io.popen instead so the call returns immediately. This solves the problem. But a new problem arises: I need to wait for the result of the copy to know if it is successful. Now I can
* When using io.popen, I can read the output. But this has the same problem that vlc crashes if the copy takes more than about 5 seconds.
* Output the result of the copy to a temporary file. However then I need a polling mechanism to wait for the temporary file (result). With vlc lua extensions, this seems only possible using a busy-wait or opening command prompts with e.g. a ping that takes one second until the copy is finished. These solutions are not very good.

ii) Another solution is maybe trying robocopy instead of xcopy. I didn't do this yet, but I think because robocopy outputs a progress during the copying, if I use io.popen and then in some way read the progress while it happens, this should maybe not be vulnerable to the vlc crash problem and avoid the busy-wait problem. The problem however is that robocopy has no possibility to rename the copied file. Since I also want to be able to automatically rename the copied file in case the file already exists, I cannot use robocopy. Xcopy can rename a copied file, but doesn't report a progress during the copy. I could use robocopy to copy it to some temporary subfolder first, and than use 'rename' and 'move' Windows commands to move it to the correct directory, which should be fast enough to not cause the crash problem. But that solution seems extremely convoluted, and I'm not sure at this point if using robocopy is actually a solution.

So I'm wondering
1. Is there anyone who knows a non-convoluted solution to counter the mentioned problems on top? Best involving not using os.execute or io.popen I think. Or if not possible to avoid this, a good solution to avoid a busy-wait during the copy.
2. Is it a bug that vlc crashes on os.execute or some other call (like file:read('*all') where file is a handle from io.popen) if this takes more than 5 seconds?

Joeri
New Cone
New Cone
Posts: 3
Joined: 05 Nov 2019 19:17

Re: Advice for copy/move file extension

Postby Joeri » 09 Nov 2019 22:24

I looked a bit futher into this.

1. Actually vlc (I use version 3.0.8 on Windows 10 Home 1903) hangs when the extension is busy with some function for 10 seconds, not 5 seconds. A popup appears 'Extension not responding! - Extension 'FileManagement' does not respond. Do you want to kill it now?'. You have only a 'Yes' button. I figured out that from now on, if the extension tries to do something (e.g. user clicks a button in the dialog or a listener function is executed), vlc becomes unresponsive. It doesn't matter if you have clicked 'Yes' or not in the popup. I think it can be a vlc feature request to find a solution for this 'crash'?

2. It is actually no solution to execute another cmd and do a busy-wait. In this case also after 10 seconds, the popup appears. Seems logic since the problem is not in os.execute, but in the fact that the extension must be ready doing it's stuff 10 seconds after the event is triggered. It could be a solution if I don't wait anymore for the copy result, but than I can't report in the extension if the copy was successful or not.

3. Using the method with vlc.io.open in wb mode and writing the file is even worse: Also in this case, if the copy takes more than 10 seconds, after 10 seconds, the popup about extension not responding appears. And in this case, the copy is done with the build in method, so the solution to not wait for the response doesn't exist for this case.

So my conclusion is it is impossible to make this work properly like I initially wanted. The best way to make it work (in Windows) seems to execute the commands with os.execute and not waiting for return, unless someone has a better solution? Possibility to implement a timer that executes every ... seconds would be handy for this case, but I read somewhere in another topic that this kind of functionality was removed in the past. I can tweak it a little so it shows the result the next time a listener is triggered or a button is pressed, or foresee a button to check for the result.

Joeri
New Cone
New Cone
Posts: 3
Joined: 05 Nov 2019 19:17

Re: Advice for copy/move file extension

Postby Joeri » 11 Nov 2019 21:21

If someone is interested, I have made a first version taking the findings above into account.

https://bitbucket.org/joeriverscheure/vlclua/get/FileManagement_1.0.0.zip


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 36 guests