Markus Rechberger / Wazee Rater
 
StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern

Veränderung (zum vorhergehenden Autor) (Änderung, Korrektur, Normalansicht)

Verändert: 1c1,314
Beschreibe hier die neue Seite.
== Wazee Rater ==

Aufgabenstellung:
Es handelt sich um eine Taskbar welche den derzeitig laufenden Song, das derzeitige Listenerrating und Album Informationen anzeigt. Bei Inaktivität(z.B.: wenn die Maus den Programmbereich verlässt) soll sich das Plugin wieder ausblenden. Die Streamdaten werden mittels HTTP vom Streaming Server abgerufen. Das GTK Frontend wird mittels Glade 2 erstellt.

Inputdaten:
[[Code]
msid=391;song=Icarus%20%28unmastered%29;artist=Hopesfall;rating=<span class="ArialBoldTitle?">5</span><span class="arialBold"></span><span class="tinylinksgrey">/6 by 1 listener</span>;albumSRC=http%3A%2F%2Fwww.wazee.org%2Fimages%2Fcover.jpg.php%3Fmsid%3D391;productLink=http%3A%2F%2Fwww.amazon.com%2Fexec%2Fobidos%2FASIN%2FB000793ANS%2Fradiowazee-20%3Fdev-t%3DD2WMCOIPS9D14E%2526camp%3D2025%2526link_code%3Dxm2;albumTitle=%22A%20Types%20%28%2B2%20Bonus%20Tracks%29%20%28Enhanced%29%22%20-%20Your%20purchase%20from%20Amazon%20supports%20Wazee;displayTime=-86;nextPacket=143;flexibility=17
]

Inputdaten sortiert:
[[Code]
msid=391;
song=Icarus%20%28unmastered%29;
artist=Hopesfall;
rating=<span class="ArialBoldTitle?">5</span><span class="arialBold"></span><span class="tinylinksgrey">/6 by 1 listener</span>;
albumSRC=http%3A%2F%2Fwww.wazee.org%2Fimages%2Fcover.jpg.php%3Fmsid%3D391;
productLink=http%3A%2F%2Fwww.amazon.com%2Fexec%2Fobidos%2FASIN%2FB000793ANS%2Fradiowazee-20%3Fdev-t%3DD2WMCOIPS9D14E%2526camp%3D2025%2526link_code%3Dxm2;albumTitle=%22A%20Types%20%28%2B2%20Bonus%20Tracks%29%20%28Enhanced%29%22%20-%20Your%20purchase%20from%20Amazon%20supports%20Wazee;
displayTime=-86;
nextPacket=143;
flexibility=17
]

Songparser:

