From fcf6ef93e520cb5250e4ec66a44ea8053ad2bce9 Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 26 May 2023 17:16:53 -0300 Subject: [PATCH] Fix #1649 randrange bug --- video_creation/background.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/video_creation/background.py b/video_creation/background.py index 010f15e..7cfdf81 100644 --- a/video_creation/background.py +++ b/video_creation/background.py @@ -47,7 +47,14 @@ def get_start_and_end_times(video_length: int, length_of_clip: int) -> Tuple[int Returns: tuple[int,int]: Start and end time of the randomized interval """ - random_time = randrange(180, int(length_of_clip) - int(video_length)) + initialValue = 180 + # Issue #1649 - Ensures that will be a valid interval in the video + while(int(length_of_clip) <= int(video_length+initialValue)): + if(initialValue == initialValue //2): + raise Exception("Your background is too short for this video length") + else: + initialValue //= 2 #Divides the initial value by 2 until reach 0 + random_time = randrange(initialValue, int(length_of_clip) - int(video_length)) return random_time, random_time + video_length @@ -157,4 +164,4 @@ def chop_background( return background_config["video"][2] # Create a tuple for downloads background (background_audio_options, background_video_options) -background_options = load_background_options() \ No newline at end of file +background_options = load_background_options()