Files
aiData/DouYin/delete_silent_videos.py
HuangHai f2f7a38210 'commit'
2026-01-20 19:06:36 +08:00

46 lines
1.4 KiB
Python

import os
import subprocess
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger("CleanupSilent")
def has_audio_stream(filepath):
try:
cmd = [
"ffprobe", "-v", "error",
"-show_entries", "stream=codec_type",
"-of", "default=noprint_wrappers=1:nokey=1",
filepath
]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
return "audio" in result.stdout
except Exception as e:
logger.error(f"Error checking {filepath}: {e}")
return False # Assume bad if error
def main():
directory = r"d:\dsWork\aiData\DouYin\DownloadedVideos"
files = [f for f in os.listdir(directory) if f.endswith(".mp4")]
count = 0
for filename in files:
filepath = os.path.join(directory, filename)
if not has_audio_stream(filepath):
logger.warning(f"[DELETE] No audio stream: {filename}")
try:
os.remove(filepath)
count += 1
except Exception as e:
logger.error(f"Failed to delete {filename}: {e}")
else:
# logger.info(f"[OK] {filename}")
pass
logger.info(f"Deleted {count} silent videos.")
if __name__ == "__main__":
main()