Jump to content

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


Turbe$Z

Recommended Posts

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