000
23.07.2006, 05:10 Uhr
Marcel86
|
Hallo,
Ich bastel zur Zeit an einem Shoutcast – Streamripper und werde bald wahnsinnig Mein Problem ist es das ich nicht ganz genau weis wie ich die Mp3 richtig zusammensetze. Als Hilfe habe ich folgende Seite genutzt: www.smackfu.com/stuff/programming/shoutcast.html
Statt den normalen Sound höre ich nur etwa 1-2 Sekunden haken und dann stoppt die Wiedergabe.
Vielleicht hat einer von euch ja bereits ähnliches getan und könnte mal über meinen (Anfänger)-Code gucken
C++: |
#include <windows.h> #include <winsock.h> #include <stdio.h> #include <stdlib.h>
void perr_exit(char* msg, int ret_code) { printf("%s, Error: ",msg); printf("%d\n",ret_code); exit(ret_code); }
int main(int argc, char** argv) { char* url; char* site; char* host; char buf[1024]; char send_buf[256]; char recv_buf[99999]; long rc; FILE* target_file; char uses_file=0; char* write_ptr; SOCKET s; SOCKADDR_IN addr; WSADATA wsa; HOSTENT* hent; int i = 0; int length; char* wt; char work[512]; int file_write = 0; int test = 0; int bytecount = 0; int remember = 0;
if(WSAStartup(MAKEWORD(2,0),&wsa)) perr_exit("WSAStartup failed",WSAGetLastError());
addr.sin_family=AF_INET; addr.sin_port=htons(80);
strcpy(buf,"http://64.236.34.196/stream/1025"); url=buf;
if(!(target_file=fopen("c:\\test.mp3","w"))) { printf("Cannot open File "); perr_exit(argv[2],GetLastError()); }
if(strncmp("http://",url,7)==0) host=url+7; else host=url;
if((site=strchr(host,'/'))!=0) *site++='\0'; else site=host+strlen(host); /* \0 */
printf("Host: %s\n",host); printf("Site: %s\n",site); printf("Connecting....\n");
if((addr.sin_addr.s_addr=inet_addr(host))==INADDR_NONE) { if(!(hent=gethostbyname(host))) perr_exit("Cannot resolve Host",WSAGetLastError());
strncpy((char*)&addr.sin_addr.s_addr,hent->h_addr,4);
if(addr.sin_addr.s_addr==INADDR_NONE) perr_exit("Cannot resolve Host",WSAGetLastError()); }
if((s=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET) perr_exit("Cannot create Socket",WSAGetLastError());
if( connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR))) perr_exit("Cannot connect",WSAGetLastError());
printf("Connected to %s...\n",host);
sprintf(send_buf,"GET /stream/1025 HTTP/1.0\r\nHost: 64.236.34.196\r\nUser-Agent: WinampMPEG/5.21\r\nAccept: */*\r\nIcy-MetaData:1\r\nConnection: close\r\n\r\n");
if((send(s,send_buf,strlen(send_buf),0))<strlen(send_buf)) perr_exit("Cannot send Data",WSAGetLastError());
while(rc=recv(s,recv_buf,9192,0)) { recv_buf[rc]='\0'; write_ptr = recv_buf; if(wt=strstr(recv_buf,"icy-metaint:")) { int xo = 0; strcpy(work,wt+13); while(work[xo] != '\0') {xo++;} work[xo] = '\0'; length = atoi(work); printf("LAENGE : %d\n\n",length); } if(test) { file_write = 1; } if(file_write) { i=0; if(remember!=0) { i+= remember; remember=0; } while(i < rc) { if(bytecount == length) { printf("\nWERT = %d",recv_buf[i]*16); bytecount = -1; if(recv_buf[i] > 0){ i += (recv_buf[i]*16); } if(i > rc) remember = i - rc; } else { write_ptr = recv_buf; write_ptr += i; fwrite(write_ptr,1,1,target_file); } i++; bytecount++; } } else { test = 1; printf("%s",recv_buf); } }
fclose(target_file); closesocket(s); return 0; }
|
Wäre für jeden Tip riesig dankbar. Bin mir auch nciht ganz sicher ob ich an der richtigen Stelle anfange die MP3-DatenBytes zu zählen ... brauch dringend Hilfe
danke schonmal |