[HELP] Download video từ m3u8 bị chặn

Discussion in 'Hỏi Đáp Kỹ Thuật' started by dev9x, Dec 29, 2020.

  1. sincos

    sincos Bang Chúng

    Không có chuyện đó đâu.... do có cơ duyên làm việc liên quan đến việc này và phải lăn lộn với nó nên biết thôi.
     
    huvo6789 and dev9x like this.
  2. dev9x

    dev9x Sơ Nhập Giang Hồ

    theo bác @sincos nói thì là do server nó chậm rồi :D
     
  3. sincos

    sincos Bang Chúng

    Dịch vụ streaming này dùng 2 source. Đầu tiên nó dùng source từ google nếu bị lỗi (do request quá nhiều bị google block) thì player sẽ load từ nguồn dự phòng (server streaming tự build) mà server này đã config bóp băng thông hoặc server cùi hoặc bị quá tải.
     
  4. dev9x

    dev9x Sơ Nhập Giang Hồ

    xin phép đc đào top, mình đang cần download link từ ok.ru, mình đã get đc link nhưng tốc độ download rất chậm 100 - 200kb/s, trong khi một số site get link speed rất cao 2MB/s. Mình get link từ những site đó đc luôn chứng tỏ họ ko download về server.
    Xin hỏi có cách nào để speed nhanh hơn ko ạ. Cảm ơn các bác.
    --- Double Post Merged, Jan 16, 2021, Original Post Date: Jan 15, 2021 ---
    up
     
    bmt likes this.
  5. Hoa Mãn Lâu

    Hoa Mãn Lâu Trưởng Môn

    Có link nòa demo ko thớt?
     
  6. dev9x

    dev9x Sơ Nhập Giang Hồ

    Đây nha bác, link get đc từ ok.ru
    https://vd295.mycdn.me/?expires=161...urls=45.136.22.5&clientType=0&id=941740198559

    Link download từ site get link : aiovideodl ml
    --- Double Post Merged, Jan 16, 2021, Original Post Date: Jan 16, 2021 ---
    https://aiovideodl.ml/#url=https://ok.ru/video/1859306523295
    --- Double Post Merged, Jan 16, 2021 ---
    à bác phải set header origin và referer là ok.ru mới download đc nha
    --- Double Post Merged, Jan 16, 2021 ---
    PHP:
    function force_download($remoteURL$vidName$ftype)
    {
        
    $fsize get_file_size($remoteURLfalsefalse);
        
    header('Content-Description: File Transfer');
        
    header('Content-Type: application/octet-stream');
        
    header('Content-Disposition: attachment; filename="' htmlspecialchars_decode(sanitize_filename($vidName$ftype)) . '"');
        
    header('Content-Transfer-Encoding: binary');
        
    header('Expires: 0');
        
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        
    header('Pragma: public');
        if (
    $fsize 0) {
            
    header('Content-Length: ' $fsize);
        }
        
    header('Connection: Close');
        
    ob_clean();
        
    flush();
        
    // Activate flush
        
    if (function_exists('apache_setenv')) {
            
    apache_setenv('no-gzip'1);
        }
        @
    ini_set('zlib.output_compression'false);
        
    ini_set('implicit_flush'true);
        
    // CURL Process
        
    $ch curl_init();
        
    $chunkEnd $chunkSize 1000000;  // 1 MB in bytes
        
    $tries $count $chunkStart 0;
        
    $cookie_file_name $_SESSION["token"] . ".txt";
        
    $cookie_file join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), $cookie_file_name]);
        while (
    $fsize $chunkStart) {
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_URL$remoteURL);
            
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
            
    curl_setopt($chCURLOPT_BINARYTRANSFER1);
            
    curl_setopt($chCURLOPT_USERAGENT_REQUEST_USER_AGENT);
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
            
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
            
    curl_setopt($chCURLOPT_RANGE$chunkStart '-' $chunkEnd);
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($chCURLOPT_BUFFERSIZE$chunkSize);
            if (!empty(
    $_SESSION["proxy"])) {
                
    $proxy $_SESSION["proxy"];
                
    curl_setopt($chCURLOPT_PROXY$proxy['ip'] . ":" $proxy['port']);
                
    curl_setopt($chCURLOPT_PROXYTYPEget_proxy_type($proxy['type']));
                if (!empty(
    $proxy['username']) && !empty($proxy['password'])) {
                    
    curl_setopt($chCURLOPT_PROXYUSERPWD$proxy['username'] . ":" $proxy['password']);
                }
                
    $chunkSize 1000000;
                
    curl_setopt($chCURLOPT_TIMEOUT, (int)ceil(* (round($chunkSize 10485762) / (8))));
            }
            if (
    file_exists($cookie_file)) {
                
    curl_setopt($chCURLOPT_COOKIEFILE$cookie_file);
            }
            
    //curl_setopt($ch, CURLOPT_MAX_RECV_SPEED_LARGE, "100");
            
    $output curl_exec($ch);
            
    $curlInfo curl_getinfo($ch);
            if (
    $curlInfo['http_code'] != "206" && $tries 10) {
                
    $tries++;
                continue;
            } else {
                
    $tries 0;
                echo 
    $output;
                
    flush();
                
    ob_implicit_flush(true);
                if (
    ob_get_length() > 0ob_end_flush();
            }
            
    $chunkStart += $chunkSize;
            
    $chunkStart += ($count == 0) ? 0;
            
    $chunkEnd += $chunkSize;
            
    $count++;
            
    //sleep(10);
        
    }
        
    curl_close($ch);
        exit;
    }
    --- Double Post Merged, Jan 16, 2021 ---
    đây là function script đấy dùng để download, speed toàn 2mb/s, em get link download chỉ đc 100kb, 200kb
    --- Double Post Merged, Jan 16, 2021 ---
    Up
    --- Double Post Merged, Jan 24, 2021 ---
    xin phép đc đào top ạ, em vẫn chưa tìm đc lời giải. Em check đc là nó dùng http transfer php, em up thử lên host ở hawhost mà downlaod vẫn chậm quá
    upload_2021-1-24_13-32-16.png
    --- Double Post Merged, Jan 24, 2021 ---
    ko hiểu sao của nó nhanh thật sự
     
  7. Cái bang

    Cái bang Sơ Nhập Giang Hồ

    Các site stream thường sẽ giới hạn tốc độ download sau 1 số MB nhất định. Cái này do server nó cấu hình để hạn chế.
    Cái code download kia nó chia ra download từng MB sau đó ghép lại nên mới maxspeed được.
     
    dev9x likes this.
  8. dev9x

    dev9x Sơ Nhập Giang Hồ

    vâng bác, nhưng em lấy nguyên code của nó vứt lên server em mà cũng chậm :(( hay do tại server của em đểu
    --- Double Post Merged, Jan 24, 2021, Original Post Date: Jan 24, 2021 ---
    PHP:
    <?php
    session_start
    ();
    const 
    _REQUEST_USER_AGENT "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36";

    force_download("https://vd296.mycdn.me/?expires=1611560222076&srcIp=117.5.147.83&srcAg=CHROME&ms=185.226.53.5&type=3&sig=f6d5gGCw7Kc&ct=0&urls=185.226.52.4&clientType=0&id=941889948319""video_name""mp4");

    function 
    force_download($remoteURL$vidName$ftype)
    {
        
    $fsize get_file_size($remoteURLfalsefalse);
        
    header("Pragma: public");
        
    header("Expires: 0");
        
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        
    header("Cache-Control: private"false);
        
    //header('Content-Description: File Transfer');
        
    header('Content-Type: application/octet-stream');
        
    header('Content-Disposition: attachment; filename="' htmlspecialchars_decode(sanitize_filename($vidName$ftype)) . '"');
        
    header("Content-Transfer-Encoding: binary");
        
    header("Accept-Ranges: bytes");
        if (
    $fsize 0) {
            
    header('Content-Length: ' $fsize);
        }
        
    header('Connection: Close');
        @
    ini_set('max_execution_time'0);
        @
    set_time_limit();
        
    ob_clean();
        
    flush();
        
    // Activate flush
        
    if (function_exists('apache_setenv')) {
            
    apache_setenv('no-gzip'1);
        }
        @
    ini_set('zlib.output_compression'false);
        
    ini_set('implicit_flush'true);
        
    // CURL Process
        
    $ch curl_init();
        
    $chunkEnd $chunkSize 1000000;  // 1 MB in bytes
        
    $tries $count $chunkStart 0;
        
    //$cookie_file_name = $_SESSION["token"] . ".txt";
        //$cookie_file = join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), $cookie_file_name]);
        
    while ($fsize $chunkStart) {
            
    curl_setopt($chCURLOPT_HEADER0);
            
    curl_setopt($chCURLOPT_URL$remoteURL);
            
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
            
    curl_setopt($chCURLOPT_BINARYTRANSFER1);
            
    curl_setopt($chCURLOPT_USERAGENT_REQUEST_USER_AGENT);
            
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
            
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
            
    curl_setopt($chCURLOPT_RANGE$chunkStart '-' $chunkEnd);
            
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($chCURLOPT_BUFFERSIZE$chunkSize);
            if (!empty(
    $_SESSION["proxy"])) {
                
    $proxy $_SESSION["proxy"];
                
    curl_setopt($chCURLOPT_PROXY$proxy['ip'] . ":" $proxy['port']);
                
    curl_setopt($chCURLOPT_PROXYTYPEget_proxy_type($proxy['type']));
                if (!empty(
    $proxy['username']) && !empty($proxy['password'])) {
                    
    curl_setopt($chCURLOPT_PROXYUSERPWD$proxy['username'] . ":" $proxy['password']);
                }
                
    $chunkSize 1000000;
                
    curl_setopt($chCURLOPT_TIMEOUT, (int)ceil(* (round($chunkSize 10485762) / (8))));
            }
            
    //if (file_exists($cookie_file)) {
            //    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
            //}
            //curl_setopt($ch, CURLOPT_MAX_RECV_SPEED_LARGE, "100");
            
    $output curl_exec($ch);
            
    $curlInfo curl_getinfo($ch);
            if (
    $curlInfo['http_code'] != "206" && $tries 10) {
                
    $tries++;
                continue;
            } else {
                
    $tries 0;
                echo 
    $output;
                
    flush();
                
    ob_implicit_flush(true);
                if (
    ob_get_length() > 0ob_end_flush();
            }
            
    $chunkStart += $chunkSize;
            
    $chunkStart += ($count == 0) ? 0;
            
    $chunkEnd += $chunkSize;
            
    $count++;
            
    //sleep(10);
        
    }
        
    curl_close($ch);
        exit;
    }
    function 
    get_file_size($url$enable_proxies false$format true)
    {
        
    $cookie_file_name $_SESSION["token"] . ".txt";
        
    $cookie_file join(DIRECTORY_SEPARATOR, [sys_get_temp_dir(), $cookie_file_name]);
        
    $result = -1;  // Assume failure.
        // Issue a HEAD request and follow any redirects.
        
    $curl curl_init($url);
        
    curl_setopt($curlCURLOPT_NOBODYtrue);
        
    curl_setopt($curlCURLOPT_HEADERtrue);
        
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($curlCURLOPT_REFERER'');
        
    //curl_setopt($curl, CURLOPT_INTERFACE, '');
        
    curl_setopt($curlCURLOPT_SSL_VERIFYHOSTFALSE);
        
    curl_setopt($curlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
        
    curl_setopt($curlCURLOPT_FOLLOWLOCATIONtrue);
        
    curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($curlCURLOPT_USERAGENT_REQUEST_USER_AGENT);
        if (
    $enable_proxies) {
            if (!empty(
    $_SESSION["proxy"] ?? null)) {
                
    $proxy $_SESSION["proxy"];
            } else {
                
    $proxy get_proxy();
                
    $_SESSION["proxy"] = $proxy;
            }
            
    curl_setopt($curlCURLOPT_PROXY$proxy['ip'] . ":" $proxy['port']);
            
    curl_setopt($curlCURLOPT_PROXYTYPEget_proxy_type($proxy['type']));
            if (!empty(
    $proxy['username']) && !empty($proxy['password'])) {
                
    curl_setopt($curlCURLOPT_PROXYUSERPWD$proxy['username'] . ":" $proxy['password']);
            }
            
    $chunkSize 1000000;
            
    curl_setopt($curlCURLOPT_TIMEOUT, (int)ceil(* (round($chunkSize 10485762) / (8))));
        }
        if (
    file_exists($cookie_file)) {
            
    curl_setopt($curlCURLOPT_COOKIEFILE$cookie_file);
        }
        
    $headers curl_exec($curl);
        if (
    curl_errno($curl) == 0) {
            
    $result = (int)curl_getinfo($curlCURLINFO_CONTENT_LENGTH_DOWNLOAD);
        }
        
    curl_close($curl);
        if (
    $result 100) {
            switch (
    $format) {
                case 
    true:
                    return 
    format_size($result);
                    break;
                case 
    false:
                    return 
    $result;
                    break;
                default:
                    return 
    format_size($result);
                    break;
            }
        } else {
            return 
    "";
        }
    }
    function 
    sanitize_filename($string$ftype)
    {
        return (
    filter_filename($string) ?? "video") . "." $ftype;
    }
    function 
    filter_filename($filename$beautify true)
    {
        
    // sanitize filename
        
    $filename preg_replace(
            
    '~
            [<>:"/\\|?*]|            # file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
            [\x00-\x1F]|             # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
            [\x7F\xA0\xAD]|          # non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN
            [#\[\]@!$&\'()+,;=]|     # URI reserved https://tools.ietf.org/html/rfc3986#section-2.2
            [{}^\~`]                 # URL unsafe characters https://www.ietf.org/rfc/rfc1738.txt
            ~x'
    ,
            
    '-'$filename);
        
    // avoids ".", ".." or ".hiddenFiles"
        
    $filename ltrim($filename'.-');
        
    // optional beautification
        
    if ($beautify$filename beautify_filename($filename);
        
    // maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
        
    $ext pathinfo($filenamePATHINFO_EXTENSION);
        
    $filename mb_strcut(pathinfo($filenamePATHINFO_FILENAME), 0255 - ($ext strlen($ext) + 0), mb_detect_encoding($filename)) . ($ext '.' $ext '');
        return 
    $filename;
    }

    function 
    beautify_filename($filename)
    {
        
    // reduce consecutive characters
        
    $filename preg_replace(array(
            
    // "file   name.zip" becomes "file-name.zip"
            
    '/ +/',
            
    // "file___name.zip" becomes "file-name.zip"
            
    '/_+/',
            
    // "file---name.zip" becomes "file-name.zip"
            
    '/-+/'
        
    ), '-'$filename);
        
    $filename preg_replace(array(
            
    // "file--.--.-.--name.zip" becomes "file.name.zip"
            
    '/-*\.-*/',
            
    // "file...name..zip" becomes "file.name.zip"
            
    '/\.{2,}/'
        
    ), '.'$filename);
        
    // lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
        
    $filename mb_strtolower($filenamemb_detect_encoding($filename));
        
    // ".file-name.-" becomes "file-name"
        
    $filename trim($filename'.-');
        return 
    $filename;
    }

    ?>
    --- Double Post Merged, Jan 24, 2021 ---
    code bên trên các bác thử test xem
    --- Double Post Merged, Jan 24, 2021 ---
    upload_2021-1-24_15-43-3.png
    --- Double Post Merged, Jan 24, 2021 ---
    sao ko có bác nào giúp em với :(
     
    nguyennv123 likes this.
  9. sincos

    sincos Bang Chúng

    Đến bước này thì tự sử đi bạn ạ. Hoặc bỏ tiền ra thuê.
     
    dev9x likes this.
  10. No.2

    No.2 Khách Qua Đường

    dùng streamlink để download nhé Bác [search google ]

    download về , giải nén ra trong folder có file Streamlink.bat paste link vào là nó tự download
    còn muốn down các res khác nhau thì thêm resolution vào
    ví dụ :
    streamlink "link ok.ru " 720p -o "file.mp4"
     
    dev9x and Hoa Mãn Lâu like this.