'commit'
This commit is contained in:
45
DouYin/delete_silent_videos.py
Normal file
45
DouYin/delete_silent_videos.py
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user