Jump to content

[HELP] Can i get the youtube video length from web browser?


Turbe$Z

Recommended Posts

Posted

I created a youtube player, and i want to remove the event handler, when the music ends, but i dont know how to get the song length from web browser... anyone can help?

  • Scripting Moderators
Posted

It may be possible if using fetchRemote with youtube's API

Posted
24 minutes ago, thisdp said:

It may be possible if using fetchRemote with youtube's API

I tried fetchRemote the yt link, but the responseData got nil...

  • Moderators
Posted (edited)
6 hours ago, thisdp said:

It may be possible if using fetchRemote with youtube's API

Ohh.. it's a good idea. ?

 

local apiKey = "censored" -- How to get own: https://www.youtube.com/watch?v=pP4zvduVAqo
local browser = createBrowser(500, 500, false)


function receiveData(result)
	local data = fromJSON(result)
	local isoDuration = data.items[1].contentDetails.duration
	local min, sec = isoDuration:match("^.-(%d+)M(%d+)S") -- this pattern work only with minimum 1 min, and maximum 1 hour videos

	setTimer(function()
		removeEventHandler("onClientRender", root, render)	
	end, (min*60 + sec) * 1000, 1)
end

function render()
	dxDrawImage(0, 0, 500, 500, browser)
end


addEventHandler("onClientBrowserCreated", browser, function()
	local url = "https://www.youtube.com/watch?v=NLb-gZNKzT8"
	local id = url:match("%?v=(...........)") -- maybe need a better pattern :'D
	
	loadBrowserURL(source, url)
	addEventHandler("onClientRender", root, render)

	fetchRemote("https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id="..id.."&key="..apiKey, receiveData)
end)

@Turbe$Z

something like that

Edited by Patrick
  • Thanks 1
  • Scripting Moderators
Posted
7 hours ago, Turbe$Z said:

I tried fetchRemote the yt link, but the responseData got nil...

that's weird

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...