PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/feeds/xVoD/xVoD/php/util/VideoUtil.php

http://eboda-hd-for-all-500.googlecode.com/
PHP | 171 lines | 115 code | 16 blank | 40 comment | 9 complexity | dc43c2e8d44c465afeef017418e75407 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. /*-------------------------
  3. * Developed by Maicros
  4. * GNU/GPL Licensed
  5. * ------------------------*/
  6. class VideoUtil {
  7. /**
  8. * Separate id+image type from Megavideo.
  9. * @param String $idWithImage
  10. * @return array Array(ID,IMAGE) in separate array string.
  11. */
  12. public static function separateMegavideoIdWithImage($idWithImage){
  13. $content = file_get_contents("http://www.megavideo.com/v/" . $idWithImage );
  14. foreach ($http_response_header as $value) {
  15. if( strpos( $value, "ocation: " ) ){
  16. $value = strstr($value, "=" );
  17. $image = substr($value, 1, strpos($value,"&")-1 );
  18. $value = strstr($value, "v=" );
  19. $id = substr($value, 2 );
  20. return array( $id, $image );
  21. }
  22. }
  23. }
  24. /**
  25. * Generate links with megaupload premium account, ORIGINAL LINK, NOT FLV
  26. *
  27. * @param String $megavideo_id
  28. * @return String Url, false if not found
  29. */
  30. public static function generateMegavideoPremiumLink($megavideo_id) {
  31. //Get megavideo original link download
  32. $link = "http://www.megavideo.com/xml/player_login.php?u=". MEGAUPLOAD_COOKIE . "&v=" . $megavideo_id;
  33. $content = file_get_contents($link);
  34. //Check for premium account
  35. if( strstr($content, 'type="premium"') ) {
  36. //Get direct download link
  37. $downloadurl = strstr($content, "downloadurl=");
  38. $downloadurl = substr($downloadurl, 13, strpos($downloadurl,'" ')-13 );
  39. if($downloadurl) {
  40. $downloadurl = urldecode($downloadurl);
  41. $downloadurl = html_entity_decode($downloadurl);
  42. //Get enclosure mimetype
  43. $videoType = VideoUtil::getEnclosureMimetype($downloadurl);
  44. //Get file name
  45. $filename = substr(strrchr($downloadurl, "/"), 1);
  46. return array($filename,$downloadurl,$videoType);
  47. }
  48. //Check another method for megavideo.com/?d links
  49. $megauploadArray = VideoUtil::generateMegauploadPremiumLink($megavideo_id);
  50. if($megauploadArray && $megauploadArray != null ){
  51. return $megauploadArray;
  52. }
  53. }
  54. }
  55. /**
  56. * Generate links with megaupload premium account
  57. *
  58. * @param String $megavideo_id
  59. * @return String Url, false if not found.
  60. */
  61. public static function generateMegauploadPremiumLink($megavideo_id) {
  62. $link = "http://www.megaupload.com/?d=" . $megavideo_id;
  63. $options = array(
  64. 'http'=>array(
  65. 'method'=>"GET",
  66. 'header'=>"Accept-language: en\r\n" .
  67. "Keep-Alive: 115\r\n" .
  68. "Connection: keep-alive\r\n" .
  69. "Cookie: l=es; user=" . MEGAUPLOAD_COOKIE . "\r\n"
  70. )
  71. );
  72. $context = stream_context_create($options);
  73. $content = file_get_contents($link,false,$context);
  74. if( !strstr($content, "captchacode") ) {
  75. $content = strstr($content, "down_ad_pad1");
  76. $content = strstr($content,'<a href="');
  77. $megauploadUrl = substr($content, 9, strpos($content,'" ')-9 );
  78. $megauploadUrl = urldecode($megauploadUrl);
  79. $megauploadUrl = html_entity_decode($megauploadUrl);
  80. $videoType = VideoUtil::getEnclosureMimetype($megauploadUrl);
  81. if($megauploadUrl){
  82. return array(substr( $megauploadUrl,strrpos($megauploadUrl, "/")+1 ) ,$megauploadUrl, $videoType);
  83. }
  84. }
  85. }
  86. /**
  87. * Generate youtube links
  88. *
  89. * @param String $youtube_id
  90. * @return String URL
  91. */
  92. public static function generateYoutubeLink($youtube_id) {
  93. $path = "http://www.youtube.com/get_video_info?";
  94. //Get token
  95. $ch = curl_init();
  96. curl_setopt ($ch, CURLOPT_URL, $path."&video_id=".$youtube_id);
  97. curl_setopt ($ch, CURLOPT_HEADER, 0);
  98. ob_start();
  99. curl_exec ($ch);
  100. curl_close ($ch);
  101. $string = ob_get_contents();
  102. ob_end_clean();
  103. parse_str($string, $opts);
  104. $token = $opts['token'];
  105. //Return link
  106. return "http://www.youtube.com/get_video.php?video_id=" . $youtube_id . "&t=" . $token . "&fmt=18";
  107. }
  108. /**
  109. * Get enclosure mimetype from extension filename
  110. * @param String $megavideo_id
  111. * @return String Mimetype.
  112. */
  113. public static function getEnclosureMimetype($name) {
  114. switch ( substr($name, strrpos($name, '.')+1 ) ) {
  115. case "asf":
  116. $videoType = "video/x-ms-asf";
  117. break;
  118. case "avi":
  119. $videoType = "video/x-msvideo";
  120. break;
  121. case "mp4":
  122. $videoType = "video/mp4";
  123. break;
  124. case "flv":
  125. $videoType = "video/x-flv"; //video/flv
  126. break;
  127. case "mkv":
  128. $videoType = "video/x-matroska"; //video/x-mkv
  129. break;
  130. case "wmv":
  131. $videoType = "video/x-ms-wmv";
  132. break;
  133. case "mov":
  134. $videoType = "video/quicktime";
  135. break;
  136. case "mpg": case "mpeg": case "vob": case "m2ts":
  137. $videoType = "video/mpeg";
  138. break;
  139. case "3gp":
  140. $videoType = "video/3gpp";
  141. break;
  142. case "ts": case "tp": case "trp":
  143. $videoType = "video/mp2t";
  144. break;
  145. case "divx":
  146. $videoType = "video/divx";
  147. break;
  148. default:
  149. $videoType = "video/x-flv";
  150. break;
  151. }
  152. return $videoType;
  153. }
  154. }
  155. ?>