Guest User

[FS] Youtube video searcher and reproducer by Riccor

a guest
Sep 4th, 2012
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd> //http://forum.sa-mp.com/showthread.php?t=91354
  3. #include <sscanf2> //http://forum.sa-mp.com/showthread.php?t=120356
  4. #include <pwncurl> //http://forum.sa-mp.com/showthread.php?t=72260 - Compiled in CentOS 5.6: http://forum.sa-mp.com/showthread.php?p=2093994#post2093994
  5.  
  6. #undef MAX_PLAYERS
  7. #define MAX_PLAYERS 50
  8.  
  9. #define MAX_SS 65536
  10. #define MAX_RESULTS 32
  11. #define YDIALOG 18450
  12.  
  13. #define COLOR_RED 0xFF0000FF
  14. #define COLOR_YELLOW 0xFFDD00FF
  15. #define COLOR_ORANGE 0xFFA500FF
  16. #define COLOR_BLUE 0x0000FFFF
  17.  
  18. new Web_Content[MAX_SS]; //string to store the data read from the webpage
  19. new Results_Links[MAX_PLAYERS][MAX_RESULTS][128];
  20. new Results_Names[MAX_PLAYERS][MAX_RESULTS][128];
  21. new Videos_Found[MAX_PLAYERS] = {0, ...};
  22. new Dialog_String[MAX_RESULTS * 128];
  23. new Last_Search[MAX_PLAYERS][128];
  24.  
  25. CMD:y(playerid, params[]) return cmd_youtube(playerid, params);
  26. CMD:youtube(playerid, params[])
  27. {
  28. if(sscanf(params, "s[128]", params))
  29. {
  30. SendClientMessage(playerid, COLOR_BLUE, "Usage: /youtube < Name of video to search >");
  31. SendClientMessage(playerid, COLOR_ORANGE, "Function: It will search and reproduce the specified youtube song.");
  32. return 1;
  33. }
  34. if(strcmp(params, Last_Search[playerid], true))
  35. {
  36. new assist[128];
  37. format(Last_Search[playerid], 128, "%s", params);
  38. format(assist, sizeof(assist), "www.youtube.com/results?search_query=%s", params);
  39. for(new i = 35; i < strlen(assist); i++) if(assist[i] == ' ') assist[i] = '+';
  40. pwncurl_get(assist, Web_Content, MAX_SS);
  41.  
  42. new f = strfind(Web_Content, "\"href=\"/watch?v=", true, 0), t = 0, offset = 0;
  43. while(f != -1 && t < MAX_RESULTS)
  44. {
  45. strmid(assist, Web_Content, f + 16, f + 27);
  46.  
  47. //by Nightmare[TR] (http://forum.sa-mp.com/showthread.php?t=370450) - You can change this address to your own website host:
  48. format(Results_Links[playerid][t], 128, "http://element-samp.net/youtube.php?videoid=%s", assist);
  49.  
  50. strmid(assist, Web_Content, f + 29, strfind(Web_Content, "</a>", true, f + 29));
  51. format(Results_Names[playerid][t], 128, "%s", assist);
  52. t++;
  53. offset = f + 164;
  54. f = strfind(Web_Content, "\"href=\"/watch?v=", true, offset);
  55. }
  56. Videos_Found[playerid] = t;
  57. }
  58. if(Videos_Found[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "- No videos were found with the specified name!");
  59. new c = 0;
  60. for(new l = 0; l < Videos_Found[playerid]; l++)
  61. {
  62. if(l == 0) format(Dialog_String, sizeof(Dialog_String), "{FFFFFF}%s", Results_Names[playerid][l]);
  63. else
  64. {
  65. if(c == 0)
  66. {
  67. format(Dialog_String, sizeof(Dialog_String), "%s\n{AFAFAF}%s", Dialog_String, Results_Names[playerid][l]);
  68. c = 1;
  69. }
  70. else
  71. {
  72. format(Dialog_String, sizeof(Dialog_String), "%s\n{FFFFFF}%s", Dialog_String, Results_Names[playerid][l]);
  73. c = 0;
  74. }
  75. }
  76.  
  77. }
  78. new title[64]; format(title, 64, "- Results for {80FF00}\"%s\":", params);
  79. ShowPlayerDialog(playerid, YDIALOG, DIALOG_STYLE_LIST, title, Dialog_String, "Play!", "Close");
  80. return 1;
  81. }
  82.  
  83. public OnFilterScriptInit()
  84. {
  85. for(new i = 0; i < MAX_PLAYERS; i++) format(Last_Search[i], 128, " - ");
  86. return 1;
  87. }
  88.  
  89. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  90. {
  91. if(dialogid == YDIALOG && response)
  92. {
  93. PlayAudioStreamForPlayer(playerid, Results_Links[playerid][listitem]);
  94. SendClientMessage(playerid, COLOR_YELLOW, "- Press N to stop the music.");
  95. return 1;
  96. }
  97. return 0;
  98. }
  99.  
  100. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  101. {
  102. if(newkeys & KEY_NO) StopAudioStreamForPlayer(playerid);
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment