Jump to content

pomoc Hudba na serveru z YouTube


Laser S3 Arctic

Recommended Posts

Já vím už jsem trapný že tu dnes dávám již několikáté téma ale přemýšlel jsem aj s kámošem ale nevím si rady ... Jde o /hudba na server ... Co nechápu ?
1,Kam dát tu URL z youtube.com
2,Příkaz .. Nikde není ! Ani na www stránkách -_-
3,Nechápu jak to může být tak složitý :d (pro mě to složitý je ale vypadá to lehce)
 

#include <a_samp>
#include <a_http>
 
#undef MAX_PLAYERS
#define MAX_PLAYERS 50
 
#define MAX_RESULTS 16
#define YDIALOG 18450
 
#define YOUR_WEBSITE "yourwebsite.com" //You need to change this.
 
#define COLOR_RED 0xFF0000FF
#define COLOR_YELLOW 0xFFDD00FF
#define COLOR_ORANGE 0xFFA500FF
#define COLOR_BLUE 0x0000FFFF
 
new Results_Links[MAX_PLAYERS][MAX_RESULTS][128];
new Results_Names[MAX_PLAYERS][MAX_RESULTS][128];
new Videos_Found[MAX_PLAYERS];
new Dialog_String[MAX_RESULTS * 128];
new Last_Search[MAX_PLAYERS][128];
new Request_Type[MAX_PLAYERS];
 
CMD:y(playerid, params[]) return cmd_youtube(playerid, params);
CMD:youtube(playerid, params[])
{
        if(sscanf(params, "s[128]", params))
        {
                SendClientMessage(playerid, COLOR_BLUE, "Usage: /hudba < Name of video to search >");
                SendClientMessage(playerid, COLOR_ORANGE, "Function: It will search and reproduce the specified youtube song.");
                return 1;
        }
        Request_Type[playerid] = 0;
        if(strcmp(params, Last_Search[playerid], true))
        {
                format(Last_Search[playerid], 128, "%s", params);
                new assist[256];
                format(assist, sizeof(assist), ""#YOUR_WEBSITE"/curl.php?limit="#MAX_RESULTS"&linkid=http://www.youtube.com/results?search_query=%s", params);
                for(new i = 35; i < strlen(assist); i++) if(assist == ' ') assist = '?';
            HTTP(playerid, HTTP_GET, assist, "", "MyYoutubeHttpResponse");
            return 1;
        }
        ShowResultsWindow(playerid);
        return 1;
}
 
CMD:yall(playerid, params[])
{
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "Error: Only RCON admins can use this command.");
        if(sscanf(params, "s[128]", params))
        {
                SendClientMessage(playerid, COLOR_BLUE, "Usage: /yall < Name of video to search >");
                SendClientMessage(playerid, COLOR_ORANGE, "Function: It will search and reproduce the specified youtube song for all players.");
                return 1;
        }
        Request_Type[playerid] = 1;
        if(strcmp(params, Last_Search[playerid], true))
        {
                format(Last_Search[playerid], 128, "%s", params);
                new assist[256];
                format(assist, sizeof(assist), ""#YOUR_WEBSITE"/curl.php?limit="#MAX_RESULTS"&linkid=http://www.youtube.com/results?search_query=%s", params);
                for(new i = 35; i < strlen(assist); i++) if(assist == ' ') assist = '?';
            HTTP(playerid, HTTP_GET, assist, "", "MyYoutubeHttpResponse");
            return 1;
        }
        ShowResultsWindow(playerid);
        return 1;
}
 
stock ShowResultsWindow(playerid)
{
        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\":", Last_Search[playerid]);
        if(Request_Type[playerid] == 1) ShowPlayerDialog(playerid, YDIALOG + 1, DIALOG_STYLE_LIST, title, Dialog_String, "Play!", "Close");
        else ShowPlayerDialog(playerid, YDIALOG, DIALOG_STYLE_LIST, title, Dialog_String, "Play!", "Close");
        return 1;
}
 
forward MyYoutubeHttpResponse(index, response_code, data[]);
public MyYoutubeHttpResponse(index, response_code, data[])
{
    if(response_code == 200)
    {
                new assist[128];
                new f = strfind(data, ">
", true, 0), t = 0, offset = 0;
                while(f != -1 && t < MAX_RESULTS)
                {
                        strmid(assist, data, f + 1, f + 12);
 
                        //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[index][t], 128, "http://element-samp.net/youtube.php?videoid=%s", assist);
 
                        strmid(assist, data, f + 15, strfind(data, "<", true, f + 15));
                        format(Results_Names[index][t], 128, "%s", assist);
                        t++;
                        offset = f + 16;
                        f = strfind(data, ">
", true, offset);
                }
                Videos_Found[index] = t;
                ShowResultsWindow(index);
    }
    else
    {
        format(Dialog_String, sizeof(Dialog_String), "Error: Request failed! Try again later. [Response code: %d]", response_code);
        SendClientMessage(index, COLOR_RED, Dialog_String);
    }
    return 1;
}
 
public OnFilterScriptInit()
{
        for(new i = 0; i < MAX_PLAYERS; i++) format(Last_Search, 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;
        }
 
        if(dialogid == YDIALOG + 1) if(response)
        {
                for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) PlayAudioStreamForPlayer(i, Results_Links[playerid][listitem]);
                new pName[MAX_PLAYER_NAME]; GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
                format(Dialog_String, sizeof(Dialog_String), "Server: Admin %s(%d) is playing youtube audio for all players!", pName, playerid);
                SendClientMessageToAll(COLOR_ORANGE, Dialog_String);
                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;
}


To je ano ... Děkuji za odpověd
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...