[[Code]
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include "urldecode.h"

struct MemoryStruct? {
char *memory;
size_t size;
};

typedef struct wazeedata wazeedata;
struct wazeedata{
char *key;
char *payload;
wazeedata *next;
wazeedata *last;
};


void wazee_addstruct(char *data,wazeedata **wz_data){
char *key=0;
char *payload=0;
int payloaddata=0;
int i;
wazeedata *inarray;
wazeedata *nextelem;
for(i=0;data[i]!=0;i++){
if(data[i]=='='){
payloaddata=1;
} else {
if(payloaddata==0){
if(key){
key=(char*)realloc(key,strlen(key)+2);
key[strlen(key)+1]=0;
key[strlen(key)]=data[i];
} else {
key=(char*)malloc(2);
key[0]=data[i];
key[1]=0;
}
} else {
if(payload){
payload=(char*)realloc(payload,strlen(payload)+2);
payload[strlen(payload)+1]=0;
payload[strlen(payload)]=data[i];
} else {
payload=(char*)malloc(2);
payload[0]=data[i];
payload[1]=0;
}
}
}
}
urldecode(key);
urldecode(payload);
if((*wz_data)==0){
(*wz_data)=(wazeedata*)malloc(sizeof(wazeedata));
(*wz_data)->key=key;
(*wz_data)->payload=payload;
(*wz_data)->next=NULL;
(*wz_data)->last=(*wz_data);
} else {
nextelem=(wazeedata*)malloc(sizeof(wazeedata));
nextelem->key=key;
nextelem->payload=payload;
nextelem->next=NULL;
nextelem->last=nextelem;
(*wz_data)->last->next=nextelem;
(*wz_data)->last=nextelem;
}

}


void wazee_split(char *indata,char delim, wazeedata **wz_inarray){
int i;
char *data=0;
wazeedata *inarray = (*wz_inarray);
for(i=0;indata[i]!=0;i++){
if(indata[i]==delim){
wazee_addstruct(data,&inarray);
if(data){
free(data);
data=0;
}
} else {
if(data){
data=(char*)realloc(data,strlen(data)+2);
data[strlen(data)+1]=0;
data[strlen(data)]=indata[i];
} else {
data=(char*)malloc(2);
data[0]=indata[i];
data[1]=0;
}
}
}
(*wz_inarray)=inarray;
}

void *myrealloc(void *ptr, size_t size){
if(ptr)
return (void*)realloc(ptr,size);
else
return (void*)malloc(size);
}

size_t memcallback(void *ptr, size_t size, size_t nmemb, void *data){
size_t realsize = size * nmemb;
struct MemoryStruct? *mem=(struct MemoryStruct? *)data;

mem->memory = (char*)myrealloc(mem->memory,mem->size + realsize + 1);
if(mem->memory){
memcpy(&(mem->memory[mem->size]),ptr,realsize);
mem->size += realsize;
mem->memory[mem->size]=0;
}
// mem->memory =
return(realsize);
}

char *wazee_parse(wazeedata **indata,char *key){
wazeedata *iterator;
iterator=(*indata);
if(iterator!=0){
for(iterator=(*indata);iterator!=NULL&&strcmp(iterator->key,key)!=0;iterator=iterator->next);
if(iterator!=NULL){
return(iterator->payload);
} else {
return(NULL);
}
}
return(NULL);
}

char *wazee_filtertags(char *data){
char *returndata;
int i,x,_switch=0;
if(data!=0){
x=0;
returndata=(char*)malloc(strlen(data));
for(i=0;i<=strlen(data);i++){
if(data[i]=='<'){
_switch=1;
}
if(_switch==1&&data[i]=='>'){
_switch=0;
} else {
if(_switch==0){
returndata[x]=data[i];
x++;
}
}
}
return(returndata);
}
return(NULL);
}

size_t wazee_save_cover(void *ptr, size_t size, size_t nmemb, void *data){
size_t realsize = size * nmemb;
struct MemoryStruct? *mem=(struct MemoryStruct? *)data;
FILE *imagefile;

mem->memory = (char*)myrealloc(mem->memory,mem->size + realsize + 1);
if(mem->memory){
memcpy(&(mem->memory[mem->size]),ptr,realsize);
mem->size += realsize;
mem->memory[mem->size]=0;
}
imagefile=fopen("test.jpg","a+");
fwrite(ptr,size,nmemb,imagefile);
fclose(imagefile);

printf("returned %d bytes\n",realsize);
return(realsize);
}

void wazee_fetch_cover(char *url){
CURL *curl;
CURLcode res;
struct MemoryStruct? chunk;
chunk.memory = NULL;
chunk.size = 0;
printf("trying to fetch url: %s\n",url);
curl=curl_easy_init();
curl_easy_setopt(curl,{CURLOPT URL}?,url);
curl_easy_setopt(curl,{CURLOPT WRITEFUNCTION}?, wazee_save_cover);
curl_easy_setopt(curl, {CURLOPT USERAGENT}?, "wazee-xmms taskbarvoter/testing..");
curl_easy_setopt(curl, {CURLOPT WRITEDATA}?,(void *)&chunk);
res=curl_easy_perform(curl);
}

wazeedata *fetchdata(void){
CURL *curl;
CURLcode res;
char wazeelink[100];
struct MemoryStruct? chunk;
wazeedata *returndata=0;
wazeedata *iterator=0;
chunk.memory = NULL;
chunk.size = 0;
char *data;

curl = curl_easy_init();
sprintf(wazeelink," http://www.wazee.org/bg_transport/currSong.php?clientTime=1108897128");
if(curl){
curl_easy_setopt(curl,{CURLOPT URL}?,wazeelink);
curl_easy_setopt(curl, {CURLOPT WRITEFUNCTION}?, memcallback);
curl_easy_setopt(curl, {CURLOPT USERAGENT}?, "wazee-xmms taskbarvoter/testing..");
curl_easy_setopt(curl, {CURLOPT WRITEDATA}?, (void *)&chunk);
res=curl_easy_perform(curl);
printf("chunk: %s\n",chunk.memory);
if(chunk.size!=0){
wazee_split(chunk.memory,';',&returndata);
}

curl_easy_cleanup(curl);
}
return(returndata);
}
]

