2016-06-19 49 views
-2

尝试运行此代码,但在下面的代码中获取了错误,未定义的偏移量:0行167。我不知道这是什么意思,因为我是一个新的PHP入门者,并且试图理解这段代码。未定义的偏移量:0在167行上的/tmp/umsp-plugins/pakfiles/pakfiles.php

<?php 
# pakfiles ver.0.1 - UMSP-plugin for http://www.pakfiles.com 
# Info - http://forum.wdlxtv.com/viewtopic.php?f=53&t=9235 
include 'myhoster.php'; 
//include $_SERVER['DOCUMENT_ROOT'] . '/umsp/plugins/hosters/hosters.php'; 


function _pluginMain($prmQuery) { 
$prmQuery = htmlspecialchars_decode($prmQuery); 
if (strpos($prmQuery,'&amp;')!==false) $prmQuery=str_replace('&amp;','&',$prmQuery); 
parse_str($prmQuery, $queryData); 
     $items = array(); 

     if(isset($queryData['cat']) && $queryData['cat']!="") 
     showMoviesMenu($items, $prmQuery); 
    else if(isset($queryData['episode']) && isset($queryData['load'])) 
    showStreamsMenu($items, $prmQuery); 
    else if(isset($queryData['tvshow']) && $queryData['tvshow']!="") 
    showALLEpisodesMenu($items, $prmQuery); 
    else if(isset($queryData['episode']) && $queryData['episode']!="") 
    showEpisodesMenu($items, $prmQuery); 
    else { 
       if (file_exists ('/var/log/apache2/proxylo.txt')) unlink('/var/log/apache2/proxylo.txt'); 
     $cats = array(
         'PakDramas:Dramas', 
         'videos:Videos', 
         'talkShows:Talk Shows', 
     ); 
     foreach($cats as $cat) { 
      $cat = explode(":", $cat); 
      $items[] = array(
       'id'    => "umsp://plugins/pakfiles?cat=".urlencode($cat[0]), 
       'dc:title'  => $cat[1], 
       'upnp:class'  => 'object.container', 
       'upnp:album_art' => '' 
      ); 
     } 

     } 

     return $items; 
    } 

    function showMoviesMenu(&$items, $prmQuery) { 
    $prmQuery = htmlspecialchars_decode($prmQuery); 
    if (strpos($prmQuery,'&amp;')!==false) $prmQuery=str_replace('&amp;','&',$prmQuery); 
    parse_str($prmQuery, $queryData); 

       $cat = $queryData['cat']; 
       $cat = str_replace("&amp;","&",$cat); 

       if (($cat === 'PakDramas') || ($cat === 'videos') || ($cat === 'talkShows')) { 
         $url = 'http://www.pakfiles.com/'; 
         if ($cat === 'PakDramas') { 

           $url = 'http://www.pakfiles.com/pakistani-dramas'; 

           $html = @file_get_contents($url); 

           $html = str_replace("\r","",$html); 
           $html = str_replace("\n"," ",$html); 
           $html = str_replace("\t","",$html); 
           $pattern = '|<div class="list-group">(.*?)</div>|'; 
           preg_match($pattern, $html, $data); 
           $pattern = '|<a href="([^"]+)" title="[^"]+"\s* class="([^"]+)">([^<]+)</a>|'; 
           preg_match_all($pattern, $data[1], $subcats, PREG_SET_ORDER); 
//print_r($subcats); 
           foreach ($subcats as $subcat){ 

             $items[] = array(
               'id'    => 'umsp://plugins/pakfiles?tvshow='.urlencode($subcat[1])."&amp;title=".urlencode($subcat[3]), 
               'dc:title'  => $subcat[3], 
               'upnp:album_art' => '', 
               'upnp:class'  => 'object.container', 
             ); 
           } 
           return $items; 
         } 

         else if (($cat === 'videos') || ($cat === 'talkShows')){ 
       if ($cat == 'videos') 
        $url ='http://www.pakfiles.com/browse-videos'; 
     if ($cat == 'talkShows') 
      $url ='http://www.pakfiles.com/browse-talkshows'; 
           $html = @file_get_contents($url); 
           //$html = @file_get_contents($url); 

           $html = str_replace("\r","",$html); 
           $html = str_replace("\n"," ",$html); 
           $html = str_replace("\t","",$html); 
           $pattern = '|<div class="list-group">(.*?)</div>|'; 
           // $pattern = '|<ul id="menu-side-menu-1" class="primary-menu">(.*?)</ul>|'; 
           preg_match($pattern, $html, $data);//print_r($html); 
$data= preg_replace('/<i\s+[^>]*class\s*=\s*"([^"]+)"[^>]*>/', '', $data[1]);  
$data= preg_replace('/<\/i>/', '', $data);  
$data= preg_replace('/<a\s+[^>]*href\s*=\s*"([^"]+)"[^>]*>/', '<a href="\1">', $data); 
//print_r($data); 
          $pattern = '|<a href="([^"]+)">([^<]+)</a>|'; 
          preg_match_all($pattern, $data, $subcats, PREG_SET_ORDER); 

          foreach ($subcats as $subcat){ 
//print_r($subcat); 
             $items[] = array(
               'id'    => 'umsp://plugins/pakfiles?tvshow='.urlencode($subcat[1])."&amp;title=".urlencode($subcat[2]), 
               'dc:title'  => $subcat[2], 
               'upnp:album_art' => '', 
               'upnp:class'  => 'object.container', 
             ); 
           } 
           return $items; 
         } 

       } 

} 

    function showALLEpisodesMenu(&$items, $prmQuery) { 
    //print('load shows list'); 
    $prmQuery = htmlspecialchars_decode($prmQuery); 
    if (strpos($prmQuery,'&amp;')!==false) $prmQuery=str_replace('&amp;','&',$prmQuery); 
    parse_str($prmQuery, $queryData); 
      $tvshow = $queryData['tvshow']; 
      $title = $queryData['title']; 

     ini_set('user_agent', 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'); 
     $url = $tvshow; 
     $html = @file_get_contents($url); 

     $html = str_replace("\r","",$html); 
     $html = str_replace("\n"," ",$html); 
     $html = str_replace("\t","",$html); 
     $html = str_replace("&#8211;","-",$html); 
     $html = preg_replace('|\xE2\x80\x93|','-',$html); 

$html= preg_replace('/<img\s+[^>]*src\s*=\s*"([^"]+)"[^>]*>/', '', $html);   
$pattern = '|<div class="thumbnail">(.*?)</div>|'; 
     preg_match_all($pattern, $html, $episodes); 
//print_r($episodes); 
$episodes=$episodes[1]; 
//print_r($episodes); 

$episodes= preg_replace('/<a\s+[^>]*href\s*=\s*"([^"]+)"[^>]*>/', '<a href="\1">', $episodes); 
$episodes= preg_replace('/<b class="thumb_title">/', '<span class="thumb_title">', $episodes); 
$episodes= preg_replace('/<\/b>/', '</span>', $episodes); 
//print_r($episodes); 
foreach($episodes as $episode) { 
//  $pattern = '|<a title="([^"]+)" href="([^"]+)">|'; 
     $pattern = '|<a href="([^"]+)">|'; 
            preg_match_all($pattern, $episode, $epis, PREG_SET_ORDER); 
//print_r($epis); 
     //$pattern = '|<span class="([^"]+)">([^<]+)</span>|'; 
     $pattern = '|<h3 class="thumb_title">([^<]+)</h3>|';   


preg_match_all($pattern, $episode, $span, PREG_SET_ORDER);       
//print_r($span); 
if(empty($span)) 
{ 
$pattern = '|<span class="thumb_title">([^<]+)</span>|'; 
preg_match_all($pattern, $episode, $span, PREG_SET_ORDER); 
} 
preg_match_all($pattern, $episode, $span, PREG_SET_ORDER); 
//$pattern = '|<a target="_blank" href="([^"]+)" title="([^"]+)" href="([^"]+)">|'; 
       $title=$span[0][1]; 
       $items[] = array(
        'id'    => "umsp://plugins/pakfiles?episode=".urlencode($epis[0][1])."&amp;title=".urlencode($title), 
        'dc:title'  => $title, 
        'upnp:class'  => 'object.container', 
       );  
} 

$pattern = '|<a href="([^"]+)" >([^"]+)</a>|'; 
preg_match_all($pattern, $html, $pages, PREG_SET_ORDER); 
//print_r($pages); 
foreach($pages as $page) 
{ 
if($page[1]=='#') 
{ 
$pno=$page[2]+1; 
}} 
$url=$queryData['tvshow']; 
if(isset($queryData['cpage'])!=""){ 
$nexturl=substr($url,0,strlen($url)-strlen($cpage)-2); 
//print_r($nexturl); 
} 
else 
{ 
if(substr($url,-2)=='-1') 
{ 
$url=substr($url,0,strlen($url)-2); 
} 
$nexturl=$url; 
} 
       $items[] = array(
        'id'    => 'umsp://plugins/pakfiles?tvshow='.urlencode($nexturl) . "-".$pno."&amp;cpage=".$pno." &amp;title=" .$queryData['title'], 
        'dc:title'  => 'Next', 
        //'upnp:album_art' => '', 
        'upnp:class'  => 'object.container', 
       ); 
foreach($pages as $page) 
{ 
if($page[1]=='#') 
{ 
//print_r($page[2]+1); 
$pno=$page[2]-1; 
//print_r($pno); 
}} 
if($pno>0) 
{ 
if(isset($queryData['cpage'])){ 
$prevurl=substr($url,0,strlen($url)-strlen($cpage)-2); 
//print_r($url); 
} 
       $items[] = array(
        'id'    => 'umsp://plugins/pakfiles?tvshow='.urlencode($prevurl) . "-".$pno."&amp;cpage=".$pno." &amp;title=" .$queryData['title'], 
        'dc:title'  => 'Prev', 
        //'upnp:album_art' => '', 
        'upnp:class'  => 'object.container', 
       ); 
} 

return $items; 
} 

function showEpisodesMenu(&$items, $prmQuery) { 
$prmQuery = htmlspecialchars_decode($prmQuery); 
if (strpos($prmQuery,'&amp;')!==false) $prmQuery=str_replace('&amp;','&',$prmQuery); 
parse_str($prmQuery, $queryData); 
      $episode = $queryData['episode']; 
      $title = $queryData['title']; 

     ini_set('user_agent', 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'); 

     if (strpos($episode,'http://') === false) 
       $url = 'http://www.pakfiles.com'.$episode; 
     else 
       $url = $episode; 

     $html = @file_get_contents($url); 
     $html = str_replace("\r","",$html); 
     $html = str_replace("\n"," ",$html); 
     $html =str_replace("\t","",$html); 
$html= preg_replace('/<img\s+[^>]*src\s*=\s*"([^"]+)"[^>]*>/', '', $html); 

//<a target="_blank" class="t_share" data-url="http://www.pakfiles.com/watch-susral-meri-behen-ka-episode-6-166888" href="https://twitter.com/intent/tweet?url=http://www.pakfiles.com/watch-susral-meri-behen-ka-episode-6-166888" data-lang="en"> 
$pattern = '|<a target="_blank" class="t_share" data-url="([^"]+)"|'; 
     preg_match_all($pattern, $html, $latest); 
//print_r($latestURL[1][0]); 
$items[] = array(
          'id'    => "umsp://plugins/pakfiles?episode=".urlencode($latest[1][0])."&amp;title=latest&amp;load=1", 
          'dc:title'  => $title. " (***New***)", 
          'upnp:class'  => 'object.container'); 
$pattern = '|<div class="thumbnail">(.*?)</div>|'; 
     preg_match_all($pattern, $html, $episodes); 
$episodes=$episodes[1]; 
unset($episodes[0]); 
//print_r($episodes); 
foreach($episodes as $episode) { 
//$pattern = '|<a target="([^"]+)" href="([^"]+)" title="([^"]+)" href="([^"]+)">|'; 
$pattern = '|<a href="([^"]+)" title="([^"]+)" target="_blank">|'; 
          preg_match_all($pattern, $episode, $epis, PREG_SET_ORDER); 
          //print_r($epis); 
      // $title=ucwords(substr($epis[0][3],0,strpos($epis[0][3],'uploaded')-1)); 
      $title=ucwords($epis[0][2]); 
      $items[] = array(
          'id'    => "umsp://plugins/pakfiles?episode=".urlencode($epis[0][1])."&amp;title=".urlencode($title) ."&amp;load=1", 
          'dc:title'  => $title, 
          'upnp:class'  => 'object.container', 
         ); 

       } 

     return $items; 
} 

    function showStreamsMenu(&$items, $prmQuery) { 
$prmQuery = htmlspecialchars_decode($prmQuery); 
if (strpos($prmQuery,'&amp;')!==false) $prmQuery=str_replace('&amp;','&',$prmQuery); 
parse_str($prmQuery, $queryData); 
      $episode = $queryData['episode']; 
      $title = $queryData['title']; 

     ini_set('user_agent', 'Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'); 

     if (strpos($episode,'http://') === false) 
       $url = 'http://www.pakfiles.com'.$episode; 
     else 
       $url = $episode; 

     $html = @file_get_contents($url); 
     $html = str_replace("\r","",$html); 
     $html = str_replace("\n"," ",$html); 
     $html =str_replace("\t","",$html); 
//print_r($url); 
/*$pattern = '|<meta name="twitter:video:source" content="([^"]+)"|'; 
preg_match_all($pattern, $html, $url); 
print_r($url); 
$url=explode(':',$url[1][0]); 
$url='http:'.$url[2]; 
$buttontext="Video Not Found"; 
    if(strcmp($url,"mp4")) 
    { 
    $buttontext=(($url !== '')? 'Play' : "Video Not Found"); 
    } 

    else 
    { 
    //print_r($html); 
    $temp = explode("<iframe id", $html); 
    $temp=$temp[1]; 
    if (empty($temp)){ 
     //print_r("Dailymotion"); 
     //<iframe frameborder="0" width="100%" height="400" related="0" info="0" logo="0" src="//www.dailymotion.com/embed/video/x35kjdz" allowfullscreen></iframe> 
     $pattern = '#<iframe frameborder="[^"]*" width="[^"]*" height="[^"]*" related="[^"]*" info="[^"]*" logo="[^"]*" src="([^"]*)" [^>]*></iframe>#'; 
     preg_match($pattern, $html, $tempArray); 
     if(isset($tempArray[1])) 
     { 
      $embedUrl= "http:".$tempArray[1]; 
      //print_r($embedUrl); 
     $videoID = getDailyMotionVideoID($embedUrl); 
     $url = getDailyMotionMP4($videoID); 
     if(strcmp($url,"http")) 
      $buttontext="Play"; 
     $url=$proxy='http://127.0.0.1/umsp/plugins/pakfiles/pakfiles_proxy.php?r='. $url; 
     } 
    } 
    } 
    else 
    */ 
    { 
     //<source src="http://vmedia.gemsiptv.com/drama/nov_2015/635829254910520000.mp4" type='video/mp4' /> 



     //print_r("You Tube"); 
     //print_r($html); 

     //<source src="//api.smartrix.com/home/get?v=UnTBFVnNQYk" type='video/mp4' /> 
     $pattern = '#<source src="([^"]*)" [^>]*>#'; 
     preg_match($pattern, $html, $tempArray); 
     if(isset($tempArray[1])) 
      { 
       if(strcmp($tempArray[1],"mp4")) 
        { 
        $url=$tempArray[1]; 
        } 
       else 
        { 
        $temp="http:".$tempArray[1]; 
        $temp = explode("=", $temp); 
        $videoID=$temp[1]; 
        } 
      } 
     else 
      { 
      $html= preg_replace('/<iframe\s+[^>]*src\s*=\s*"([^"]+)"[^>]*>/', '<iframe src="\1">', $html); 
      $pattern = '#<iframe src="([^"]*)">#'; 
      preg_match($pattern, $html, $tempArray); 
      if(isset($tempArray[1])) 
       { 
       $videoID=getYouTubeVideoID($tempArray[1]); 
       } 
      } 

     if (yt_exists($videoID)) 
     { 
     $url = getYouTubeMovie($videoID); 
     $buttontext="Play"; 
     } 
     else if(strcmp($url,"mp4")) 
     { 
     $buttontext="Play"; 
     } 
     else 
     { 
     $buttontext="Video Not Found"; 
     $url="Not Found"; 
     //print_r("inside"); 
     } 

    } 

         $items[] = array(
          'id'    => 'Pakfiles', 
          'dc:title'  => $buttontext, 
          'upnp:class'  => 'object.item.videoItem', 
          'res'    => $url, 
          'protocolInfo' => 'http-get:*:*:*', 
         );  
} 

function getDailyMotionMP4($videoID) 
{ 

//print_r("videoid:::".$videoID); 
//$videoID="184449123"; 
//$html = file_get_contents('http://www.dailymotion.com/json/video/' . $videoID . '?fields=stream_h264_hd_url,stream_h264_hq_url,stream_h264_url,stream_h264_sd_url'); 
//print_r($html); 
/*preg_match_all('|"stream_h264_hd_url":"([^"]+)"|', $html, $HDURL);  //not supported 
preg_match_all('|"stream_h264_hq_url":"([^"]+)"|', $html, $HDURL);   
*/ 
$html = file_get_contents('http://www.dailymotion.com/embed/video/'.$videoID); 

$tempArray = explode('dmp.create(document.getElementById(\'player\'), ', $html); 
//print_r($tempArray[1]); 
$tempArray = explode('{}}});', $tempArray[1]); 
// dispatch event for embed used on dailymotion.com 
$jsonurl=$tempArray[0]."{}}}"; 
if(preg_match('/Content rejected/',$html)) 
{ 
    print_r("hi"); 
    return ""; 
} 

$json = json_decode($jsonurl, true); 
//var_dump($json); 
$video = $json['metadata']['qualities']; 
//print_r($video); 
if (array_key_exists('380', $video)) { 
    // print_r($video['380']['0']['url']); 
    $videoUrl=$video['380']['0']['url']; 
} 
else if (array_key_exists('480', $video)) { 
    // print_r($video['480']['0']['url']); 
    $videoUrl=$video['480']['0']['url']; 
} 
else if (array_key_exists('380', $video)) { 
    // print_r($video['380']['0']['url']); 
    $videoUrl=$video['380']['0']['url']; 
} 
else if (array_key_exists('240', $video)) { 
    //print_r($video['240']['0']['url']); 
    $videoUrl=$video['240']['0']['url']; 
} 

if($videoUrl != '') 
    { 
    $headers = get_headers($videoUrl, 1); 
    //print_r($headers); 
    $videoUrl = $headers['Location']; 
    }  
//print_r($videoUrl); 
    /////////////////////////////////////////////////////////////////////////////////// 
return $videoUrl; 
} 

function getDailyMotionVideoID($url) 
{ 
//http://www.dailymotion.com/embed/video/x2r1r6f?autoPlay=1&syndication=262479 
$pattern = '#http://www.dailymotion.com/embed/[^/]*/([^\?]*)?[^"]*#'; 

preg_match($pattern, $url, $tempArray); 

//print_r($tempArray); 

$videoID = $tempArray[1]; 

return $videoID; 
} 


function yt_exists($videoID) { 
    $theURL = "http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=$videoID&format=json"; 
    $headers = get_headers($theURL); 

    if (substr($headers[0], 9, 3) !== "404") { 
     return true; 
    } else { 
     return false; 
    } 
} 

function getYouTubeVideoID($url) 
{ 
$pattern = '#^.*((youtu.be/)|(v/)|(/u/\w/)|(embed/)|(watch\?))\??v?=?([^\#\&\?]*).*#'; 

preg_match($pattern, $url, $tempArray); 

//print_r($tempArray); 
$videoID = ''; 

if(isset($tempArray[7])) 
{ 
$videoID = $tempArray[7]; 
} 
//print_r($videoID); 
return $videoID; 
} 

function getYouTubeMovie($videoID) 
{ 
$returnValue = ''; 

$url = 'http://youtube.com/get_video_info?video_id='; 
$key = 'url_encoded_fmt_stream_map'; 
$content = file_get_contents($url . $videoID); 

parse_str($content,$videoParams); 
//print_r($videoParams); 
if(isset($videoParams['reason'])) 
{ 
return 'Error: ' . $videoParams['reason']; 
} 

$videoURLs = explode(',', $videoParams[$key]); 
foreach($videoURLs as $vURL) 
{ 
$sURL = $vURL; 

parse_str($sURL, $urlParams); 
$type = $urlParams['type']; 

$tempArray = explode(';', $type); 
$tempArray2 = explode('/', $tempArray[0]); 
$videoFormat = $tempArray2[1]; 
$quality = $urlParams['quality']; 

$sURL = $urlParams['url']; 
if(isset($urlParams['sig'])) 
{ 
$sURL .= '&signature=' . $urlParams['sig']; 
} 

//  echo($sURL . "\n\n"); 
//print_r($videoFormat); 
//print_r($sURL); 
if($videoFormat == 'mp4') 
{ 
//return the first mp4 - hopefully, the best quality 
$returnValue = $sURL; 
break; 
} 
$returnValue[] = array('url' => $sURL, 
       'videoFormat' => $videoFormat, 
       'quality' => $quality 
      ); 
} 
//echo $html; 
return $returnValue; 
} 

?> 

回答

0

未定义的偏移意味着您尝试访问第167行的数组条目,其索引0不存在。例如,当你有一个数组$ array = [1,2,3],并且你试图$ array [4]时,这会在错误时产生,因为数组中不存在第四个索引。

+0

“某处” =错误消息中的文件和行。 – AD7six

+0

正确,我会编辑我的答案。 @ AD7six – markvdlaan93

0

你应该减少你的问题到最小可重复的代码。它看起来像你的错误在这行抛出:

'id'=> "umsp://plugins/pakfiles?episode=".urlencode($epis[0][1])."&amp;title=".urlencode($title), 

检查$epis包含在索引0的东西一般情况下,你可以使用print_r功能显示有关数组的详细信息:

print_r($epis);