File size: 1,171 Bytes
343eed9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys

file_path = r"c:\Users\lapet\github-all\darkmedia\.youtube\scripts\firefly_horror_bot.py"

try:
    with open(file_path, "r", encoding="utf-8") as f:
        text = f.read()

    # Attempt to reverse the double-encoding
    # If the text was UTF-8 interpreted as Latin-1 and saved as UTF-8:
    # We encode to Latin-1 to get the original UTF-8 bytes, then decode as UTF-8
    original_bytes = text.encode("latin-1")
    fixed_text = original_bytes.decode("utf-8")

    # If successful, save it back
    with open(file_path, "w", encoding="utf-8") as f:
        f.write(fixed_text)
    
    print("SUCCESS: File was double-encoded and has now been repaired.")

except Exception as e:
    print(f"FAILED to repair: {e}")
    # If latin-1 fails, maybe cp1252 with a fallback?
    try:
        original_bytes = text.encode("cp1252", errors="replace")
        fixed_text = original_bytes.decode("utf-8", errors="replace")
        with open(file_path, "w", encoding="utf-8") as f:
            f.write(fixed_text)
        print("SUCCESS (with replace): File was repaired using cp1252 fallback.")
    except Exception as e2:
        print(f"Completely failed: {e2}")