Syntax:
[[Code]
wazeedata *songdata;
songdata = fetchdata();
(char*)=wazee_parse(&songdata,"song");
]

Rating:
[[Code]
POST /bg_transport/recordRating.php?clientTime=1108918933 HTTP/1.1
Host: www.wazee.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041102 Firefox/1.0RC1 (Debian package 0.99+1.0RC1-3)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 18
Cookie: wazeeforum04=<L/P ID>; PHPSESSID=784cfa6eb54de9553a401c0cf9b0ab9a
Pragma: no-cache
Cache-Control: no-cache

msid=1602&rating=3
]

[[Code]
POST /bg_transport/rateSong.php?msid=current&clientTime=1108919845 HTTP/1.1
Host: www.wazee.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041102 Firefox/1.0RC1 (Debian package 0.99+1.0RC1-3)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
Cookie: PHPSESSID=453aaed268faf1be48ba2abb9a2008e4
Pragma: no-cache
Cache-Control: no-cache

{YaBB username}?=revenger&{YaBB password}?=muh

Antwort:

HTTP/1.1 200 OK
Date: Sun, 20 Feb 2005 17:15:18 GMT
Server: Apache
X-Powered-By: PHP/5.0.3
Set-Cookie: <ID Cookie> welche wichtig is für's rating
expires=Mon, 20-Feb-06 17:15:18 GMT; path=/
X-Item-Title: listener.rating
X-Song-ID: 2085
X-Rating: <span class="ArialBoldTitle?">4</span><span class="arialBold">.4</span><span class="tinylinksgrey">/6 by 5 listeners</span>
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 1037
Keep-Alive: timeout=15, max=71
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1
]
free's kommen später noch.. :-)

Wazee Rater

Aufgabenstellung: Es handelt sich um eine Taskbar welche den derzeitig laufenden Song, das derzeitige Listenerrating und Album Informationen anzeigt. Bei Inaktivität(z.B.: wenn die Maus den Programmbereich verlässt) soll sich das Plugin wieder ausblenden. Die Streamdaten werden mittels HTTP vom Streaming Server abgerufen. Das GTK Frontend wird mittels Glade 2 erstellt.

Inputdaten:
msid=391;song=Icarus%20%28unmastered%29;artist=Hopesfall;rating=<span class="ArialBoldTitle">5</span><span class="arialBold"></span><span class="tinylinksgrey">/6 by 1 listener</span>;albumSRC=http%3A%2F%2Fwww.wazee.org%2Fimages%2Fcover.jpg.php%3Fmsid%3D391;productLink=http%3A%2F%2Fwww.amazon.com%2Fexec%2Fobidos%2FASIN%2FB000793ANS%2Fradiowazee-20%3Fdev-t%3DD2WMCOIPS9D14E%2526camp%3D2025%2526link_code%3Dxm2;albumTitle=%22A%20Types%20%28%2B2%20Bonus%20Tracks%29%20%28Enhanced%29%22%20-%20Your%20purchase%20from%20Amazon%20supports%20Wazee;displayTime=-86;nextPacket=143;flexibility=17

Inputdaten sortiert:
msid=391;
song=Icarus%20%28unmastered%29;
artist=Hopesfall;
rating=<span class="ArialBoldTitle">5</span><span class="arialBold"></span><span class="tinylinksgrey">/6 by 1 listener</span>;
albumSRC=http%3A%2F%2Fwww.wazee.org%2Fimages%2Fcover.jpg.php%3Fmsid%3D391;
productLink=http%3A%2F%2Fwww.amazon.com%2Fexec%2Fobidos%2FASIN%2FB000793ANS%2Fradiowazee-20%3Fdev-t%3DD2WMCOIPS9D14E%2526camp%3D2025%2526link_code%3Dxm2;albumTitle=%22A%20Types%20%28%2B2%20Bonus%20Tracks%29%20%28Enhanced%29%22%20-%20Your%20purchase%20from%20Amazon%20supports%20Wazee;
displayTime=-86;
nextPacket=143;
flexibility=17

