Guest User

youtube player

a guest
Oct 29th, 2012
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. //==============================================================================
  2. // Youtube Player v1.0 by Miha_Sasal !
  3. // http://forum.sa-mp.com/member.php?u=122322
  4. //==============================================================================
  5. // Includes & Defines
  6. //==============================================================================
  7. #include <a_samp>
  8. #include <a_http>
  9. #include <core>
  10. #include <float>
  11. #define U2BDIAG 6958 //DialogID used
  12. new PlayerU2B[MAX_PLAYERS];
  13. new PlayerU2BLink[MAX_PLAYERS][32];
  14. new U2BRadius[MAX_PLAYERS][16];
  15. forward U2BInfo(playerid, response_code, data[]);
  16. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  17. #define WHOMADETHIS "Youtube Player v1.0 by {FF0000}us{FFEF00}rb{1A00FF}1n"
  18.  
  19. public OnFilterScriptInit()
  20. {
  21. print("Youtube player by usrb1n has been loaded");
  22. }
  23. public OnFilterScriptExit()
  24. {
  25. print("Youtube player by usrb1n has been unloaded");
  26. }
  27.  
  28. //==============================================================================
  29. // Commands
  30. //==============================================================================
  31. public OnPlayerCommandText(playerid, cmdtext[])
  32. {
  33. dcmd(youtube, 7, cmdtext);
  34. dcmd(stopu2b, 7, cmdtext);
  35. return 0;
  36. }
  37.  
  38. dcmd_stopu2b(playerid, params[])
  39. {
  40. if(strlen(params)) return 0;
  41. PlayAudioStreamForPlayer(playerid, "Music was stoped by player.");
  42. return 1;
  43. }
  44.  
  45. dcmd_youtube(playerid, params[])
  46. {
  47. if(strlen(params)) return 0;
  48. if(!IsPlayerAdmin(playerid))
  49. {
  50. SendClientMessage(playerid, 0xD776FF, "Only RCON people can do this.");
  51. return 1;
  52. }
  53. ShowPlayerDialog(playerid, U2BDIAG, DIALOG_STYLE_LIST, WHOMADETHIS, "{46BEE6}Play for yourself (The song will be played only for you)\n{ED954E}Play for someone (The song will be played for the ID you input in the textbox)\n{46BEE6}Play for a location (The song will be played with the radius you choose)\n{ED954E}Play for all (The song will be played for all the players in the server)", "Select", "Cancel");
  54. return 1;
  55. }
  56. //==============================================================================
  57. // Dialogs
  58. //==============================================================================
  59. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  60. {
  61. if(dialogid == U2BDIAG && response)
  62. {
  63. switch(listitem)
  64. {
  65. case 0:
  66. {
  67. PlayerU2B[playerid] = 1;
  68. ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"Paste the youtube link you want to play for yourself:","Play","Cancel");
  69. return 1;
  70. }
  71. case 1:
  72. {
  73. PlayerU2B[playerid] = 2;
  74. ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"Paste the youtube link you want to play for a player:","Play","Cancel");
  75. return 1;
  76. }
  77. case 2:
  78. {
  79. PlayerU2B[playerid] = 3;
  80. ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"Paste the youtube link you want to play for your location:","Play","Cancel");
  81. return 1;
  82. }
  83. case 3:
  84. {
  85. PlayerU2B[playerid] = 4;
  86. ShowPlayerDialog(playerid,U2BDIAG+1,DIALOG_STYLE_INPUT,WHOMADETHIS,"Paste the youtube link you want to play for the whole server:","Play","Cancel");
  87. return 1;
  88. }
  89. }
  90. }
  91. if(dialogid == U2BDIAG+1 && response)
  92. {
  93. if(strlen(inputtext))
  94. {
  95. new result[128], videostr[128];
  96. strmid(result,inputtext,31,44,strlen(inputtext));
  97. format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",result);
  98. strmid(PlayerU2BLink[playerid], result, 0, 32);
  99. if (PlayerU2B[playerid] == 1)
  100. {
  101. PlayerU2B[playerid] = 11;
  102. HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
  103. }
  104. else if (PlayerU2B[playerid] == 2)
  105. {
  106. PlayerU2B[playerid] = 22;
  107. ShowPlayerDialog(playerid,U2BDIAG+2,DIALOG_STYLE_INPUT,WHOMADETHIS,"Enter the player id you want to play the song for:","Play","Cancel");
  108. new string[128];
  109. format(string, sizeof(string), "%s", PlayerU2BLink[playerid]);
  110. }
  111. else if (PlayerU2B[playerid] == 3)
  112. {
  113. PlayerU2B[playerid] = 33;
  114. ShowPlayerDialog(playerid,U2BDIAG+3,DIALOG_STYLE_INPUT,WHOMADETHIS,"Enter the radius in which you want the song to be heard:","Play","Cancel");
  115. }
  116. else if (PlayerU2B[playerid] == 4)
  117. {
  118. PlayerU2B[playerid] = 44;
  119. HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
  120. }
  121. }
  122. return 1;
  123.  
  124. }
  125. if(dialogid == U2BDIAG+2 && response)
  126. {
  127. new gpid = strval(inputtext);
  128. new videostr[128];
  129. format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",PlayerU2BLink[playerid]);
  130. HTTP(gpid,HTTP_GET,videostr,"","U2BInfo");
  131. return 1;
  132.  
  133. }
  134. if(dialogid == U2BDIAG+3 && response)
  135. {
  136. strmid(U2BRadius[playerid], inputtext, 0, 32);
  137. new videostr[128];
  138. PlayerU2B[playerid] = 333;
  139. format(videostr,sizeof(videostr),"www.youtube-mp3.org/api/itemInfo/?video_id=%s",PlayerU2BLink[playerid]);
  140. HTTP(playerid,HTTP_GET,videostr,"","U2BInfo");
  141. return 1;
  142.  
  143. }
  144.  
  145.  
  146. return 0;
  147. }
  148.  
  149. //==============================================================================
  150. // Functions
  151. //==============================================================================
  152.  
  153. public U2BInfo(playerid, response_code, data[])
  154. {
  155. if(response_code == 200)
  156. {
  157. new result[33], u2bstr[33]; new streamedurl[128];
  158. new crypted = strfind(data, "\"h\"", true, -1);
  159. strmid(result,data,crypted+7,crypted+39,strlen(data));
  160. format(u2bstr,sizeof(u2bstr), "%s", result);
  161. format(streamedurl, sizeof(streamedurl), "http://www.youtube-mp3.org/get?video_id=%s&h=%s",PlayerU2BLink[playerid], u2bstr);
  162. if(PlayerU2B[playerid] == 11)
  163. {
  164. PlayAudioStreamForPlayer(playerid, streamedurl);
  165. return 1;
  166. }
  167. else if(PlayerU2B[playerid] == 22)
  168. {
  169. PlayAudioStreamForPlayer(playerid, streamedurl);
  170. return 1;
  171. }
  172. else if(PlayerU2B[playerid] == 33)
  173. {
  174.  
  175. PlayAudioStreamForPlayer(playerid, streamedurl);
  176. return 1;
  177. }
  178. else if(PlayerU2B[playerid] == 44)
  179. {
  180. for(new i = 0; i < MAX_PLAYERS; i++)
  181. {
  182. if(IsPlayerConnected(i))
  183. {
  184. PlayAudioStreamForPlayer(i, streamedurl);
  185. return 1;
  186. }
  187. else return 1;
  188. }
  189. }
  190. else if(PlayerU2B[playerid] == 333)
  191. {
  192. new Float:X, Float:Y, Float:Z;
  193. GetPlayerPos(playerid, X, Y, Z);
  194. new radius = strval(U2BRadius[playerid]);
  195. for(new i = 0; i < MAX_PLAYERS; i++)
  196. {
  197. if(IsPlayerConnected(i))
  198. {
  199. if(IsPlayerInRangeOfPoint(i, radius , X, Y, Z))
  200. {
  201. PlayAudioStreamForPlayer(i, streamedurl, X, Y, Z, radius, 1);
  202. return 1;
  203. }
  204. else return 1;
  205. }
  206. }
  207. }
  208.  
  209. }
  210. else
  211. {
  212.  
  213. new u2bstring[128];
  214. format(u2bstring,sizeof(u2bstring)," {FF0000}Youtube link error\n\n{FFFFFF}This youtube link is broken or uses some copyright protection, we can't convert it to mp3 for streaming. Try another link please. ");
  215. ShowPlayerDialog(playerid,61,DIALOG_STYLE_MSGBOX ,WHOMADETHIS,u2bstring, "Exit", "");
  216. }
  217. return 1;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment