@@ -17,6 +17,7 @@ def get_duration(seconds):
1717
1818# Display video(s) duration for given directory
1919def display_video_duration (videos_list ):
20+ global all_video_durations
2021 for video_file in videos_list :
2122 video_file_path = dir_path + "/" + video_file
2223
@@ -28,14 +29,15 @@ def display_video_duration(videos_list):
2829
2930 # Contains the duration of the video in terms of seconds
3031 video_duration = int (video .duration ) # video length output is in seconds
32+ all_video_durations = all_video_durations + video_duration # adding all videos duration in seconds for total time.
3133 hours , minutes , seconds = get_duration (video_duration ) #convert into human readable duration format
3234
3335 print (f"{ video_file } : { hours } :{ minutes } :{ seconds } " )
3436 except AttributeError :
3537 pass
3638
3739if (len (sys .argv ) != 2 ):
38- exit ("It needs video file list to work" )
40+ exit ("It needs video directory path to work" )
3941
4042dir_path = ""
4143if (os .path .isdir (sys .argv [1 ])):
@@ -44,15 +46,15 @@ def display_video_duration(videos_list):
4446# list to store vodeo files
4547videos = []
4648
49+ # variable to store total duration
50+ all_video_durations = 0
51+
4752# Iterate directory
4853for path in os .listdir (dir_path ):
4954 # check if current path is a file
5055 if os .path .isfile (os .path .join (dir_path , path )):
5156 videos .append (path )
5257
5358display_video_duration (videos )
54-
55-
56- # If you want to check the given file is a video file
57- #if mimetypes.guess_type(path)[0].startswith('video'):
58- # print('It is a video')
59+ hours , minutes , seconds = get_duration (all_video_durations )
60+ print (f"Total Video duration under directory { dir_path } : { hours } :{ minutes } :{ seconds } " )
0 commit comments