Songparser:

#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include "urldecode.h"

struct MemoryStruct {
        char *memory;
        size_t size;
};

typedef struct wazeedata wazeedata;
struct wazeedata{
        char *key;
        char *payload;
        wazeedata *next;
        wazeedata *last;
};


void wazee_addstruct(char *data,wazeedata **wz_data){
        char *key=0;
        char *payload=0;
        int payloaddata=0;
        int i;
        wazeedata *inarray;
        wazeedata *nextelem;
        for(i=0;data[i]!=0;i++){
                if(data[i]=='='){
                        payloaddata=1;
                } else {
                        if(payloaddata==0){
                                if(key){
                                        key=(char*)realloc(key,strlen(key)+2);
                                        key[strlen(key)+1]=0;
                                        key[strlen(key)]=data[i];
                                } else {
                                        key=(char*)malloc(2);
                                        key[0]=data[i];
                                        key[1]=0;
                                }
                        } else {
                                if(payload){
                                        payload=(char*)realloc(payload,strlen(payload)+2);
                                        payload[strlen(payload)+1]=0;
                                        payload[strlen(payload)]=data[i];
                                } else {
                                        payload=(char*)malloc(2);
                                        payload[0]=data[i];
                                        payload[1]=0;
                                }
                        }
                }
        }
        urldecode(key);
        urldecode(payload);
        if((*wz_data)==0){
                (*wz_data)=(wazeedata*)malloc(sizeof(wazeedata));
                (*wz_data)->key=key;
                (*wz_data)->payload=payload;
                (*wz_data)->next=NULL;
                (*wz_data)->last=(*wz_data);
        } else {
                nextelem=(wazeedata*)malloc(sizeof(wazeedata));
                nextelem->key=key;
                nextelem->payload=payload;
                nextelem->next=NULL;
                nextelem->last=nextelem;
                (*wz_data)->last->next=nextelem;
                (*wz_data)->last=nextelem;
        }

}


void wazee_split(char *indata,char delim, wazeedata **wz_inarray){
        int i;
        char *data=0;
        wazeedata *inarray = (*wz_inarray);
        for(i=0;indata[i]!=0;i++){
                if(indata[i]==delim){
                        wazee_addstruct(data,&inarray);
                        if(data){
                                free(data);
                                data=0;
                        }
                } else {
                        if(data){
                                data=(char*)realloc(data,strlen(data)+2);
                                data[strlen(data)+1]=0;
                                data[strlen(data)]=indata[i];
                        } else {
                                data=(char*)malloc(2);
                                data[0]=indata[i];
                                data[1]=0;
                        }
                }
        }
        (*wz_inarray)=inarray;
}

void *myrealloc(void *ptr, size_t size){
        if(ptr)
                return (void*)realloc(ptr,size);
        else
                return (void*)malloc(size);
}

size_t memcallback(void *ptr, size_t size, size_t nmemb, void *data){
        size_t realsize = size * nmemb;
        struct MemoryStruct *mem=(struct MemoryStruct *)data;

        mem->memory = (char*)myrealloc(mem->memory,mem->size + realsize + 1);
        if(mem->memory){
                memcpy(&(mem->memory[mem->size]),ptr,realsize);
                mem->size += realsize;
                mem->memory[mem->size]=0;
        }
//      mem->memory = 
        return(realsize);
}

char *wazee_parse(wazeedata **indata,char *key){
        wazeedata *iterator;
        iterator=(*indata);
        if(iterator!=0){
                for(iterator=(*indata);iterator!=NULL&&strcmp(iterator->key,key)!=0;iterator=iterator->next);
                if(iterator!=NULL){
                        return(iterator->payload);
                } else {
                        return(NULL);
                }
        }
        return(NULL);
}

char *wazee_filtertags(char *data){
        char *returndata;
        int i,x,_switch=0;
        if(data!=0){
                x=0;
                returndata=(char*)malloc(strlen(data));
                for(i=0;i<=strlen(data);i++){
                        if(data[i]=='<'){
                                _switch=1;
                        }
                        if(_switch==1&&data[i]=='>'){
                                _switch=0;
                        } else {
                                if(_switch==0){
                                        returndata[x]=data[i];
                                        x++;
                                }
                        }
                }
                return(returndata);
        }
        return(NULL);
}

