1
+ import zipfile
1
2
import requests
2
3
import os
3
4
import subprocess
4
5
5
6
6
7
def ffmpeg_install_windows ():
7
8
try :
8
- zip = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
9
- r = requests .get (zip )
10
- with open ("ffmpeg.zip" , "wb" ) as f :
9
+ ffmpeg_url = "https://github.com/GyanD/codexffmpeg/releases/download/6.0/ffmpeg-6.0-full_build.zip"
10
+ ffmpeg_zip_filename = "ffmpeg.zip"
11
+ ffmpeg_extracted_folder = "ffmpeg"
12
+
13
+ # Check if ffmpeg.zip already exists
14
+ if os .path .exists (ffmpeg_zip_filename ):
15
+ os .remove (ffmpeg_zip_filename )
16
+
17
+ # Download FFmpeg
18
+ r = requests .get (ffmpeg_url )
19
+ with open (ffmpeg_zip_filename , "wb" ) as f :
11
20
f .write (r .content )
12
- import zipfile
13
21
14
- with zipfile .ZipFile ("ffmpeg.zip" , "r" ) as zip_ref :
22
+ # Check if the extracted folder already exists
23
+ if os .path .exists (ffmpeg_extracted_folder ):
24
+ # Remove existing extracted folder and its contents
25
+ for root , dirs , files in os .walk (ffmpeg_extracted_folder , topdown = False ):
26
+ for file in files :
27
+ os .remove (os .path .join (root , file ))
28
+ for dir in dirs :
29
+ os .rmdir (os .path .join (root , dir ))
30
+ os .rmdir (ffmpeg_extracted_folder )
31
+
32
+ # Extract FFmpeg
33
+ with zipfile .ZipFile (ffmpeg_zip_filename , "r" ) as zip_ref :
15
34
zip_ref .extractall ()
16
35
os .remove ("ffmpeg.zip" )
17
- os .rename ("ffmpeg-master-latest-win64-gpl" , "ffmpeg" )
18
- # Move the files inside bin to the root
19
- for file in os .listdir ("ffmpeg/bin" ):
20
- os .rename (f"ffmpeg/bin/{ file } " , f"./{ file } " )
21
- os .rmdir ("ffmpeg/bin" )
22
- for file in os .listdir ("ffmpeg/doc" ):
23
- os .remove (f"ffmpeg/doc/{ file } " )
24
- os .rmdir ("ffmpeg/doc" )
25
- os .remove ("ffmpeg/LICENSE.txt" )
26
- os .rmdir ("ffmpeg/" )
27
36
28
- print (
29
- "FFmpeg installed successfully! Please restart your computer and then re-run the program."
30
- )
37
+ # Rename and move files
38
+ os .rename (f"{ ffmpeg_extracted_folder } -6.0-full_build" , ffmpeg_extracted_folder )
39
+ for file in os .listdir (os .path .join (ffmpeg_extracted_folder , "bin" )):
40
+ os .rename (os .path .join (ffmpeg_extracted_folder , "bin" , file ), os .path .join ("." , file ))
41
+ os .rmdir (os .path .join (ffmpeg_extracted_folder , "bin" ))
42
+ for file in os .listdir (os .path .join (ffmpeg_extracted_folder , "doc" )):
43
+ os .remove (os .path .join (ffmpeg_extracted_folder , "doc" , file ))
44
+ for file in os .listdir (os .path .join (ffmpeg_extracted_folder , "presets" )):
45
+ os .remove (os .path .join (ffmpeg_extracted_folder , "presets" , file ))
46
+ os .rmdir (os .path .join (ffmpeg_extracted_folder , "presets" ))
47
+ os .rmdir (os .path .join (ffmpeg_extracted_folder , "doc" ))
48
+ os .remove (os .path .join (ffmpeg_extracted_folder , "LICENSE" ))
49
+ os .remove (os .path .join (ffmpeg_extracted_folder , "README.txt" ))
50
+ os .rmdir (ffmpeg_extracted_folder )
31
51
52
+ print ("FFmpeg installed successfully! Please restart your computer and then re-run the program." )
32
53
except Exception as e :
33
54
print (
34
55
"An error occurred while trying to install FFmpeg. Please try again. Otherwise, please install FFmpeg manually and try again."
@@ -75,16 +96,12 @@ def ffmpeg_install_mac():
75
96
def ffmpeg_install ():
76
97
try :
77
98
# Try to run the FFmpeg command
78
- subprocess .run (
79
- ["ffmpeg" , "-version" ], check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE
80
- )
99
+ subprocess .run (['ffmpeg' , '-version' ], check = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
81
100
except FileNotFoundError as e :
82
101
# Check if there's ffmpeg.exe in the current directory
83
102
if os .path .exists ("./ffmpeg.exe" ):
84
- print (
85
- "FFmpeg is installed on this system! If you are seeing this error for the second time, restart your computer."
86
- )
87
- print ("FFmpeg is not installed on this system." )
103
+ print ('FFmpeg is installed on this system! If you are seeing this error for the second time, restart your computer.' )
104
+ print ('FFmpeg is not installed on this system.' )
88
105
resp = input (
89
106
"We can try to automatically install it for you. Would you like to do that? (y/n): "
90
107
)
@@ -97,7 +114,9 @@ def ffmpeg_install():
97
114
elif os .name == "mac" :
98
115
ffmpeg_install_mac ()
99
116
else :
100
- print ("Your OS is not supported. Please install FFmpeg manually and try again." )
117
+ print (
118
+ "Your OS is not supported. Please install FFmpeg manually and try again."
119
+ )
101
120
exit ()
102
121
else :
103
122
print ("Please install FFmpeg manually and try again." )
0 commit comments