File size: 2,761 Bytes
32a9fa4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import subprocess
import struct
import json
import os
import sys

def test_postprocessor_resilience():
    script_dir = os.path.dirname(os.path.abspath(__file__))
    project_dir = os.path.dirname(script_dir)
    host_py = os.path.join(project_dir, "host", "download_host.py")
    
    # We pass a test URL
    payload = {
        "command": "download",
        "url": "https://es.pornhub.com/view_video.php?viewkey=68ebf3648ffdd",
        "savePath": os.path.join(os.path.expanduser("~"), "Downloads"),
        "title": "TestPornhubThumb",
        "formatSetting": "mp4",
        "qualitySetting": "min", # min quality for quick test
        "engineSetting": "ytdlp",
        "threadCount": 4,
        "audioFormat": "best",
        "audioQuality": "0",
        "audioConvert": "none",
        "videoFormatPref": "legado",
        "isAutoTitle": False
    }
    
    encoded_msg = json.dumps(payload).encode('utf-8')
    length_prefix = struct.pack('@I', len(encoded_msg))
    
    print("Enviando petición de descarga con incrustación de miniatura...")
    process = subprocess.Popen(
        [sys.executable, host_py],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        bufsize=0
    )
    
    process.stdin.write(length_prefix)
    process.stdin.write(encoded_msg)
    process.stdin.flush()
    
    status = "started"
    final_file = ""
    logs = []
    
    try:
        while True:
            raw_length = process.stdout.read(4)
            if not raw_length or len(raw_length) < 4:
                break
            msg_length = struct.unpack('@I', raw_length)[0]
            msg_data = process.stdout.read(msg_length).decode('utf-8')
            msg = json.loads(msg_data)
            
            st = msg.get("status")
            if st == "log":
                logs.append(msg.get("log"))
                print(f"[LOG] {msg.get('log')}")
            elif st == "completed":
                status = "completed"
                final_file = msg.get("final_file")
                print(f"[COMPLETED] Archivo final: {final_file}")
                break
            elif st == "error":
                status = "error"
                print(f"[ERROR] {msg.get('error')}")
                break
    except Exception as e:
        status = "exception"
        print(f"[EXCEPTION] {e}")
    finally:
        process.terminate()
        
    print(f"\nResultado final del Test: Estado={status}, Archivo={final_file}")
    if final_file and os.path.exists(final_file):
        print(f"ÉXITO CONFIRMADO: El video existe en el disco ({os.path.getsize(final_file)} bytes).")
    else:
        print("FALLO: El video no fue conservado.")

if __name__ == "__main__":
    test_postprocessor_resilience()