Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
astromo
Visitor

Re: Youtube contents in a private channel ?

Buenafe, this is my script that works. You will need to remove some commands to process the SRT subtitle which causes an error.


'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
'bitrates = [2048] ' >=1.1Mbps = 4 dots

'video

url = "http://www.youtube.com/watch?v=RfOSqpZ0jEM&feature=youtube_gdata" ' The URL for the video
mp4Urls = getMP4Url (url) ' Get a list of all MP4 URLs
sdUrl = mp4Urls.sdUrl
hdUrl = mp4Urls.hdUrl ' Will be empty string if no HD MP4 found
hd1080pUrl = mp4Urls.hd1080pUrl ' Will be empty string if no 1080p MP4 found

urls = [sdUrl]
qualities = ["SD"]
StreamFormat = "mp4"
title = "Youtube"

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
print "play failed: "; msg.GetMessage()
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
end if
end while
End Function


0 Kudos
bandal
Visitor

Re: Youtube contents in a private channel ?

Tried it on simplevideoplayer and not working. Can you post all the code in appMain.brs?
0 Kudos
buenafe
Visitor

Re: Youtube contents in a private channel ?

@astromo - thanks. I can't to try this when I get home

I would have never come up with @belltown's function to get that elusive mp4 link. I unsuccessfully tried to understand a python youtube-dl code which did similar thing. I wonder how these guys do it so easily. So much to learn.
----------------------------------------------------------------------------------
current: two roku XDS 2xs, dtvpal, boxeebox, kylo.tv,
radar: wdlxtv.com
0 Kudos
astromo
Visitor

Re: Youtube contents in a private channel ?

This is my code. Make sure you the image files are the same as those in your folder.

' ********************************************************************
' ** Sample PlayVideo App
' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.
' ********************************************************************

Sub Main(args As Dynamic)
'initialize theme attributes like titles, logos and overhang color
initTheme()

'has to live for the duration of the whole app to prevent flashing
'back to the roku home screen.
screenFacade = CreateObject("roPosterScreen")
screenFacade.show()

item = { ContentType:"episode"
SDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
HDPosterUrl:"file://pkg:/images/MainMenu_Icon_Center_HD.png"
IsHD:True
HDBranded:True
ShortDescriptionLine1:""
ShortDescriptionLine2:""
Description:""
Rating:"NR"
StarRating:"80"
Length:1972
Categories:["Technology","Talk"]
Title:" "
}

showSpringboardScreen(item)

'exit the app gently so that the screen doesn't flash to black
screenFacade.showMessage("")
sleep(25)
End Sub

'*************************************************************
'** Set the configurable theme attributes for the application
'**
'** Configure the custom overhang and Logo attributes
'*************************************************************

Sub initTheme()

app = CreateObject("roAppManager")
theme = CreateObject("roAssociativeArray")

theme.OverhangPrimaryLogoOffsetSD_X = "72"
theme.OverhangPrimaryLogoOffsetSD_Y = "15"
theme.OverhangSliceSD = "pkg:/images/Overhang_BackgroundSlice_SD43.png"
theme.OverhangPrimaryLogoSD = "pkg:/images/Logo_Overhang_SD43.png"

theme.OverhangPrimaryLogoOffsetHD_X = "123"
theme.OverhangPrimaryLogoOffsetHD_Y = "20"
theme.OverhangSliceHD = "pkg:/images/Overhang_BackgroundSlice_HD.png"
theme.OverhangPrimaryLogoHD = "pkg:/images/Logo_Overhang_HD.png"

app.SetTheme(theme)

End Sub


'*************************************************************
'** showSpringboardScreen()
'*************************************************************

Function showSpringboardScreen(item as object) As Boolean
port = CreateObject("roMessagePort")
screen = CreateObject("roSpringboardScreen")

print "showSpringboardScreen"

screen.SetMessagePort(port)
screen.AllowUpdates(false)
if item <> invalid and type(item) = "roAssociativeArray"
screen.SetContent(item)
endif

screen.SetDescriptionStyle("generic") 'audio, movie, video, generic
' generic+episode=4x3,
screen.ClearButtons()
screen.AddButton(1,"Play")
screen.AddButton(2,"Go Back")
screen.SetStaticRatingEnabled(false)
screen.AllowUpdates(true)
screen.Show()

downKey=3
selectKey=6
while true
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSpringboardScreenEvent"
if msg.isScreenClosed()
print "Screen closed"
exit while
else if msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
if msg.GetIndex() = 1
displayVideo("")
else if msg.GetIndex() = 2
return true
endif
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
else
print "wrong type.... type=";msg.GetType(); " msg: "; msg.GetMessage()
endif
end while


return true
End Function


'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
'bitrates = [2048] ' >=1.1Mbps = 4 dots

'video

url = "http://www.youtube.com/watch?v=RfOSqpZ0jEM&feature=youtube_gdata" ' The URL for the video
mp4Urls = getMP4Url (url) ' Get a list of all MP4 URLs
sdUrl = mp4Urls.sdUrl
hdUrl = mp4Urls.hdUrl ' Will be empty string if no HD MP4 found
hd1080pUrl = mp4Urls.hd1080pUrl ' Will be empty string if no 1080p MP4 found

urls = [sdUrl]
qualities = ["SD"]
StreamFormat = "mp4"
title = "Youtube"

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
print "play failed: "; msg.GetMessage()
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
end if
end while
End Function


function getMP4Url (urlParam as string) as object
mp4VideoList = {sdUrl: "", hdUrl: "", hd1080pUrl: ""}
urlTransferObject = CreateObject ("roUrlTransfer")
urlTransferObject.SetPort (CreateObject ("roMessagePort"))
urlTransferObject.SetUrl (urlParam)
htmlString = urlTransferObject.GetToString ()
urlEncodedFmtStreamMap = CreateObject ("roRegex", "url_encoded_fmt_stream_map=([^(" + Chr (34) + "|&|$)]*)", "").Match (htmlString)
if urlEncodedFmtStreamMap.Count () < 2 then return mp4VideoList
urlEncodedFmtStreamList = CreateObject ("roRegex", "%2C", "").Split (urlEncodedFmtStreamMap [1])
for each urlEncodedFmtStream in urlEncodedFmtStreamList
urlStreamMatches = CreateObject ("roRegex", "url%3D(http.*?)%26", "").Match (urlEncodedFmtStream)
if urlStreamMatches.Count () > 1
urlDecoded = CreateObject ("roUrlTransfer").Unescape (CreateObject ("roUrlTransfer").Unescape (urlStreamMatches [1]))
if CreateObject ("roRegex", "itag=18\D", "").IsMatch (urlDecoded)
mp4VideoList.sdUrl = urlDecoded
else if CreateObject ("roRegex", "itag=22\D", "").IsMatch (urlDecoded)
mp4VideoList.hdUrl = urlDecoded
else if CreateObject ("roRegex", "itag=37\D", "").IsMatch (urlDecoded)
mp4VideoList.hd1080pUrl = urlDecoded
endif
endif
end for
return mp4VideoList
end function
0 Kudos
bandal
Visitor

Re: Youtube contents in a private channel ?

Your the Man. It works. This is a first that I know of that someone can share the complete code when asked a question. Building my library little by little.
How would I make a list of various urls to select from on a PosterScreen? Lets say I want to see 5 of my youtube videos and want to select which one to play?

Thank You....

DA
0 Kudos
koopakid08
Visitor

Re: Youtube contents in a private channel ?

@bandal I'm looking at making something similar. Did you ever get it figured out?
0 Kudos
bandal
Visitor

Re: Youtube contents in a private channel ?

@koopakid08
I have 1 feed working from the script post above, but I am my other developer will create one that we can update with an xml file and place content we want with more selections that we want with our custom graphics and descriptions. I want to integrate this into my videoplayer app that is working now. I cannot say how long yet as we are doing the registration and web services links at the moment.

DA
0 Kudos
ciack404
Visitor

Re: Youtube contents in a private channel ?

Hi everyone.

I'm using this script to play yt video on Roku, but the buffering really slow. Anyone else having the same problem? Or are there better solutions than this one? (the thread is quite old, sorry for using it).

Thanks to everyone who can/will help.
0 Kudos