"astromo" wrote:
And what is the URL to be used for pointing to youtube contents?
You could try this function:
'**********************************************************************************************************************
' ytGetMP4Url - Retrieve a list of MP4 urls from YouTube for the specified video id
'
' Example usage:
'
' videoId = "S2wAMaM2OYQ" ' (required) YouTube Video Id
' ' Alternatively, the full Url of the YouTube video may be specified here
' timeout = 60000 ' (optional) Timeout in milliseconds (default: 0 => wait forever)
' loginCookie = "" ' (optional) YouTube login cookie - only required if video requires a login,
' ' e.g. Private or R-Rated videos (default: "")
' ' The login cookie can be obtained by calling ytLoginYouTube
' mp4VideoList = ytGetMP4Url (videoId, timeout, loginCookie)
' if mp4VideoList <> Invalid ' Invalid returned if no MP4 streams detected
' sdUrl = mp4VideoList.sdUrl
' hdUrl = mp4VideoList.hdUrl ' Will be empty string if no HD MP4 found
' hd1080pUrl = mp4VideoList.hd1080pUrl ' Will be empty string if no 1080p MP4 found
' hlsUrl = mp4VideoList.hlsUrl ' If an HLS stream is found, set to its index file's Url
' endif
'**********************************************************************************************************************
function ytGetMP4Url (videoIdOrUrl as string, timeout = 0 as integer, loginCookie = "" as string) as object
mp4VideoList = {sdUrl: "", hdUrl: "", hd1080pUrl: "", hlsUrl: ""}
if Left (LCase (videoIdOrUrl), 4) = "http"
url = videoIdOrUrl
else
url = "http://www.youtube.com/get_video_info?hl=en&el=detailpage&video_id=" + videoIdOrUrl
endif
'
' Get the web page containing video information
'
htmlString = ""
port = CreateObject ("roMessagePort")
ut = CreateObject ("roUrlTransfer")
ut.SetPort (port)
ut.AddHeader ("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0 (gzip)")
if loginCookie <> ""
ut.AddHeader ("Cookie", loginCookie)
endif
ut.SetCertificatesFile ("common:/certs/ca-bundle.crt")
ut.InitClientCertificates ()
ut.EnableEncodings (true)
ut.SetUrl (url)
if ut.AsyncGetToString ()
while true
msg = Wait (timeout, port)
if type (msg) = "roUrlEvent"
status = msg.GetResponseCode ()
print "ytGetMP4Url. MP4 Url Request: Url = " + url + ". status = " + status.ToStr () + ". failureReason = " + msg.GetFailureReason ()
if status = 200
htmlString = msg.GetString ()
print "htmlString=" + htmlString
endif
exit while
else if type (msg) = "Invalid"
ut.AsyncCancel ()
print "ytGetMP4Url. Timeout"
exit while
endif
end while
endif
'
' urlEncodedFmtStreamMap contains any mp4 urls
' TODO: Check if 1080p support has been discontinued
'
urlEncodedFmtStreamMap = CreateObject ("roRegex", "\x22url_encoded_fmt_stream_map\x22:\x22([^\x22]+)\x22", "").Match (htmlString)
if urlEncodedFmtStreamMap.Count () > 1
commaSplit = CreateObject ("roRegex", ",", "").Split (urlEncodedFmtStreamMap [1])
for each commaItem in commaSplit
maVideoUrl = CreateObject ("roRegex", "url=(.+)", "").Match (commaItem)
if maVideoUrl.Count () = 2
videoUrl = ut.Unescape (maVideoUrl [1])
print "videoUrl: " + videoUrl
pair = {itag: ""}
ampersandSplit = CreateObject ("roRegex", "&", "").Split (videoUrl)
for each ampersandItem in ampersandSplit
equalsSplit = CreateObject ("roRegex", "=", "").Split (ampersandItem)
if equalsSplit.Count () = 2
pair [equalsSplit [0]] = equalsSplit [1]
endif
end for
if Left (LCase (videoUrl), 4) = "http"
urlDecoded = ut.Unescape (videoUrl)
if pair.itag = "18"
mp4VideoList.sdUrl = urlDecoded
else if pair.itag = "22"
mp4VideoList.hdUrl = urlDecoded
else if pair.itag = "37"
mp4VideoList.hd1080pUrl = urlDecoded
endif
endif
endif
end for
endif
'
' If no mp4 urls, check for live (HLS) feed in the hlsvp attribute
'
if mp4VideoList.sdUrl = "" and mp4VideoList.hdUrl = "" and mp4VideoList.hd1080pUrl = ""
' If no mp4 video streams were found, search for a live stream HLS manifest (.m3u8) file
hlsvp = CreateObject ("roRegex", "hlsvp=([^(" + Chr(34) + "|&|$)]*)", "").Match (htmlString)
if hlsvp.Count () > 1
hlsUrlDecoded = ut.Unescape (ut.Unescape (hlsvp [1]))
mp4VideoList.hlsUrl = hlsUrlDecoded
endif
if mp4VideoList.hlsUrl = ""
mp4VideoList = Invalid
endif
endif
if mp4VideoList <> invalid
print "ytGetMP4Url. sdUrl=" + mp4VideoList.sdUrl
print "ytGetMP4Url. hdUrl=" + mp4VideoList.hdUrl
print "ytGetMP4Url. hd1080pUrl=" + mp4VideoList.hd1080pUrl
print "ytGetMP4Url. hlsUrl=" + mp4VideoList.hlsUrl
else
print "ytGetMP4Url. No Video Streams Found"
endif
return mp4VideoList
end function