sudo apt update && sudo apt install jq



//pour audio la meilleur qualité
yt-dlp -J "https://www.youtube.com/watch?v=udjFBEM85to" | jq '
.formats
| map(select(.vcodec=="none" and .acodec!="none"))
| max_by(.abr // 0)
| {id: .format_id, ext, abr, codec: .acodec,
   size_mb: ((.filesize // .filesize_approx // 0)/1024/1024|floor)}'



///pour le vidéo pour chaque format la meilleur qualité
yt-dlp -J "https://www.youtube.com/watch?v=udjFBEM85to" | jq '
.formats
| map(select(.acodec=="none" and .vcodec!="none"))
| group_by(.height)
| map(max_by((.tbr // 0), (.filesize // .filesize_approx // 0)))
| sort_by(.height)
| map({
    id: .format_id,
    ext,
    resolution,
    fps,
    vcodec,
    size_mb: ((.filesize // .filesize_approx // 0)/1024/1024|floor)
  })
'


yt-dlp -f 137+140 URL

//la taille en Mo
echo $(($(yt-dlp --print "%(filesize,filesize_approx)s" "https://www.youtube.com/watch?v=r8gPG3JrNhw") / 1024 / 1024))


yt-dlp --newline "https://www.4s.io/video/k2gW_G5Yku/amira_w_dofda3.html"




<?php

$url = $_POST['url'];

$cmd = "yt-dlp --newline " . escapeshellarg($url) . " 2>&1";
$handle = popen($cmd, "r");

$socket = fsockopen("127.0.0.1", 8080);

function ws_send($socket, $msg) {
    fwrite($socket, $msg . "\n");
}

while (!feof($handle)) {
    $line = fgets($handle);

    if (preg_match('/(\d+\.?\d*)%/', $line, $m)) {
        $data = json_encode([
            "progress" => (float)$m[1],
            "line" => trim($line)
        ]);

        ws_send($socket, $data);
    }
}

pclose($handle);

ws_send($socket, json_encode([
    "progress" => 100,
    "status" => "done"
]));

fclose($socket);