Hi all.
With this class compatible for B4X (B4A, B4i, B4J? I haven't tried) you can read and import all the information coming from youtube into your application.
Etag, Title, Description, PublisheAt, Urlpicture, categoryId, channelTitle, Definition, dimension, PrivacyStatus, dislikeCount, likeCount, viewCount, CommentCount, Duration
Note Duration return example: PT15M33S this is 15 minutes and 33 seconds.
And more.... this version is very fast look movie in youtube.
For this example you need also Class CustomListView and ImageDownloader
Example Code:
Enjoy
Marco
With this class compatible for B4X (B4A, B4i, B4J? I haven't tried) you can read and import all the information coming from youtube into your application.
Etag, Title, Description, PublisheAt, Urlpicture, categoryId, channelTitle, Definition, dimension, PrivacyStatus, dislikeCount, likeCount, viewCount, CommentCount, Duration
Note Duration return example: PT15M33S this is 15 minutes and 33 seconds.
And more.... this version is very fast look movie in youtube.
For this example you need also Class CustomListView and ImageDownloader
Example Code:
B4X:
Code module
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 7
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Private CLV1 As CustomListView
Dim preleva As Map
Dim nextpage, prevpage As String
Dim p1 As Int
Dim yt As youtube
Dim key As String = "AIzaxxxx"
Dim maxresult As Int = 10
Dim order = "title"
Dim channelId As String = "UC2rtpKv9X9pfwCuaEt9wsrQ"
Dim playlist As String = "PL3DC5149322C58874"
Dim search As String = "Ricky Martin"
Dim cosaleggo As String = ""
Private btn_reading_channel As Button
Private btn_reading_pl As Button
Private btn_seach_pl As Button
Private btn_search_channel As Button
Private btn_search_video As Button
Private lbl_type As Label
Private btn_avanti As Button
Private btn_indietro As Button
Dim hd As HUD
Private btn2 As Button
Private ImageView1 As ImageView
Private lbl_primo As Label
Dim Downloader As ImageDownloader
End Sub
Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
Page1.RootPanel.LoadLayout("main")
NavControl.ShowPage(Page1)
preleva.Initialize
Downloader.Initialize
lbl_type.Text = "SEARCH VIDEO - Ricky Martin"
yt.Initialize(key, True)
yt.SearchVideo( maxresult, search, "", "", "", Me, "search_video")
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
End Sub
Private Sub Application_Background
End Sub
Sub details_page(DVideo As DetailsVideo)
LogColor("Title: " & DVideo.title(0), Colors.Blue)
Log("Description: " & DVideo.descriptionc(0) )
Log("Pubblished At: " & DVideo.publishedAt(0) )
Log("Url Pictures: " & DVideo.urlpicture(0) )
Log("Etag: " & DVideo.Etag(0) )
Log("CategoryId: " & DVideo.CategoryId(0) )
Log("ChannelTitle: " & DVideo.channelTitle(0) )
Log("Definition: " & DVideo.Definition(0) )
Log("Dimension: " & DVideo.Dimension(0) )
Log("PrivacyStatus: " & DVideo.PrivacyStatus(0) )
Log("disLikeCount: " & DVideo.DislikeCount(0) )
Log("LikeCount: " & DVideo.LikeCount(0) )
Log("ViewCount: " & DVideo.ViewCount(0) )
Log("CommentCount: " & DVideo.CommentCount(0) )
Log("Duration: " & DVideo.Duration(0) )
End Sub
Sub reading_channel(RChannel As ReadChannel)
cosaleggo = "reading_channel"
If RChannel.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & RChannel.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To RChannel.TotalChannel - 1
LogColor("Title: " & RChannel.title(p1), Colors.Blue)
Log("Description: " & RChannel.descriptionc(p1) )
Log("Pubblished At: " & RChannel.publishedAt(p1) )
Log("Url Pictures: " & RChannel.urlpicture(p1) )
Log("ID Channel: " & RChannel.idChannel(p1) )
Log("ID Video: " & RChannel.idVideo(p1))
If p1 = 0 Then
nextpage = RChannel.nextpage(p1)
prevpage = RChannel.prevpage(p1)
End If
preleva.Put("title" & p1, RChannel.title(p1))
preleva.Put("description" & p1, RChannel.descriptionc(p1))
preleva.Put("pubblished" & p1, RChannel.publishedAt(p1))
preleva.Put("url" & p1, RChannel.urlpicture(p1))
preleva.Put("idChannel" & p1, RChannel.idChannel(p1))
preleva.Put("id" & p1, RChannel.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub scroll_reading_channel(RChannel As ReadChannel)
cosaleggo = "reading_channel"
If RChannel.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & RChannel.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To RChannel.TotalChannel - 1
LogColor("Title: " & RChannel.title(p1), Colors.Blue)
Log("Description: " & RChannel.descriptionc(p1) )
Log("Pubblished At: " & RChannel.publishedAt(p1) )
Log("Url Pictures: " & RChannel.urlpicture(p1) )
Log("ID Channel: " & RChannel.idChannel(p1) )
If p1 = 0 Then
nextpage = RChannel.nextpage(p1)
prevpage = RChannel.prevpage(p1)
End If
preleva.Put("title" & p1, RChannel.title(p1))
preleva.Put("description" & p1, RChannel.descriptionc(p1))
preleva.Put("pubblished" & p1, RChannel.publishedAt(p1))
preleva.Put("url" & p1, RChannel.urlpicture(p1))
preleva.Put("idChannel" & p1, RChannel.idChannel(p1))
preleva.Put("id" & p1, RChannel.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub reading_playlist(RPList As ReadingPlayList)
cosaleggo = "reading_playlist"
If RPList.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & RPList.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To RPList.TotalChannel - 1
LogColor("Title: " & RPList.title(p1), Colors.Blue)
Log("Description: " & RPList.descriptionc(p1) )
Log("Pubblished At: " & RPList.publishedAt(p1) )
Log("Url Pictures: " & RPList.urlpicture(p1) )
Log("ID Video: " & RPList.idVideo(p1) )
If p1 = 0 Then
nextpage = RPList.nextpage(p1)
prevpage = RPList.prevpage(p1)
End If
preleva.Put("title" & p1, RPList.title(p1))
preleva.Put("description" & p1, RPList.descriptionc(p1))
preleva.Put("pubblished" & p1, RPList.publishedAt(p1))
preleva.Put("url" & p1, RPList.urlpicture(p1))
preleva.Put("id" & p1, RPList.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub scroll_reading_playlist(RPList As ReadingPlayList)
cosaleggo = "reading_playlist"
If RPList.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & RPList.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To RPList.TotalChannel - 1
LogColor("Title: " & RPList.title(p1), Colors.Blue)
Log("Description: " & RPList.descriptionc(p1) )
Log("Pubblished At: " & RPList.publishedAt(p1) )
Log("Url Pictures: " & RPList.urlpicture(p1) )
Log("ID Video: " & RPList.idVideo(p1) )
If p1 = 0 Then
nextpage = RPList.nextpage(p1)
prevpage = RPList.prevpage(p1)
End If
preleva.Put("title" & p1, RPList.title(p1))
preleva.Put("description" & p1, RPList.descriptionc(p1))
preleva.Put("pubblished" & p1, RPList.publishedAt(p1))
preleva.Put("url" & p1, RPList.urlpicture(p1))
preleva.Put("id" & p1, RPList.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub search_channel(SChannel As SearchChannel)
cosaleggo = "search_channel"
If SChannel.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SChannel.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SChannel.TotalChannel - 1
LogColor("Title: " & SChannel.title(p1), Colors.Blue)
Log("Channel Title: " & SChannel.ChannelTitle(p1))
Log("Description: " & SChannel.descriptionc(p1) )
Log("Pubblished At: " & SChannel.publishedAt(p1) )
Log("Url Pictures: " & SChannel.urlpicture(p1) )
Log("ID Channel: " & SChannel.ChannelId(p1) )
If p1 = 0 Then
nextpage = SChannel.nextpage(p1)
prevpage = SChannel.prevpage(p1)
End If
preleva.Put("title" & p1, SChannel.title(p1))
preleva.Put("description" & p1, SChannel.descriptionc(p1))
preleva.Put("pubblished" & p1, SChannel.publishedAt(p1))
preleva.Put("url" & p1, SChannel.urlpicture(p1))
preleva.Put("id" & p1, SChannel.ChannelId(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub scroll_search_channel(SChannel As SearchChannel)
cosaleggo = "search_channel"
If SChannel.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SChannel.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SChannel.TotalChannel - 1
LogColor("Title: " & SChannel.title(p1), Colors.Blue)
Log("Channel Title: " & SChannel.ChannelTitle(p1))
Log("Description: " & SChannel.descriptionc(p1) )
Log("Pubblished At: " & SChannel.publishedAt(p1) )
Log("Url Pictures: " & SChannel.urlpicture(p1) )
Log("ID Channel: " & SChannel.ChannelId(p1) )
If p1 = 0 Then
nextpage = SChannel.nextpage(p1)
prevpage = SChannel.prevpage(p1)
End If
preleva.Put("title" & p1, SChannel.title(p1))
preleva.Put("description" & p1, SChannel.descriptionc(p1))
preleva.Put("pubblished" & p1, SChannel.publishedAt(p1))
preleva.Put("url" & p1, SChannel.urlpicture(p1))
preleva.Put("id" & p1, SChannel.ChannelId(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub search_playlist(SPList As SearchPlayList)
cosaleggo = "search_playlist"
If SPList.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SPList.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SPList.TotalChannel - 1
LogColor("Title: " & SPList.title(p1), Colors.Blue)
Log("Channel Title: " & SPList.ChannelTitle(p1))
Log("Description: " & SPList.descriptionc(p1) )
Log("Pubblished At: " & SPList.publishedAt(p1) )
Log("Url Pictures: " & SPList.urlpicture(p1) )
Log("ID PlayList: " & SPList.PlayListId(p1) )
If p1 = 0 Then
nextpage = SPList.nextpage(p1)
prevpage = SPList.prevpage(p1)
End If
preleva.Put("title" & p1, SPList.title(p1))
preleva.Put("description" & p1, SPList.descriptionc(p1))
preleva.Put("pubblished" & p1, SPList.publishedAt(p1))
preleva.Put("url" & p1, SPList.urlpicture(p1))
preleva.Put("id" & p1, SPList.PlayListId(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).Append(CRLF).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub scroll_search_playlist(SPList As SearchPlayList)
cosaleggo = "search_playlist"
If SPList.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SPList.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SPList.TotalChannel - 1
LogColor("Title: " & SPList.title(p1), Colors.Blue)
Log("Channel Title: " & SPList.ChannelTitle(p1))
Log("Description: " & SPList.descriptionc(p1) )
Log("Pubblished At: " & SPList.publishedAt(p1) )
Log("Url Pictures: " & SPList.urlpicture(p1) )
Log("ID PlayList: " & SPList.PlayListId(p1) )
If p1 = 0 Then
nextpage = SPList.nextpage(p1)
prevpage = SPList.prevpage(p1)
End If
preleva.Put("title" & p1, SPList.title(p1))
preleva.Put("description" & p1, SPList.descriptionc(p1))
preleva.Put("pubblished" & p1, SPList.publishedAt(p1))
preleva.Put("url" & p1, SPList.urlpicture(p1))
preleva.Put("id" & p1, SPList.PlayListId(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub search_video(SVideo As SearchVideo)
cosaleggo = "search_video"
If SVideo.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SVideo.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SVideo.TotalChannel - 1
LogColor("Title: " & SVideo.title(p1), Colors.Blue)
Log("Description: " & SVideo.descriptionc(p1) )
Log("Pubblished At: " & SVideo.publishedAt(p1) )
Log("Url Pictures: " & SVideo.urlpicture(p1) )
Log("ID Video: " & SVideo.idVideo(p1) )
If p1 = 0 Then
nextpage = SVideo.nextpage(p1)
prevpage = SVideo.prevpage(p1)
End If
preleva.Put("title" & p1, SVideo.title(p1))
preleva.Put("description" & p1, SVideo.descriptionc(p1))
preleva.Put("pubblished" & p1, SVideo.publishedAt(p1))
preleva.Put("url" & p1, SVideo.urlpicture(p1))
preleva.Put("id" & p1, SVideo.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).Append(CRLF).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub scroll_search_video(SVideo As SearchVideo)
cosaleggo = "search_video"
If SVideo.TotalChannel > 0 Then CLV1.Clear
LogColor("Total Results: " & SVideo.totalResults, Colors.Red)
Dim p1 As Int
For p1 = 0 To SVideo.TotalChannel - 1
LogColor("Title: " & SVideo.title(p1), Colors.Blue)
Log("Description: " & SVideo.descriptionc(p1) )
Log("Pubblished At: " & SVideo.publishedAt(p1) )
Log("Url Pictures: " & SVideo.urlpicture(p1) )
Log("ID Video: " & SVideo.idVideo(p1) )
If p1 = 0 Then
nextpage = SVideo.nextpage(p1)
prevpage = SVideo.prevpage(p1)
End If
preleva.Put("title" & p1, SVideo.title(p1))
preleva.Put("description" & p1, SVideo.descriptionc(p1))
preleva.Put("pubblished" & p1, SVideo.publishedAt(p1))
preleva.Put("url" & p1, SVideo.urlpicture(p1))
preleva.Put("id" & p1, SVideo.idVideo(p1))
Dim cs As CSBuilder
cs.Initialize.Font(Font.DEFAULT_BOLD).Color(Colors.Red).Append(preleva.Get("title" & p1)).PopAll
cs.Append(preleva.Get("description" & p1))
CLV1.Add(CreateListItem( cs, preleva.Get("url" & p1), CLV1.GetBase.Width, 25%x), "")
Next
End Sub
Sub btn2_Click
Dim Btn As Button = Sender
Log(Btn.Tag)
hd.ToastMessageShow("ID: " & Btn.Tag, True)
End Sub
Sub btn_search_video_Click
CLV1.Clear
nextpage = ""
prevpage = ""
yt.SearchVideo( maxresult, search, order, "", "", Me, "scroll_search_video")
hd.ToastMessageShow("Search Video: Ricky Martin", True)
lbl_type.TextColor = Colors.Red
lbl_type.Text = "SEARCH VIDEO - Ricky Martin"
End Sub
Sub btn_search_channel_Click
CLV1.Clear
nextpage = ""
prevpage = ""
yt.SearchChannel( maxresult, search, "", "", Me, "scroll_search_channel")
hd.ToastMessageShow("Search Channel: Ricky Martin", True)
lbl_type.TextColor = Colors.Red
lbl_type.Text = "SEARCH CHANNEL - Ricky Martin"
End Sub
Sub btn_seach_pl_Click
CLV1.Clear
nextpage = ""
prevpage = ""
yt.SearchPlayList( maxresult, search, "", "", "", Me, "scroll_search_playlist")
hd.ToastMessageShow("Search Play List: Ricky Martin", True)
lbl_type.TextColor = Colors.Red
lbl_type.Text = "SEARCH PLAYLIST - Ricky Martin"
End Sub
Sub btn_reading_pl_Click
CLV1.Clear
nextpage = ""
prevpage = ""
yt.ReadingPlayList(maxresult, playlist, Me, "scroll_reading_playlist")
hd.ToastMessageShow("Reading Play List: PL0BBE53C9127C3B45", True)
lbl_type.TextColor = Colors.Red
lbl_type.Text = "READING PLAYLIST - PL0BBE53C9127C3B45"
End Sub
Sub btn_reading_channel_Click
CLV1.Clear
nextpage = ""
prevpage = ""
yt.ReadingChannel( maxresult, channelId, order, "", Me, "scroll_reading_channel")
hd.ToastMessageShow("Reading Channel: UC2rtpKv9X9pfwCuaEt9wsrQ", True)
lbl_type.TextColor = Colors.Red
lbl_type.Text = "READING CHANNEL - UC2rtpKv9X9pfwCuaEt9wsrQ"
End Sub
'Page Previous
Sub btn_indietro_Click
Select cosaleggo
Case "reading_channel"
yt.ReadingChannelPage("", prevpage, maxresult, channelId, order, "", Me, "scroll_reading_channel")
Case "reading_playlist"
yt.ReadingPlayListPage("", prevpage,maxresult, playlist, Me, "scroll_reading_playlist")
Case "search_channel"
yt.SearchChannelPage("", prevpage, maxresult, search, "", "", Me, "scroll_search_channel")
Case "search_playlist"
yt.SearchPlayListPage("", prevpage, maxresult, search, "", "", "", Me, "scroll_search_playlist")
Case "search_video"
yt.SearchVideoPage("", prevpage, maxresult, search, order, "", "", Me, "scroll_search_video")
End Select
End Sub
'Page Next
Sub btn_avanti_Click
Select cosaleggo
Case "reading_channel"
yt.ReadingChannelPage(nextpage, "", maxresult, channelId, order, "", Me, "scroll_reading_channel")
Case "reading_playlist"
yt.ReadingPlayListPage(nextpage, "",maxresult, playlist, Me, "scroll_reading_playlist")
Case "search_channel"
yt.SearchChannelPage(nextpage, "", maxresult, search, "", "", Me, "scroll_search_channel")
Case "search_playlist"
yt.SearchPlayListPage(nextpage, "", maxresult, search, "", "", "", Me, "scroll_search_playlist")
Case "search_video"
yt.SearchVideoPage(nextpage, "", maxresult, search, order, "", "", Me, "scroll_search_video")
End Select
End Sub
Sub CreateListItem(Text As CSBuilder, name_image As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
p.SetLayoutAnimated(0, 1, 0, 0, Width, Height) 'set the size before the layout is loaded
p.LoadLayout("lay_clv")
lbl_primo.AttributedText = Text
'Immagina Carico dal Sito B4A / B4i
Dim m As Map
m.Initialize
#if B4i
m.Put(ImageView1, name_image)
Downloader.Download(m)
#else if B4A
m.Put(ImageView1, name_image)
CallSubDelayed2(ImageDownloader, "Download", m)
#End If
Return p
End Sub
Sub clv1_ItemClick (Index As Int, Value As Object)
'Page1.Title = Value
End Sub
Enjoy
Marco
Attachments
Last edited: