0

I'm searching for a solution to this problem for a long time and I didn't get any solutions.

I managed to extract the mp4 URL, ​​but the problem is that this link redirects to another URL that can be seen in response header: Location, I don't know how I can get this URL.

Response Header(img)

<?php
function tidy_html($input_string) {
         
    $config = array('output-html'   => true,'indent' => true,'wrap'=> 800); 
            
    // Detect if Tidy is in configured    
    if( function_exists('tidy_get_release') ) {
        $tidy = new tidy;
        $tidy->parseString($input_string, $config, 'raw');
        $tidy->cleanRepair();
        $cleaned_html  = tidy_get_output($tidy); 
        } 
    else {
        # Tidy not configured for this Server
        $cleaned_html = $input_string;
    }
    return $cleaned_html;
}

function getFromPage($webAddress,$path){
    $source = file_get_contents($webAddress); //download the page 
    $clean_source = tidy_html($source);
    $doc = new DOMDocument;

    // suppress errors
    libxml_use_internal_errors(true);

    // load the html source from a string
    $doc->loadHTML($clean_source);
    $xpath = new DOMXPath($doc);
    $data="";
    $nodelist = $xpath->query($path);
    $node_counts = $nodelist->length; // count how many nodes returned
    if ($node_counts) { // it will be true if the count is more than 0
        foreach ($nodelist as $element) {
           $data= $data.$element->nodeValue . "\n";
        }
    }
    return $data;
    
}


$vidID = 4145616; //videoid : https://video.sibnet.ru/shell.php?videoid=4145616

$link1 = getFromPage("https://video.sibnet.ru/shell.php?videoid=".$vidID,"/html/body/script[21]/text()"); // Use XPath 
$json = urldecode($link1);

$link2 = strstr($json, "player.src");

$url = substr($link2, 0, strpos($link2, ","));

$url =str_replace('"',"",$url);

$url = substr($url , 18);


//header('Location: https://video.sibnet.ru'.$url);
echo ('https://video.sibnet.ru'.$url)


?>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
S Moutz
  • 1
  • 2

1 Answers1

1

<?php 

$url='https://video.sibnet.ru'.$url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$a = curl_exec($ch);

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL

$realUrl = $url; //here you go

?>

SOURCE: https://stackoverflow.com/a/17473000/14885297

Mateja
  • 271
  • 1
  • 11