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

Needs randomization in the output filename to avoid replacing #10

Open
masterofobzene opened this issue Dec 6, 2023 · 5 comments
Open

Comments

@masterofobzene
Copy link

masterofobzene commented Dec 6, 2023

The script needs randomization numbers in its filename so we can make many clips without replacing the same file over and over.

I would like to contribute but I don't understand lua

Ideas:

  • Using clip timestamps as "unique" numbers
  • Using increasing numbers
  • Using a random numbers generator, 4 digits would be ok.
@masterofobzene
Copy link
Author

I've patched for my use; but maybe you can implement this better.

local output_name = ""
    if string.len(settings.custom_output_path) > 0 then
	    output_name = string.format("%s\\%s %s cut.%s", settings.custom_output_path, math.random(1,9999), vars.only_filename:gsub("%" .. string.format(".%s", settings.video_extension), ""), settings.video_extension)

@b1scoito
Copy link
Owner

b1scoito commented Dec 7, 2023

Instead of implementing random, we can keep a variable to append a growing number on each cut. Could you PR those changes?

@masterofobzene
Copy link
Author

masterofobzene commented Dec 7, 2023

Sorry but no, I can't do that change since I don't know how to code in lua properly, this was just a workaround for me after hours of searching.

Bear in mind that if you choose to use incremental numbers, once you close the player (script) it will restart said number list, so there is a risk of replacing old clips if the user is not aware (and tries to make more clips of the same movie file, with same name). More code would have to be put in place to mitigate this, by using some kind of "memory" (a file or something) that can keep track of the last number used and restart from there. That is why I chose random numbers instead.

I say thanks to you, since this is THE ONLY script I found working on windows platform, all the others are unix based and they just don't work on windows.

@b1scoito
Copy link
Owner

b1scoito commented Dec 19, 2023

I'll take a look at it later. I'm now using Linux so I'll have to test on every platform.

@masterofobzene
Copy link
Author

masterofobzene commented Dec 19, 2023

Hi there again, I made a modification to my modification. It seems using that randomizer command, its VERY likely to get the same numbers over and over again (not very good at randomizing). So after a couple of hours, I found a workaround by using os.time() instead of math.random(1,9999)

local output_name = ""
    if string.len(settings.custom_output_path) > 0 then
	    output_name = string.format("%s\\%s %s cut.%s", settings.custom_output_path, os.time(), vars.only_filename:gsub("%" .. string.format(".%s", settings.video_extension), ""), settings.video_extension)
-- Resize video
    if is_web then
	    local output_name_resized = ""
	    if string.len(settings.custom_output_path) > 0 then 
		    output_name_resized = string.format("%s\\%s %s cutr.%s", settings.custom_output_path, os.time(), vars.only_filename:gsub("%" .. string.format(".%s", settings.video_extension), ""), settings.video_extension)
	    else 
		    output_name_resized = string.format("%s %s cutr.%s", os.time(), vars.only_filename:gsub("%" .. string.format(".%s", settings.video_extension), ""), settings.video_extension)
	    end

Results in filenames like: "1703019293 somethingsomething cut.mp4"
Where 1703019293 is the time in epoch as far as I understand. This way, you will not overwrite any files since the time will always be different.

[edit: removed offtopic]

regards

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

No branches or pull requests

2 participants