function get(anz){
this.downloadanz = anz; //Anzahl der zeitgleichen Downloads
this.i = 0; //Nummer des Aktuellen Request
this.nr = 0; //Nummer des Aktuellen Request für widerchronologische Anfragem
this.download = new Array(this.downloadanz); //Jedes Array-Element enthält ein Array mit allen titeln eines Requests
this.img = new Array(this.downloadanz); //alle Link zu Standardcovern (126x126)
this.ignor = null; //Array mit allen zu ignorierenden Titeln
this.timeouts = new Array(); //ID sämmtlicher Timeouts
//Frames zum Donwload einhängen
var e,ee;
e=document.createElement("frameset");
e.border = 0;
e.framespacing = 0;
e.cols = 0;
e.id = "Frameset";
e.style.display = "display: none !important";
document.getElementsByTagName('html')[0].appendChild(e);
for(var u=0; u<this.downloadanz; u++){
e = document.createElement("frame");
e.frameborder = "0"
e.id = 'saveFrame'+u;
ee = document.createElement("frame");
ee.frameborder = "0"
ee.id = 'saveFrame'+u+"img";
document.getElementById('Frameset').appendChild(e);
document.getElementById('Frameset').appendChild(ee);
}
this.request = function (){
if(this.request.arguments.length<1){
if(this.i>=this.downloadanz)return false;
this.nr = this.i++;
}else{
this.nr = this.request.arguments[0];
this.download[this.nr]=0;
}
if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}else if(window.ActiveXObject){
http = new ActiveXObject("Microsoft.XMLHTTP");
}
http.open('GET', 'test.php', true);
http.onreadystatechange = function(){
var response, i, e;
if(http.readyState==4){
try{
response = eval("(" + http.responseText + ")");//http.responseText ist ein JSON-Array mit folgendem Aufbau: array['Eigenschaft'][nr]
}catch(e){}
get.download[get.nr] = new Array();
get.img[get.nr] = new Array();
http = null;
if(!response)get.request(get.nr);//Falls kein Ergebnis zurückgegeben wurde oder dies Fehlerhaft war, wird es erneut versucht
if(typeof(response)=='object'){
if(typeof(get.download[this.nr])!='object')get.download[this.nr]=new Array();
for(i=0; i<response['title'].length; i++){
if(response['title'][i]=='' || response['creator'][i]==''){
continue;
}else{
saveas=(response['album'][i]=='')?response['creator'][i]+' - '+response['title'][i]+'.mp3':
response['creator'][i]+' - '+response['title'][i]+' - '+response['album'][i]+'.mp3';
}
//Daten in Array speichern
get.download[get.nr].push([response['location'][i], saveas, response['duration'][i]]);
get.img[get.nr].push([response['image'][i], response['creator'][i]+' - '+response['album'][i]+response['image'][i].substr(response['image'][i].lastIndexOf('.'))]);
}
get.load(get.nr);
get.request();
}
}
return true;
}
http.send(null);
return true;
}
this.load = function(requestNr){
var title, img;
if(this.download[requestNr].length==0){
this.request(requestNr);
return false;
}
title = this.download[requestNr].pop();
img = this.img[requestNr].pop();
this.timeouts.push(setTimeout('get.load('+requestNr+')', (1000*title[2])));
document.getElementById("saveFrame"+requestNr+"img").src="test.php?mode=save&link="+img[0]+"&saveas="+img[1];
document.getElementById("saveFrame"+requestNr).src="test.php?mode=save&link="+title[0]+"&saveas="+title[1];
}
this.stop = function(){
for(var i=0; i<this.timeouts.length; i++)
clearTimeout(this.timeouts[i]);
return true;
}
this.request();
}
var get=new get(6);