Jun-30-2023, 09:47 AM
hi. first of all I have to tell you that I'm a noob.
I'm trying to extract a zip file that gets downloaded and I get error
I double checked but I can't find the mistake
PS: how do I check if ffmpeg already exists and only run it after the first time when it's been updated. should use a checksum check?
I'm trying to extract a zip file that gets downloaded and I get error
I double checked but I can't find the mistake
PS: how do I check if ffmpeg already exists and only run it after the first time when it's been updated. should use a checksum check?
import os import requests import zipfile import io import subprocess # Function to install the 'requests' module def install_requests(): try: # Check if 'requests' is already installed import requests print("requests module is already installed.") except ImportError: # 'requests' is not installed, so install it subprocess.check_call(["pip", "install", "requests"]) print("requests module installed successfully.") # Function to download the latest version of FFmpeg def download_ffmpeg(): # Fetch the latest FFmpeg release URL url = "https://github.com/BtbN/FFmpeg-Builds/releases/latest" response = requests.get(url) response.raise_for_status() # Extract the download URL from the response download_url = response.url + "/ffmpeg-*-essentials_build.zip" # Download the FFmpeg archive archive_response = requests.get(download_url) archive_response.raise_for_status() # Extract the downloaded archive archive = zipfile.ZipFile(io.BytesIO(archive_response.content)) archive.extractall() # Find the extracted FFmpeg folder ffmpeg_folder = [folder for folder in archive.namelist() if folder.startswith("ffmpeg-")][0] # Return the path to the FFmpeg folder return os.path.abspath(ffmpeg_folder) # Function to add FFmpeg to the PATH environment variable def add_ffmpeg_to_path(ffmpeg_path): # Get the current PATH environment variable value current_path = os.environ.get("PATH", "") # Add the FFmpeg path to the current PATH updated_path = current_path + os.pathsep + ffmpeg_path # Set the updated PATH environment variable for the current session os.environ["PATH"] = updated_path # Set the updated PATH environment variable permanently subprocess.call(["setx", "PATH", updated_path]) # Install 'requests' module install_requests() # Download FFmpeg ffmpeg_path = download_ffmpeg() # Add FFmpeg to the PATH add_ffmpeg_to_path(ffmpeg_path) # Print the path to FFmpeg print("FFmpeg path:", ffmpeg_path)