Last active
October 26, 2025 11:27
-
-
Save michivonah/ab033b1195aaba493d55235814beeafb to your computer and use it in GitHub Desktop.
Find corrupt files which were exported from snapchat memories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| import json | |
| import shutil | |
| from datetime import datetime | |
| from zoneinfo import ZoneInfo # Python 3.9+ | |
| # === Konfiguration === | |
| input_dir = r"./downloads-with-captions" # Ordner mit defekten Dateien | |
| fixed_dir = r"./downloads-no-captions" # Ordner mit funktionierenden Dateien (UTC) | |
| output_dir = r"./downloads-with-captions" # Zielordner für kopierte Dateien | |
| json_path = os.path.join(input_dir, "corrupt-files.json") | |
| corrupt_files = [] | |
| # === Schritt 1: Defekte Dateien erkennen === | |
| for root, _, files in os.walk(input_dir): | |
| for file in files: | |
| if file.lower().endswith(".mp4"): | |
| path = os.path.join(root, file) | |
| try: | |
| result = subprocess.run( | |
| ['ffprobe', '-v', 'error', | |
| '-select_streams', 'v', | |
| '-show_entries', 'stream=codec_type', | |
| '-of', 'csv=p=0', path], | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True | |
| ) | |
| if 'video' not in result.stdout: | |
| corrupt_files.append(path) | |
| print(f"Potential corrupt file: {path}") | |
| except Exception as e: | |
| print(f"Error while testing file {path}: {e}") | |
| # === Schritt 2: Defekte Dateien in JSON speichern === | |
| with open(json_path, 'w', encoding='utf-8') as f: | |
| json.dump(corrupt_files, f, indent=4, ensure_ascii=False) | |
| print(f"\n✅ Corrupt files saved to {json_path}") | |
| # === Schritt 3: Funktionierende Dateien kopieren mit Zeitzonenanpassung === | |
| os.makedirs(output_dir, exist_ok=True) | |
| for corrupt_path in corrupt_files: | |
| filename = os.path.basename(corrupt_path) | |
| name_part, ext = os.path.splitext(filename) | |
| try: | |
| # Datum aus Europe/Zurich-Dateiname parsen | |
| dt_zh = datetime.strptime(name_part, "%Y-%m-%d_%H-%M-%S").replace(tzinfo=ZoneInfo("Europe/Zurich")) | |
| # In UTC konvertieren (so heißt die Datei im fixed_dir) | |
| dt_utc = dt_zh.astimezone(ZoneInfo("UTC")) | |
| fixed_filename = dt_utc.strftime("%Y-%m-%d_%H-%M-%S") + ext | |
| fixed_file_path = os.path.join(fixed_dir, fixed_filename) | |
| if not os.path.exists(fixed_file_path): | |
| print(f"⚠️ Fixed file not found for {filename} → looked for {fixed_filename}") | |
| continue | |
| # Kopieren unter Originalnamen (Europe/Zurich) | |
| dst_path = os.path.join(output_dir, filename) | |
| shutil.copy2(fixed_file_path, dst_path) | |
| print(f"✅ Copied {fixed_file_path} → {dst_path}") | |
| except Exception as e: | |
| print(f"⚠️ Error processing {filename}: {e}") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script made with ChatGPT