Jump to content

YOUTUBE AND LUA!


ednatmp

Recommended Posts

Hello Forum, first of all, I'm from Argentina so sorry for my bad English. Well, I 'm scripting is a command which lets you listen to music from youtube. Already finished but I would like to know if there is any way to get the name of the video.

Please help.

Regards, Enz0Z

Link to comment
Hello Forum, first of all, I'm from Argentina so sorry for my bad English. Well, I 'm scripting is a command which lets you listen to music from youtube. Already finished but I would like to know if there is any way to get the name of the video.

Please help.

Regards, Enz0Z

Depends on the method, for the most part, youtube links all have the video name in the web page name.

This is mine (Kinda old, but still works):

Server

  
addCommandHandler('ls',function(player,cmd,url) 
local url = url:gsub("www.", "") 
local url = url:gsub("https://", "") 
local url = url:gsub("http://", "") 
if string.find(url:lower(), "youtube.com") then 
    local url = url:gsub('youtube.com','') 
    local url = url:gsub('/watch%?v%=','') 
    if string.find(url,'%&list%=') then 
    outputChatBox('#ff0000youtube playlists are not allowed!',player,255,255,255,true) 
    return 
    end 
    outputChatBox('sending '..url) 
    triggerClientEvent(root,'LoadClientSong',resourceRoot,getPlayerName(player), url) 
else 
outputChatBox('#ff0000Please use a youtube song!',player,255,255,255,true) 
end 
end) 
  

Client

  
local x,y = guiGetScreenSize() 
local browser = createBrowser(x,y,false,false) 
local currentSong = '' 
local Player = '' 
local newTitle = '' 
  
local text = 'Random Crappy Text' 
local g_Font = dxCreateFont('hvrom.otf',15,false,"antialiased") 
local scale = 10 
local maxW = x*0.1 
  
local w = dxGetTextWidth(text,scale,g_Font) 
while w > maxW do 
scale = scale - 0.01 
local w = dxGetTextWidth(text, scale, g_Font) 
    if w < maxW then     
    break end 
end 
  
  
addEvent('LoadClientSong',true) 
addEventHandler('LoadClientSong',root,function(player,url) 
   if browser then   
   Player = player 
   local newURL = 'https://youtube.com/embed/'..url..'?autoplay=1' 
   loadBrowserURL(browser,newURL) 
   outputChatBox('loading '..newURL) 
   currentSong = newURL 
   end 
end) 
  
addEventHandler('onClientBrowserNavigate',root,function(url) 
    if source == browser then 
        if url ~= currentSong then 
        outputChatBox('unallowed!') 
        cancelEvent() 
        end 
    end 
end) 
  
local start = getTickCount() 
  
addEventHandler('onClientRender',root,function() 
dxDrawImageSection(x*0.5,y*0.75 + (y*0.2)*0.15,x*0.2,(y*0.2)*0.85,0,y*0.05,x,y*0.85,browser) 
local title = getBrowserTitle(browser) 
if title ~= newTitle then 
newTitle = title 
  
    local width = dxGetTextWidth(title.."  ",1*scale,g_Font) 
    target = nil 
    target = dxCreateRenderTarget(width, dxGetFontHeight(1*scale,g_Font),true) 
    targetX,targetY = width,dxGetFontHeight(1*scale,g_Font) 
    outputChatBox(targetX*10) 
    start = getTickCount() 
    end 
if title then 
    if target then 
    dxSetRenderTarget(target) 
    dxSetBlendMode('modulate_add') 
    dxDrawRectangle(0,0,targetX,targetY,tocolor(0,0,0,255)) 
    dxDrawText(' ' ..title,0,0,targetX,targetY,tocolor(255,255,255,255),1*scale,g_Font)  
    dxSetRenderTarget() 
    dxSetBlendMode('add') 
    local now = getTickCount() 
    local p = (now-start)/(targetX*100) 
    if p >= 1 and p < 2 then 
    p = 0 
    elseif p >= 2 then 
    start = getTickCount() 
    end 
    local calx = p*targetX 
    local calx2 = x*0.2 
    if calx >= targetX - x*0.2 then 
    calx2 = targetX - calx 
    end 
    dxDrawRectangle(x*0.5,y*0.95,x*0.2,y*0.05,tocolor(0,0,0,255)) 
    dxDrawImageSection(x*0.5,y*0.95,calx2,targetY,calx,0,calx2,targetY,target) 
    dxSetBlendMode('blend') 
    end 
    if Player and Player ~= '' then 
    dxDrawText(' Player: '..Player:gsub('#%x%x%x%x%x%x',''),x*0.5,y*0.965,x,y,tocolor(255,255,255,255),1*scale,g_Font) 
    end 
end 
end) 

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...