Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
zipfile module error
#1
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?

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)
Reply


Messages In This Thread
zipfile module error - by pseudo - Jun-30-2023, 09:47 AM
RE: zipfile module error - by ibreeden - Jun-30-2023, 09:56 AM
RE: zipfile module error - by pseudo - Jun-30-2023, 11:11 AM
RE: zipfile module error - by Gribouillis - Jun-30-2023, 03:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using zipfile module - finding folders not files darter1010 2 428 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  [Solved by deanhystad] Create a zip file using zipfile library DZ_Galaxy 2 1,274 Aug-17-2022, 04:57 PM
Last Post: DZ_Galaxy
  Can ZipFile be used to extract hidden files? AiedailEclipsed 0 1,710 Mar-22-2022, 05:21 PM
Last Post: AiedailEclipsed
  Created zipfile without all the subfolder? korenron 3 3,969 Jun-23-2021, 12:44 PM
Last Post: korenron
  Create ZIP file not working using ZipFile? korenron 1 2,188 Jun-13-2021, 04:15 PM
Last Post: korenron
  zipfile sagpal 2 2,308 Jun-03-2020, 08:35 PM
Last Post: sagpal
  vlc module error pythonprogrammer 1 2,946 Apr-23-2020, 04:16 AM
Last Post: Larz60+
  zip file variable prints <zipfile.ZipFile object at 0x7f83fd13bd90> ? Rsh 9 4,336 Jun-27-2019, 02:00 PM
Last Post: Rsh
  python zipfile.ZipFile makes zip file but can't add folders to them CashMunny 3 3,759 May-09-2018, 10:28 PM
Last Post: CashMunny
  pyhton error there is no PIL module error help! pokeboss235 1 2,998 Feb-22-2018, 03:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020