size_t wazee_save_cover(void *ptr, size_t size, size_t nmemb, void *data){
        size_t realsize = size * nmemb;
        struct MemoryStruct *mem=(struct MemoryStruct *)data;
        FILE *imagefile;

        mem->memory = (char*)myrealloc(mem->memory,mem->size + realsize + 1);
        if(mem->memory){
                memcpy(&(mem->memory[mem->size]),ptr,realsize);
                mem->size += realsize;
                mem->memory[mem->size]=0;
        }
        imagefile=fopen("test.jpg","a+");
        fwrite(ptr,size,nmemb,imagefile);
        fclose(imagefile);

        printf("returned %d bytes\n",realsize);
        return(realsize);
}

void wazee_fetch_cover(char *url){
        CURL *curl;
        CURLcode res;
        struct MemoryStruct chunk;
        chunk.memory = NULL;
        chunk.size = 0;
        printf("trying to fetch url: %s\n",url);
        curl=curl_easy_init();
        curl_easy_setopt(curl,CURLOPT_URL,url);
        curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, wazee_save_cover);
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "wazee-xmms taskbarvoter/testing..");
        curl_easy_setopt(curl, CURLOPT_WRITEDATA,(void *)&chunk);
        res=curl_easy_perform(curl);
}

wazeedata *fetchdata(void){
        CURL *curl;
        CURLcode res;
        char wazeelink[100];
        struct MemoryStruct chunk;
        wazeedata *returndata=0;
        wazeedata *iterator=0;
        chunk.memory = NULL;
        chunk.size = 0;
        char *data;

        curl = curl_easy_init();
        sprintf(wazeelink,"http://www.wazee.org/bg_transport/currSong.php?clientTime=1108897128"); 
        if(curl){
                curl_easy_setopt(curl,CURLOPT_URL,wazeelink);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memcallback);
                curl_easy_setopt(curl, CURLOPT_USERAGENT, "wazee-xmms taskbarvoter/testing..");
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
                res=curl_easy_perform(curl);
                printf("chunk: %s\n",chunk.memory);
                if(chunk.size!=0){
                        wazee_split(chunk.memory,';',&returndata);
                }

                curl_easy_cleanup(curl);
        }
        return(returndata);
}

Syntax:
wazeedata *songdata;
songdata = fetchdata();
(char*)=wazee_parse(&songdata,"song");

Rating:
POST /bg_transport/recordRating.php?clientTime=1108918933 HTTP/1.1
Host: www.wazee.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041102 Firefox/1.0RC1 (Debian package 0.99+1.0RC1-3)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 18
Cookie: wazeeforum04=<L/P ID>; PHPSESSID=784cfa6eb54de9553a401c0cf9b0ab9a
Pragma: no-cache
Cache-Control: no-cache

msid=1602&rating=3

POST /bg_transport/rateSong.php?msid=current&clientTime=1108919845 HTTP/1.1
Host: www.wazee.org
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041102 Firefox/1.0RC1 (Debian package 0.99+1.0RC1-3)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 43
Cookie: PHPSESSID=453aaed268faf1be48ba2abb9a2008e4
Pragma: no-cache
Cache-Control: no-cache

YaBB_username=revenger&YaBB_password=muh

Antwort:

HTTP/1.1 200 OK
Date: Sun, 20 Feb 2005 17:15:18 GMT
Server: Apache
X-Powered-By: PHP/5.0.3
Set-Cookie: <ID Cookie>  welche wichtig is für's rating
expires=Mon, 20-Feb-06 17:15:18 GMT; path=/
X-Item-Title: listener.rating
X-Song-ID: 2085
X-Rating: <span class="ArialBoldTitle">4</span><span class="arialBold">.4</span><span class="tinylinksgrey">/6 by 5 listeners</span>
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 1037
Keep-Alive: timeout=15, max=71
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1
free's kommen später noch.. :-)


StartSeite | MarkusRechberger/ | Neues | TestSeite | ForumSeite | Teilnehmer | Kategorien | Index | Hilfe | Einstellungen | Ändern
Text dieser Seite ändern (zuletzt geändert: 20. Februar 2005 18:23 (diff))
Suchbegriff: gesucht wird
im Titel
im Text