Guest User

Ok.ru

a guest
Apr 14th, 2020
1,578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.68 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Getting direct mixdrop URL
  5.  * using node-urlresolver-api API by @lscofield
  6.  * This script is only tested with mixdrop links
  7.  */
  8.  
  9. // mixdrop test url
  10. // Note the url should be embed (/e/) to work
  11. // Do not use url without embed it (/f/)
  12. // You can test with another link if this link go down
  13. $url = 'https://ok.ru/videoembed/3462041111040';
  14. // Create curl instance (GET)
  15. $ch = curl_init();
  16. //Set the URL that you want to GET by using the CURLOPT_URL option.
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. //Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  20. //Set CURLOPT_FOLLOWLOCATION to false to follow redirects.
  21. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
  22. // Set referer for mixdrop request
  23. $refer = "https://ok.ru/";
  24. curl_setopt($ch, CURLOPT_REFERER, $refer);
  25. //Execute the request.
  26. $html = curl_exec($ch);
  27. //Close the cURL handle.
  28. curl_close($ch);
  29.  
  30. // Encode the html code to base64
  31. $html = base64_encode($html);
  32. $host = "ok"; // in this case
  33. $api_endpoint = "http://localhost:8000/api/v1/$host";
  34. // Prepare POST params
  35. // Prepare auth param
  36. $auth = '{"auth":"","skk":"123123"}';
  37. // Encode auth to base64
  38. $auth = base64_encode($auth);
  39. $params = array(
  40.   "source" => $html,
  41.   "mode" => 'local', // always local
  42.   "auth" => $auth
  43. );
  44.  
  45. $params = json_encode($params);
  46. // Create curl instance (POST) to get direct
  47. // URL with API
  48. $ch = curl_init($api_endpoint);
  49. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  50. curl_setopt($ch, CURLINFO_HEADER_OUT, true);
  51. curl_setopt($ch, CURLOPT_POST, true);
  52. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  53. // Set HTTP Header for POST request
  54. curl_setopt(
  55.   $ch,
  56.   CURLOPT_HTTPHEADER,
  57.   array(
  58.     'Content-Type: application/json',
  59.     'Content-Length: ' . strlen($params)
  60.   )
  61. );
  62. // Submit the POST request
  63. $result = curl_exec($ch);
  64. // Close cURL session handle
  65. curl_close($ch);
  66.  
  67.  
  68. if ($result) {
  69.   // Convert to json
  70.   $result = json_decode($result);
  71.   // Print direct url (format: .mp4 or .m3u8)
  72.   // Note to play this video in a videoplayer
  73.   // you need to pass $url to http referer header in these
  74.   // player to be play
  75.   // Other wise you will get ERROR 404 or similar in
  76.   // the media player
  77.   echo $result->url;
  78.   echo '<video width="320" height="240" controls>
  79.  <source src="' . $result->url . '" type="video/mp4">
  80.  </video>';
  81.   // Note if the app_key set in post auth
  82.   // not match with the app_key that you
  83.   // has in your server config file
  84.   // $resul->url will have a random troll mp4 video
  85.   // If mixdrop url is down $result->url will have empty string
  86. } else {
  87.   // No data fetched
  88.   // Typically API or SERVER issue
  89. }
Advertisement
Add Comment
Please, Sign In to add comment