Spaces:
Sleeping
Sleeping
File size: 1,286 Bytes
a58ab35 2ae1a70 a58ab35 2ae1a70 a58ab35 2ae1a70 a58ab35 d57239f a58ab35 d57239f a58ab35 d57239f a58ab35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# utils.py
import os
import logging
import requests
# Basic logger setup
logger = logging.getLogger("audio_splitter")
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter("[%(levelname)s] %(message)s"))
logger.addHandler(ch)
def create_directories(path):
os.makedirs(path, exist_ok=True)
def remove_directory_contents(path):
if not os.path.exists(path):
return
for filename in os.listdir(path):
file_path = os.path.join(path, filename)
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.isdir(file_path):
import shutil
shutil.rmtree(file_path)
def download_manager(url, output_dir):
filename = os.path.basename(url)
output_path = os.path.join(output_dir, filename)
if os.path.exists(output_path):
return output_path
logger.info(f"Downloading: {filename}")
os.makedirs(os.path.dirname(output_path), exist_ok=True) # Ensure directory exists
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(output_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
logger.info(f"Downloaded: {filename}")
return output_path
|