Skip to content

Instantly share code, notes, and snippets.

@optinsoft
Created August 3, 2024 08:19
Show Gist options
  • Select an option

  • Save optinsoft/6515ec8cfc4125d4a03bcab6012a656f to your computer and use it in GitHub Desktop.

Select an option

Save optinsoft/6515ec8cfc4125d4a03bcab6012a656f to your computer and use it in GitHub Desktop.
Get eurosport stream URL
<?php
$eurosport_url = 'http://cdntvmedia.com/eurosport-1.php';
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36';
function load_url($url, $referer, &$location, &$contenttype) {
$location = null;
$contenttype = null;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
$error = null;
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
$headers = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $response));
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 200: # OK
break;
case 301:
case 302:
foreach($headers as $header) {
if (empty($header)) break;
if (preg_match('/Location: (.+)/m', $header, $match) ) {
$location = $match[1];
}
}
if (!$location) {
$error = 'Location not found';
}
break;
default:
$error = 'Unexpected HTTP code: ' . $http_code;
}
foreach($headers as $header) {
if (empty($header)) break;
if (preg_match('/Content-Type: (.+)/m', $header, $match) ) {
$contenttype = $match[1];
}
}
}
else {
$error = curl_error($ch);
}
curl_close($ch);
if ($error) {
die($error);
}
$html_pos = strpos($response, "\r\n\r\n");
$html = $html_pos === false ? $response : substr($response, $html_pos+4);
return $html;
}
$location = null;
$contenttype = null;
$response = load_url($eurosport_url, 'http://smotret-tv.live/', $location, $contenttype);
$playerjs_pattern = '/new Playerjs\(([^)]*)\)/';
$success = preg_match($playerjs_pattern, $response, $match);
if ($success) {
$playerjs = $match[1];
$file_pattern = '/file:\s*"([^"]*)"/';
$success = preg_match($file_pattern, $playerjs, $match);
if ($success) {
$file_url = $match[1];
# header('Location: ' . $file_url, true, 302);
# die();
$parse = parse_url($file_url);
$file = load_url($file_url, 'http://cdntvmedia.com/', $location, $contenttype);
if (!empty($location)) {
if (str_starts_with($location, '/')) {
$parse = parse_url($file_url);
$location = $parse['scheme'] . '://' . $parse['host'] . $location;
}
$location_url = $location;
header('Location: ' . $location_url, true, 302);
die();
}
echo '(3) no redirect';
}
else {
echo '(2) not match';
}
}
else {
echo '(1) not match';
}
?>
<?php
$eurosport_url = 'http://cdntvmedia.com/eurosport-2.php';
$user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36';
function load_url($url, $referer, &$location, &$contenttype) {
$location = null;
$contenttype = null;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$response = curl_exec($ch);
$error = null;
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
$headers = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $response));
switch ($http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
case 200: # OK
break;
case 301:
case 302:
foreach($headers as $header) {
if (empty($header)) break;
if (preg_match('/Location: (.+)/m', $header, $match) ) {
$location = $match[1];
}
}
if (!$location) {
$error = 'Location not found';
}
break;
default:
$error = 'Unexpected HTTP code: ' . $http_code;
}
foreach($headers as $header) {
if (empty($header)) break;
if (preg_match('/Content-Type: (.+)/m', $header, $match) ) {
$contenttype = $match[1];
}
}
}
else {
$error = curl_error($ch);
}
curl_close($ch);
if ($error) {
die($error);
}
$html_pos = strpos($response, "\r\n\r\n");
$html = $html_pos === false ? $response : substr($response, $html_pos+4);
return $html;
}
$location = null;
$contenttype = null;
$response = load_url($eurosport_url, 'http://smotret-tv.live/', $location, $contenttype);
$playerjs_pattern = '/new Playerjs\(([^)]*)\)/';
$success = preg_match($playerjs_pattern, $response, $match);
if ($success) {
$playerjs = $match[1];
$file_pattern = '/file:\s*"([^"]*)"/';
$success = preg_match($file_pattern, $playerjs, $match);
if ($success) {
$file_url = $match[1];
//header('Location: ' . $file_url, true, 302);
//die();
$parse = parse_url($file_url);
$file = load_url($file_url, 'http://cdntvmedia.com/', $location, $contenttype);
if (!empty($location)) {
if (str_starts_with($location, '/')) {
$parse = parse_url($file_url);
$location = $parse['scheme'] . '://' . $parse['host'] . $location;
}
$location_url = $location;
header('Location: ' . $location_url, true, 302);
die();
}
echo '(3) no redirect';
}
else {
echo '(2) not match';
}
}
else {
echo '(1) not match';
}
?>
@44zzffrvs14
Copy link

Hello.
Tell me how to use it, how to embed playerjs on the page?

@optinsoft
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment