Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd> //Credits to Zeex (http://forum.sa-mp.com/showthread.php?t=91354)
- #include <sscanf2> //Credits to Y_Less (http://forum.sa-mp.com/showthread.php?t=120356)
- #include <pwncurl> //Credits to DracoBlue (http://forum.sa-mp.com/showthread.php?t=72260)
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 50 //number of server slots
- #define MDIALOG 23345 //change it if needed
- #define COLOR_RED 0xFF0000FF
- #define COLOR_YELLOW 0xFFDD00FF
- #define COLOR_BLUE 0xF6BB0FF
- #define COLOR_ORANGE 0xFF9900FF
- new cstring[MAX_PLAYERS][16][256]; //max. number of songs links found = 16
- new cstring2[MAX_PLAYERS][16][128]; //max. number of songs names found = 16
- new dstring[2048]; //dialog string
- new content[16384]; //data read from webpage
- new available[MAX_PLAYERS] = {0, ...}; //number of found song links results
- new lastsearch[MAX_PLAYERS][128]; //used to check if player is searching the same song name and avoid useless new searches
- //Note: You can reduce/increase string sizes depending on the amount of songs you want appearing in the list.
- public OnFilterScriptInit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++) format(lastsearch[i], 128, " ");
- print(":: Music Searcher and Reproducer by Riccor Loaded!");
- return 1;
- }
- public OnFilterScriptExit()
- {
- print(":: Music Searcher and Reproducer by Riccor Unloaded!");
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_NO)
- {
- StopAudioStreamForPlayer(playerid);
- GameTextForPlayer(playerid,"~w~Music ~r~OFF", 2000, 3);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == MDIALOG) if(response)
- {
- PlayAudioStreamForPlayer(playerid, cstring[playerid][listitem]);
- SendClientMessage(playerid, COLOR_YELLOW, ":: Press N to stop music.");
- }
- return 0;
- }
- CMD:music(playerid, params[])
- {
- if(sscanf(params, "s[128]", params))
- {
- SendClientMessage(playerid, COLOR_BLUE, "USAGE: /music [Name]");
- SendClientMessage(playerid, COLOR_ORANGE, "Function: Will search and reproduce the specified song if it exist.");
- return 1;
- }
- new url[160], flag = 0, flag2 = 0, size, size2, k, j, address[256];
- if(strcmp(params, lastsearch[playerid], true))
- {
- available[playerid] = 0;
- j = 0;
- format(lastsearch[playerid], 128, "%s", params);
- format(url, 160, "mp3skull.com/mp3/%s.html", params);
- pwncurl_get(url, content, 16384); //read webpage
- for(new d = 0; d < 16 ; d++) format(cstring[playerid][d], 256, " "); //clean array information
- for(new d = 0; d < 16 ; d++) format(cstring2[playerid][d], 128, " "); //clean array information
- for(new f = 0; f < 16384-7 ; f++)
- {
- //look for "http://"
- if(content[f] == 'h' && content[f+1] == 't' && content[f+2] == 't' && content[f+3] == 'p'
- && content[f+4] == ':' && content[f+5] == '/' && content[f+6] == '/')
- {
- flag = 1; //now we can search for a ".mp3"
- size = f; //regist the begin of song address
- f = f+7; //doesn't matter to check the same characters again
- continue;
- }
- if(flag == 1)
- {
- //look for ".mp3"
- if(content[f] == '.' && content[f+1] == 'm' && content[f+2] == 'p' && content[f+3] == '3')
- {
- if(available[playerid] + 1 > 15) break; //limit reached
- format(address, 256, " ");
- k = 0;
- for(new g = size; g < f+4; g++) //copy string information
- {
- address[k] = content[g];
- k++;
- }
- address[k] = '\0'; //finalize string
- flag = 0;
- f = f+4;
- if(strcmp(address, "http://ac.mp3", true) && strcmp(address, "http://static.mp3", true)) //acceptable results?
- {
- format(cstring[playerid][available[playerid]], 256, "%s", address);
- available[playerid]++;
- }
- }
- }
- //look for "<b>"
- if(content[f] == '<' && content[f+1] == 'b' && content[f+2] == '>')
- {
- flag2 = 1; //now we can search for a "</b>"
- size2 = f; //regist the begin of song name
- f = f+3; //doesn't matter to check the same characters again
- continue;
- }
- if(flag2 == 1)
- {
- //look for "</b>"
- if(content[f] == '<' && content[f+1] == '/' && content[f+2] == 'b' && content[f+3] == '>')
- {
- if(j + 1 > 15) break; //limit reached
- format(address, 256, " ");
- k = 0;
- for(new g = size2+3; g < f-4; g++) //copy string information
- {
- address[k] = content[g];
- k++;
- }
- address[k] = '\0'; //finalize string
- flag2 = 0;
- f = f+4;
- format(cstring2[playerid][j], 128, "%s", address);
- j++;
- }
- }
- }
- }
- if(available[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, ":: Sorry, there's no songs with the specified name!");
- for(new f = 0; f < available[playerid]; f++)
- {
- if(f == 0) format(dstring, 2048, "%s", cstring2[playerid][f]);
- else format(dstring, 2048, "%s\n%s", dstring, cstring2[playerid][f]);
- }
- new title[128]; format(title, 128, ":: Results for {FF6400}'%s':", params);
- ShowPlayerDialog(playerid, MDIALOG, DIALOG_STYLE_LIST, title, dstring, "Play!", "Close");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment