Guest User

MusicSearcherReproducer2.1

a guest
Mar 19th, 2012
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd> //Credits to Zeex (http://forum.sa-mp.com/showthread.php?t=91354)
  3. #include <sscanf2> //Credits to Y_Less (http://forum.sa-mp.com/showthread.php?t=120356)
  4. #include <pwncurl> //Credits to DracoBlue (http://forum.sa-mp.com/showthread.php?t=72260)
  5.  
  6. #undef MAX_PLAYERS
  7. #define MAX_PLAYERS 50 //number of server slots
  8. #define MDIALOG 23345 //change it if needed
  9.  
  10. #define COLOR_RED 0xFF0000FF
  11. #define COLOR_YELLOW 0xFFDD00FF
  12. #define COLOR_BLUE 0xF6BB0FF
  13. #define COLOR_ORANGE 0xFF9900FF
  14.  
  15. new cstring[MAX_PLAYERS][16][256]; //max. number of songs links found = 16
  16. new cstring2[MAX_PLAYERS][16][128]; //max. number of songs names found = 16
  17. new dstring[2048]; //dialog string
  18. new content[16384]; //data read from webpage
  19. new available[MAX_PLAYERS] = {0, ...}; //number of found song links results
  20. new lastsearch[MAX_PLAYERS][128]; //used to check if player is searching the same song name and avoid useless new searches
  21. //Note: You can reduce/increase string sizes depending on the amount of songs you want appearing in the list.
  22.  
  23. public OnFilterScriptInit()
  24. {
  25. for(new i = 0; i < MAX_PLAYERS; i++) format(lastsearch[i], 128, " ");
  26. print(":: Music Searcher and Reproducer by Riccor Loaded!");
  27. return 1;
  28. }
  29.  
  30. public OnFilterScriptExit()
  31. {
  32. print(":: Music Searcher and Reproducer by Riccor Unloaded!");
  33. return 1;
  34. }
  35.  
  36. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  37. {
  38. if(newkeys & KEY_NO)
  39. {
  40. StopAudioStreamForPlayer(playerid);
  41. GameTextForPlayer(playerid,"~w~Music ~r~OFF", 2000, 3);
  42. }
  43. return 1;
  44. }
  45.  
  46. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  47. {
  48. if(dialogid == MDIALOG) if(response)
  49. {
  50. PlayAudioStreamForPlayer(playerid, cstring[playerid][listitem]);
  51. SendClientMessage(playerid, COLOR_YELLOW, ":: Press N to stop music.");
  52. }
  53. return 0;
  54. }
  55.  
  56. CMD:music(playerid, params[])
  57. {
  58. if(sscanf(params, "s[128]", params))
  59. {
  60. SendClientMessage(playerid, COLOR_BLUE, "USAGE: /music [Name]");
  61. SendClientMessage(playerid, COLOR_ORANGE, "Function: Will search and reproduce the specified song if it exist.");
  62. return 1;
  63. }
  64.  
  65. new url[160], flag = 0, flag2 = 0, size, size2, k, j, address[256];
  66. if(strcmp(params, lastsearch[playerid], true))
  67. {
  68. available[playerid] = 0;
  69. j = 0;
  70. format(lastsearch[playerid], 128, "%s", params);
  71. format(url, 160, "mp3skull.com/mp3/%s.html", params);
  72. pwncurl_get(url, content, 16384); //read webpage
  73. for(new d = 0; d < 16 ; d++) format(cstring[playerid][d], 256, " "); //clean array information
  74. for(new d = 0; d < 16 ; d++) format(cstring2[playerid][d], 128, " "); //clean array information
  75.  
  76. for(new f = 0; f < 16384-7 ; f++)
  77. {
  78. //look for "http://"
  79. if(content[f] == 'h' && content[f+1] == 't' && content[f+2] == 't' && content[f+3] == 'p'
  80. && content[f+4] == ':' && content[f+5] == '/' && content[f+6] == '/')
  81. {
  82. flag = 1; //now we can search for a ".mp3"
  83. size = f; //regist the begin of song address
  84. f = f+7; //doesn't matter to check the same characters again
  85. continue;
  86. }
  87.  
  88. if(flag == 1)
  89. {
  90. //look for ".mp3"
  91. if(content[f] == '.' && content[f+1] == 'm' && content[f+2] == 'p' && content[f+3] == '3')
  92. {
  93. if(available[playerid] + 1 > 15) break; //limit reached
  94. format(address, 256, " ");
  95. k = 0;
  96. for(new g = size; g < f+4; g++) //copy string information
  97. {
  98. address[k] = content[g];
  99. k++;
  100. }
  101. address[k] = '\0'; //finalize string
  102.  
  103. flag = 0;
  104. f = f+4;
  105.  
  106. if(strcmp(address, "http://ac.mp3", true) && strcmp(address, "http://static.mp3", true)) //acceptable results?
  107. {
  108. format(cstring[playerid][available[playerid]], 256, "%s", address);
  109. available[playerid]++;
  110. }
  111. }
  112. }
  113.  
  114. //look for "<b>"
  115. if(content[f] == '<' && content[f+1] == 'b' && content[f+2] == '>')
  116. {
  117. flag2 = 1; //now we can search for a "</b>"
  118. size2 = f; //regist the begin of song name
  119. f = f+3; //doesn't matter to check the same characters again
  120. continue;
  121. }
  122.  
  123. if(flag2 == 1)
  124. {
  125. //look for "</b>"
  126. if(content[f] == '<' && content[f+1] == '/' && content[f+2] == 'b' && content[f+3] == '>')
  127. {
  128. if(j + 1 > 15) break; //limit reached
  129. format(address, 256, " ");
  130. k = 0;
  131. for(new g = size2+3; g < f-4; g++) //copy string information
  132. {
  133. address[k] = content[g];
  134. k++;
  135. }
  136. address[k] = '\0'; //finalize string
  137.  
  138. flag2 = 0;
  139. f = f+4;
  140.  
  141. format(cstring2[playerid][j], 128, "%s", address);
  142. j++;
  143. }
  144. }
  145. }
  146. }
  147. if(available[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, ":: Sorry, there's no songs with the specified name!");
  148. for(new f = 0; f < available[playerid]; f++)
  149. {
  150. if(f == 0) format(dstring, 2048, "%s", cstring2[playerid][f]);
  151. else format(dstring, 2048, "%s\n%s", dstring, cstring2[playerid][f]);
  152. }
  153. new title[128]; format(title, 128, ":: Results for {FF6400}'%s':", params);
  154. ShowPlayerDialog(playerid, MDIALOG, DIALOG_STYLE_LIST, title, dstring, "Play!", "Close");
  155. return 1;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment