45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
# Folders
|
|
source_folder = "audio_files"
|
|
destination_folder = "music_prolly"
|
|
|
|
# Ensure destination folder exists
|
|
os.makedirs(destination_folder, exist_ok=True)
|
|
|
|
def get_audio_duration(file_path):
|
|
"""Returns duration of audio file in seconds using ffprobe."""
|
|
try:
|
|
result = subprocess.run(
|
|
[
|
|
"ffprobe",
|
|
"-v", "error",
|
|
"-show_entries", "format=duration",
|
|
"-of", "default=noprint_wrappers=1:nokey=1",
|
|
file_path
|
|
],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT
|
|
)
|
|
return float(result.stdout)
|
|
except Exception as e:
|
|
print(f"Error reading duration for '{file_path}': {e}")
|
|
return 0
|
|
|
|
# Process files
|
|
for filename in os.listdir(source_folder):
|
|
file_path = os.path.join(source_folder, filename)
|
|
|
|
if not os.path.isfile(file_path):
|
|
continue
|
|
|
|
duration = get_audio_duration(file_path)
|
|
|
|
if duration > 30:
|
|
shutil.move(file_path, os.path.join(destination_folder, filename))
|
|
print(f"Moved '{filename}' ({duration:.2f}s) → '{destination_folder}'")
|
|
else:
|
|
print(f"Kept '{filename}' ({duration:.2f}s)")
|