%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/www_bck/varak.net_bck/wow2.varak.net/xml/
Upload File :
Create Path :
Current File : //data/www_bck/varak.net_bck/wow2.varak.net/xml/lfmget.php

<?php

  function download_file($url)
  {
    $ch = curl_init($url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.9.1 (i386--Gentoo) libcurl 7.9.1 (OpenSSL 0.9.6a)");
    $ret = curl_exec($ch);
    curl_close($ch);
    return (string)$ret;
  }

  // CONFIG
  $key = "72b681b906e65badd51629d23d72c907";
  $limit = 10;

  header("Content-type: text/plain");
  //error_reporting(0);
  include("../lib.php");
  $tzac=getmicrotime();
  $usrs = file("recent.usr");
  if($_GET['usr'])
  {
    $usrs = array($_GET['usr']);
  }
  if($_GET['limit'])
  {
    $limit = $_GET['limit'];
  }

  $count = 0;

  //$spojeni = sqlite_open("recent2.db");

  $spojeni = mysql_connect("localhost", "waritko", "blade666");
  mysql_select_db("waritko_horde", $spojeni);
  
  $lc = 0;
  $mid = trim(file_get_contents("waritko.max"));
  $txt = download_file("http://vserver.varak.net/lfmlist.php?id=$mid");
  $lines = explode("\n", $txt);
  foreach($lines as $l)
  {
    $l = trim($l);
    $l = str_replace("'", "\\'", $l);
    if($l == "") continue;
    $r = explode("|", $l);
    $query = "insert into recent(artist, album, track, time, user, len) values('$r[1]', '$r[2]', '$r[0]', $r[3], 'waritko', $r[5])";
    //echo $query.";\n";
    mysql_query($query);
    $lc++;
    $mid = $r[4] > $mid ? $r[4] : $mid;
  }
  file_put_contents("waritko.max", $mid);
  echo "Waritko: $lc\n";


  // Awmade
  $lc = 0;
  $mid = trim(file_get_contents("awmade.max"));
  $txt = download_file("http://vserver.varak.net/lfmlist_awmade.php?id=$mid");
  $lines = explode("\n", $txt);
  foreach($lines as $l)
  {
    $l = trim($l);
    $l = str_replace("'", "\\'", $l);
    if($l == "") continue;
    $r = explode("|", $l);
    $query = "insert into recent(artist, album, track, time, user, len) values('$r[1]', '$r[2]', '$r[0]', $r[3], 'awmade', $r[5])";
    //echo $query.";\n";
    mysql_query($query);
    $lc++;
    $mid = $r[4] > $mid ? $r[4] : $mid;
  }
  file_put_contents("awmade.max", $mid);
  echo "Awmade: $lc\n";

foreach($usrs as $usr)
{
	$usr = trim($usr);
	$data = array();
	$lc = 0;
	$done = false;
	$llimit = $limit;
	$result = mysql_query("select max(time) from recent where user like '$usr'", $spojeni);
  $last = mysql_fetch_row($result);
  $last = $last[0];
  $last = time()-14*24*3600; // max 14 dni dozadu
  //echo $last; die;
  $i = 1;

	while(!$done)
	{
	  $cnt = 0;
    $recent = download_file("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=$usr&api_key=$key&limit=10&page=$i");
    $res = simplexml_load_string($recent);
    //print_r($res);
    foreach($res->recenttracks->track as $item)
    {
      if(strtotime($item->date) < $last) continue;
      $artist = str_replace("'", "''", $item->artist);
      $album = str_replace("'", "''", $item->album);
      $track = str_replace("'", "''", $item->name);
      $time = strtotime($item->date)+3600;
      if($time != $last)
      {
        //sqlite_query($spojeni, "insert into recent(artist, album, track, time, user) values('$artist', '$album', '$track', $time, '$usr')");
        $query = "insert into recent(artist, album, track, time, user) values('$artist', '$album', '$track', $time, '$usr')";
        mysql_query($query);
        if(mysql_affected_rows() > 0)
        {
          $cnt += mysql_affected_rows();
        }
//        $lc++;
      }
    }
    /*if($lc < $llimit)
    {
      $done = true;
    }
    else
    {
      $data = array();
      $llimit *= 3;
      $lc = 0;
      $done = false;
    } */
    $lc += $cnt;
    if($cnt > 0)
    {
      $i++;
    }
    else
    {
      $done = true;
    }
    if($i > 10) break;
  }
  $count += $lc;
  $st = getmicrotime();
/*  foreach($data as $l)
  {
    // Samotne provedeni SQL prikazu
    mysql_query($l, $spojeni);
  }*/
  $skt = getmicrotime();
  $qt=$skt-$st;
  $qt = sprintf("%01.4f", $qt);
  //echo "Llimit: $llimit\n";
  //print_r($data);
  echo "$usr: $lc (Llimit: $llimit; time: $qt)\n";
}
echo "\n\n";
  mysql_close($spojeni);
  $mem = sprintf("%01.2f", memory_get_peak_usage(true)/(1024*2024));
  $tkon=getmicrotime();
  $time=$tkon-$tzac;
  $time = sprintf("%01.4f", $time);
  echo "Hotovo, importovano $count prehranych pisnicek\nImport trval $time sekund, bylo pouzito $mem MB pameti";
?>

Zerion Mini Shell 1.0