Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd> //http://forum.sa-mp.com/showthread.php?t=91354
- #include <sscanf2> //http://forum.sa-mp.com/showthread.php?t=120356
- #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
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 50
- #define MAX_SS 65536
- #define MAX_RESULTS 32
- #define YDIALOG 18450
- #define COLOR_RED 0xFF0000FF
- #define COLOR_YELLOW 0xFFDD00FF
- #define COLOR_ORANGE 0xFFA500FF
- #define COLOR_BLUE 0x0000FFFF
- new Web_Content[MAX_SS]; //string to store the data read from the webpage
- new Results_Links[MAX_PLAYERS][MAX_RESULTS][128];
- new Results_Names[MAX_PLAYERS][MAX_RESULTS][128];
- new Videos_Found[MAX_PLAYERS] = {0, ...};
- new Dialog_String[MAX_RESULTS * 128];
- new Last_Search[MAX_PLAYERS][128];
- CMD:y(playerid, params[]) return cmd_youtube(playerid, params);
- CMD:youtube(playerid, params[])
- {
- if(sscanf(params, "s[128]", params))
- {
- SendClientMessage(playerid, COLOR_BLUE, "Usage: /youtube < Name of video to search >");
- SendClientMessage(playerid, COLOR_ORANGE, "Function: It will search and reproduce the specified youtube song.");
- return 1;
- }
- if(strcmp(params, Last_Search[playerid], true))
- {
- new assist[128];
- format(Last_Search[playerid], 128, "%s", params);
- format(assist, sizeof(assist), "www.youtube.com/results?search_query=%s", params);
- for(new i = 35; i < strlen(assist); i++) if(assist[i] == ' ') assist[i] = '+';
- pwncurl_get(assist, Web_Content, MAX_SS);
- new f = strfind(Web_Content, "\"href=\"/watch?v=", true, 0), t = 0, offset = 0;
- while(f != -1 && t < MAX_RESULTS)
- {
- strmid(assist, Web_Content, f + 16, f + 27);
- //by Nightmare[TR] (http://forum.sa-mp.com/showthread.php?t=370450) - You can change this address to your own website host:
- format(Results_Links[playerid][t], 128, "http://element-samp.net/youtube.php?videoid=%s", assist);
- strmid(assist, Web_Content, f + 29, strfind(Web_Content, "</a>", true, f + 29));
- format(Results_Names[playerid][t], 128, "%s", assist);
- t++;
- offset = f + 164;
- f = strfind(Web_Content, "\"href=\"/watch?v=", true, offset);
- }
- Videos_Found[playerid] = t;
- }
- if(Videos_Found[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "- No videos were found with the specified name!");
- new c = 0;
- for(new l = 0; l < Videos_Found[playerid]; l++)
- {
- if(l == 0) format(Dialog_String, sizeof(Dialog_String), "{FFFFFF}%s", Results_Names[playerid][l]);
- else
- {
- if(c == 0)
- {
- format(Dialog_String, sizeof(Dialog_String), "%s\n{AFAFAF}%s", Dialog_String, Results_Names[playerid][l]);
- c = 1;
- }
- else
- {
- format(Dialog_String, sizeof(Dialog_String), "%s\n{FFFFFF}%s", Dialog_String, Results_Names[playerid][l]);
- c = 0;
- }
- }
- }
- new title[64]; format(title, 64, "- Results for {80FF00}\"%s\":", params);
- ShowPlayerDialog(playerid, YDIALOG, DIALOG_STYLE_LIST, title, Dialog_String, "Play!", "Close");
- return 1;
- }
- public OnFilterScriptInit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++) format(Last_Search[i], 128, " - ");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == YDIALOG && response)
- {
- PlayAudioStreamForPlayer(playerid, Results_Links[playerid][listitem]);
- SendClientMessage(playerid, COLOR_YELLOW, "- Press N to stop the music.");
- return 1;
- }
- return 0;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_NO) StopAudioStreamForPlayer(playerid);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment