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: 
hugetv
Visitor

help with code please

the code

Sub showMoviesScreen()
port=CreateObject("roMessagePort")
dialogPort=CreateObject("roMessagePort")
subMovies = getCategoryListMovies()
countsubMovies = subMovies.Count()
subRedditNamesAfterAsync = CreateObject("roArray", subMovies.Count(), true)

grid = CreateObject("roGridScreen")
grid.SetMessagePort(port)
grid.SetDisplayMode("scale-to-fit")
grid.SetGridStyle("flat-portrait")
grid.SetupLists(countsubMovies)


grid.show()

dialog = showLoadingScreen("Downloading subMovies: 0/" +(countsubMovies-1).tostr(),dialogPort)

list = CreateObject("roArray", subMovies.Count(), true)

request = CreateObject("roArray", 100, true)
'httpPort=CreateObject("roMessagePort")
for j = 1 to subMovies.Count() -1
request[j] = CreateObject("roUrlTransfer")
request[j].SetPort(port)
category = subMovies[j]
api_url = UrlServidor()+"/movies.php?cat="+category
request[j].SetUrl(api_url)
request[j].AsyncGetToString()
print "init list " + j.tostr()
end for


countListAsync = 1 'counting the list but for when the async returns

timer = CreateObject("roTimespan")

while true
msg = wait(0, port)

TotalSeconds = timer.TotalSeconds()
if(TotalSeconds > 90) 'prevent infinite while loop while
exit while
end if

if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
print "Codigo:";code
if (code = 200)
newList = invalid
response = msg.GetString()
json = ParseJSON(response)
if(json = invalid)
'do nothing
else
newList = parseJsonPosts(json)
subRedditName = newList[0].subReddit
if(subRedditName <> invalid)
print "got the subreddit= " + subRedditName
subRedditNamesAfterAsync.push(subRedditName)
end if
list[countListAsync] = newList
if(list[countListAsync] = invalid)
'build a failed to load icon for the grid
list[countListAsync] = buildErrorGrid()
END IF

dialog.SetTitle( "Downloading subMovies: "+countListAsync.tostr()+ "/" + (countsubMovies-1).tostr() )
dialog.Show()

'print "[" + msg.GetString() + "]"
END IF

countListAsync = countListAsync+1

if(countListAsync = countsubMovies )
exit while
end if
else
'code was not 200
print "HTTP response was not 200"
END IF
END IF
end while



grid.SetListNames(subRedditNamesAfterAsync) 'we are now setting these asyncornously

dialog.SetTitle( "Loading subMovies" )
dialog.Show()



for i = 0 to subMovies.Count() -1
grid.SetContentList(i, list[i])
end for
grid.SetFocusedListItem(2,0)
'grid.show()
dialog.Close()


while true
msg = wait(10, port)


if msg <> invalid and type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
exit while
else if msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
else if msg.isListItemSelected() then
print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();
'selection = seriesList.GetEntry(msg.GetIndex())[msg.GetData()]

list = seriesList.GetEntry(msg.GetIndex())
if list <> invalid then
selection = list[msg.GetData()]
end if

if selection.Title = "Search"
searchMovies()
else if selection.Title = "Favorites"
FavoritesMovies()
else
showSpringboardScreenMovies(selection)
end if

end if
end if
end while

End Sub

Function getCategoryListMovies() as object
jsonAsString = CreateObject("roUrlTransfer")
jsonAsString.SetURL(UrlServidor()+"/category.php?t=movies")
json = ParseJson(jsonAsString.GetToString())
return json
End Function


Function showLoadingScreen(msg As String,port)
dialog = CreateObject( "roOneLineDialog" )
dialog.SetMessagePort(port)
dialog.ShowBusyAnimation()
dialog.SetTitle( msg )
dialog.Show()
return dialog
END FUNCTION

Function parseJsonPosts(json)
tmpList = CreateObject("roArray", 28, true)

count = 0
for each curShow in json.Videos

'fetch all values from the xml for the current show
item.ContentId = curShow.ContentId
item.ContentType = "episode"
item.Title = curShow.Title
item.Description = curShow.Description
item.Length = curShow.Length
item.Rating = curShow.Rating
item.StarRating = curShow.StarRating
item.Categories = curShow.Categories
item.Director = curShow.Director
item.Actors = curShow.Actors
item.ReleaseDate = curShow.ReleaseDate
item.StreamFormat = curShow.StreamFormat
item.StreamBitrates = curShow.StreamBitrates
item.StreamUrl = curShow.StreamUrl
item.SubtitleUrl = curShow.SubtitleUrl
item.StreamQualities = curShow.StreamQualities
item.HDPosterUrl = curShow.HDPosterUrl
item.SDPosterUrl = curShow.SDPosterUrl
'Set Default screen values for items not in feed
item.HDBranded = curShow.SubtitleUrl
item.IsHD = curShow.SubtitleUrl
item.fullHD = curShow.fullHD
item.Categories = curShow.Categories
item.Actors = curShow.Actors
item.Director = curShow.Director
item.Font = "Large"
item.TextAttrs = {
Color:"#FFCCCCCC",
Font:"Large",
HAlign:"HCenter",
VAlign:"VCenter",
Direction:"LeftToRight"
}
count = count+1
tmpList.Push(item)

end for

return tmpList
END FUNCTION


the json

{"Videos":[{"ContentId":"2162","ContentType":"movie","Title":"Rocky 1 (4K)","Description":"When world heavyweight boxing champ Apollo Creed wants to give an unknown fighter a shot at the title as a publicity stunt, his handlers pick palooka Rocky Balboa, an uneducated collector for a Philadelphia loan shark.","Watched":true,"Length":"7140","Rating":"PG","StarRating":77,"Categories":"4k ","Director":"John G. Avildsen","Actors":"Sylvester Stallone, Talia Shire, Burt Young, Carl Weathers","ReleaseDate":"1976","StreamFormat":"MKV","StreamBitrates":"0","StreamUrl":"20Latino.mkv","SDPosterUrl":"1451440544587.jpg","HDPosterUrl":"1451440544587.jpg","SubtitleUrl":"1451440689145.srt","quality":true,"HDBranded":true,"isHD":true,"fullHD":false}]}



the problem generated
Our system http://www.rokumanager.com
0 Kudos
3 REPLIES 3
belltown
Roku Guru

Re: help with code please

item.
0 Kudos
hugetv
Visitor

Re: help with code please

ok it is that I found this app https://github.com/barbergeek/fairfaxcc/tree/master

and I want to do the same with my app to open fast with this

This is my current code for my movies


Sub showMoviesScreen()
dlg = CreateObject("roOneLineDialog")
dlg.setTitle("Loading Collection")
dlg.showBusyAnimation()
dlg.show()
screen = CreateObject("roGridScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)
screen.SetGridStyle("flat-portrait")
screen.SetDescriptionVisible(true)
screen.SetBreadcrumbText("Movies", "Session")

categoryList = getCategoryListMovies()
categoryCount = categoryList.count()

seriesList = CreateObject("roList")

screen.SetupLists(categoryCount)
screen.show()
screen.setListNames(categoryList)

for i = 0 to categoryCount-1
tmpMoviesList = getMoviesByCategory(categoryList[i])
screen.SetContentList(i,tmpMoviesList)
seriesList.AddTail(tmpMoviesList)
screen.show()
end for

screen.show()

dlg.close()
while true
msg = wait(0, port)

if msg <> invalid and type(msg) = "roGridScreenEvent" then
if msg.isScreenClosed() then
exit while
else if msg.isListItemFocused()
print "Focused msg: ";msg.GetMessage();"row: ";msg.GetIndex();
print " col: ";msg.GetData()
else if msg.isListItemSelected() then
print "Selected msg: ";msg.GetMessage();"row: ";msg.GetIndex();
'selection = seriesList.GetEntry(msg.GetIndex())[msg.GetData()]

list = seriesList.GetEntry(msg.GetIndex())
if list <> invalid then
selection = list[msg.GetData()]
end if

if selection.Title = "Search"
searchMovies()
else if selection.Title = "Favorites"
FavoritesMovies()
else
showSpringboardScreenMovies(selection)
end if

end if
end if
end while

End Sub

Function getCategoryListMovies() as object
jsonAsString = CreateObject("roUrlTransfer")
jsonAsString.SetURL(UrlServidor()+"/category.php?t=movies")
json = ParseJson(jsonAsString.GetToString())
return json
End Function


Function getMoviesByCategory(category)
jsonAsString = CreateObject("roUrlTransfer")
jsonAsString.SetURL(UrlServidor()+"/movies.php?cat="+category)
json = ParseJson(jsonAsString.GetToString())
return json.Videos

End Function



that I have to do to be like that of the
Our system http://www.rokumanager.com
0 Kudos
hugetv
Visitor

Re: help with code please

I can help to load the covers as fast as 1,000 movies surpasses the content is put slow loading :? :? :?: :?: :?: :idea: :idea:
Our system http://www.rokumanager.com
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.