Advertisement
EddieKidiw

Php youtube to mp3 ( convert2mp3.net )

Apr 3rd, 2016
1,401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Online Video Converter
  4.  * @author Achunk JealousMan
  5.  * @link http://fb.me/achunks
  6.  * @link http://convert2mp3.net
  7.  * @license GPL
  8.  * @Cara menggunakannya, upload atau kopi paste ke hosting anda masing-masing dan jalankan, contoh: http://situs-anda.com/file.php?id=id_youtube
  9.  */
  10. @set_time_limit(0);
  11. $video_url = 'https://www.youtube.com/watch?v='.$_GET['id'].''; // supported sites:  YouTube, Dailymotion, Vevo and Clipfish
  12. $format = 'mp3'; //supported format: mp3, m4a, aac, flac, ogg, wma, mp4, 3gp, avi, wmp
  13. $user_agent = 'Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54';
  14. $cookie = dirname(__file__) . '/convert2mp3.txt';
  15. $ch = curl_init();
  16. curl_setopt($ch, CURLOPT_URL, 'http://convert2mp3.net/en/index.php');
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  18. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  19. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  20. $result = curl_exec($ch);
  21. preg_match('/\<input type\=\"hidden\" name\=\"([a-z0-9]+)\" value\=\"([\d]+)\"\>/', $result, $matches, PREG_OFFSET_CAPTURE);
  22. if (!$matches)
  23. {
  24.     header("HTTP/1.0 404 Not Found");
  25.     die('Error');
  26. }
  27. $params = implode('&', array(
  28.     'url=' . urlencode($video_url),
  29.     'format=' . $format,
  30.     'quality=1',
  31.     $matches[1][0] . '=' . $matches[2][0],
  32.     'convert=1',
  33.     ));
  34. $url = 'http://convert2mp3.net/en/index.php?p=convert';
  35. curl_setopt($ch, CURLOPT_URL, $url);
  36. curl_setopt($ch, CURLOPT_POST, 1);
  37. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  38. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  39. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  40. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  41. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  42. $res = curl_exec($ch);
  43. $exp = explode('<iframe id="convertFrame" src="', $res);
  44. $sub = explode('"', $exp[1]);
  45. $frame_url = $sub[0];
  46. curl_setopt($ch, CURLOPT_URL, $frame_url);
  47. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  48. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  49. curl_setopt($ch, CURLOPT_NOBODY, true);
  50. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  51. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  52. $res = curl_exec($ch);
  53. parse_str(parse_url($frame_url, PHP_URL_QUERY));
  54. $sid = substr(parse_url($frame_url, PHP_URL_HOST), 5, -16);
  55. $file_url = 'http://cdl' . $sid . '.convert2mp3.net/download.php?id=' . $id . '&key=' . $key . '&d=y';
  56. curl_setopt($ch, CURLOPT_URL, $file_url);
  57. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  58. curl_setopt($ch, CURLOPT_HEADER, true);
  59. curl_setopt($ch, CURLOPT_NOBODY, true);
  60. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  61. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  62. $out = curl_exec($ch);
  63. $out = explode("\n", $out);
  64. foreach ($out as $header)
  65. {
  66.     preg_match('#(.*?)\:\s(.*)#', $header, $matches);
  67.     if (isset($matches[1]) && isset($matches[2]))
  68.         header($matches[1] . ': ' . $matches[2]);
  69. }
  70. curl_setopt($ch, CURLOPT_URL, $file_url);
  71. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  72. curl_setopt($ch, CURLOPT_HEADER, false);
  73. curl_setopt($ch, CURLOPT_NOBODY, false);
  74. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  75. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
  76. echo curl_exec($ch);
  77. curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement