Пример #1
0
 function misc_download($url, $path = NULL, $use_tor = 0, $is_xml = 0)
 {
     if ($use_tor == 1) {
         $t = tor_get_contents($url);
     } else {
         //      if ($is_xml == 1)
         //        $t = simplexml_load_file ($url, 'SimpleXMLElement', LIBXML_NOCDATA);
         //      else
         $t = file_get_contents($url);
     }
     if ($is_xml == 1) {
         $t = simplexml_load_string($t, 'SimpleXMLElement', LIBXML_NOCDATA);
     }
     // DEBUG
     //  echo '<pre><tt>';
     //  print_r ($t);
     //  exit;
     if (!$t) {
         return $path ? -1 : NULL;
     }
     if ($path == NULL || $is_xml == 1) {
         return $t;
     }
     if (!($out = fopen($path, 'wb'))) {
         return $path ? -1 : NULL;
     }
     fwrite($out, $t);
     fclose($out);
     // error
     if (!file_exists($path)) {
         return $path ? -1 : NULL;
     }
     return $path ? 0 : NULL;
 }
Пример #2
0
 function misc_youtube_download($video_id, $use_tor = 0, $debug = 0)
 {
     $a = array();
     if (strstr($video_id, '?v=')) {
         $a[0] = misc_youtube_download_single($video_id, $debug);
     } else {
         if (strstr($video_id, 'http://')) {
             if ($use_tor) {
                 $xml = tor_get_contents($video_id);
                 $b = simplexml_load_string($xml);
             } else {
                 $b = simplexml_load_file($video_id);
             }
             if ($debug == 1) {
                 echo '<pre><tt>';
                 print_r($b);
                 echo '</tt></pre>';
             }
             for ($i = 0; isset($b->channel->item[$i]); $i++) {
                 $a[$i] = misc_youtube_download_single($b->channel->item[$i]->link, $use_tor, $debug);
             }
         } else {
             $a[0] = misc_youtube_download_single($video_id, $use_tor, $debug);
         }
     }
     return $a;
 }