B4A Library [Class B4X ] YouTube V3

Hi all.
This is new version 2.00
Now is possibile NextPage and PreviousPage.
For any movie you have all details as:
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.


YouTubeList
Author:
Devil-App
Version: 2.05

YouTubeList
Author: Devil-App
Version: 2

  • Methods:
    • IsInitialized As Boolean

    • Tests whether the object has been initialized.
      [*]detailsvideo (id As String, Module As Object, EventName As String) As String


      Example
      yt.DeatilsVideo( id, Me, "details_page")

      id = Id Video YouTube type: "7lCDEYXw3mM"


      [*]initialize (key As String, Log as Boolean) As String

      [*]readingchannel (maxresult As Int, channelId As String, order As String, videoDuration As String, Module As Object, EventName As String) As String
      maxresult = 0 to 50
      channelId = example --> "UCe5xLaib7HmDPbBp132t_9A"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is relevance )
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]readingchannelpage (nextpage As String, prevpage As String, maxresult As Int, channelId As String, order As String, videoDuration As String, Module As Object, EventName As String) As String


      Example
      For Next Page:
      yt.ReadingChannelPage(nextpage, "", maxresult, channelId, order, videoDuration, Me, "scroll_page")
      or
      For Previous Page
      yt.ReadingChannelPage("", prevpage, maxresult, channelId, order, videoDuration, Me, "scroll_page")

      maxresult = 0 to 50
      channelId = example --> "UCe5xLaib7HmDPbBp132t_9A"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is relevance )
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]readingplaylist (maxresult As Int, playlistId As String, Module As Object, EventName As String) As String

      maxresult = 0 to 50
      playlistId = example --> "PL63F0C78739B09958"


      [*]readingplaylistpage (nextpage As String, prevpage As String, maxresult As Int, playlistId As String, Module As Object, EventName As String) As String


      Example
      For Next Page:
      yt.ReadingPlayListPage(nextpage, "", maxresult, playlistId, Me, "scroll_page")
      or
      For Previous Page
      yt.ReadingPlayListPage("", prevpage, maxresult, playlistId, Me, "scroll_page")

      maxresult = 0 to 50
      playlistId = example --> "PL63F0C78739B09958"


      [*]searchchannel (maxresult As Int, search As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String

      maxresult = 0 to 50
      search = "Ricky Martin"
      regioncode = "IT" - "US" etc.
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]searchchannelpage (nextpage As String, prevpage As String, maxresult As Int, search As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String


      Example
      For Next Page:
      yt.SearchChannelPage(nextpage, "", maxresult, search, regionCode, videoDuration, Me, "scroll_page")
      or
      For Previous Page
      yt.SearchChannelPage("", prevpage, maxresult, search, regionCode, videoDuration, Me, "scroll_page")

      maxresult = 0 to 50
      search = "Ricky Martin"
      regioncode = "" is all or "IT" - "US" etc.
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]searchplaylist (maxresult As Int, search As String, order As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String

      maxresult = 0 to 50
      search = "Ricky Martin"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is revelance )
      regioncode = "IT" - "US" etc.
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]searchplaylistpage (nextpage As String, prevpage As String, maxresult As Int, search As String, order As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String


      Example
      For Next Page:
      yt.SearchPlayListPage(nextpage, "", maxresult, search, order, regionCode, videoDuration, Me, "scroll_page")
      or
      For Previous Page
      yt.SearchPlayListPage("", prevpage, maxresult, search, order, regionCode, videoDuration, Me, "scroll_page")

      maxresult = 0 to 50
      search = "Ricky Martin"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is revelance )
      regioncode = "IT" - "US" etc.
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]searchvideo (maxresult As Int, search As String, order As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String

      maxresult = 0 to 50
      search = "Ricky Martin"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is revelance )
      regioncode = "IT" - "US" etc. ( if "" default value is all world )
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )


      [*]searchvideopage (nextpage As String, prevpage As String, maxresult As Int, search As String, order As String, regionCode As String, videoDuration As String, Module As Object, EventName As String) As String


      Example
      For Next Page:
      yt.SearchVideoPage(nextpage, "", maxresult, search, order, "", "", Me, "scroll_page")
      or
      For Previous Page
      yt.SearchVideoPage("", prevpage, maxresult, search, order, "", "", Me, "scroll_page")

      nextpage = SVideo.nextpage(i)
      prevpage = SVideo.prevpage(i)
      maxresult = 0 to 50
      search = "Ricky Martin"
      order = date - rating - relevance - title - videoCount - viewCount ( if "" default value is revelance )
      regioncode = "IT" - "US" etc. ( if "" default value is all world )
      videoDuration = any - long( > 20 min.) - medium ( 4 min. to 20 min. ) - short ( if "" default value is any )




B4X:
Sub Activity_Create(FirstTime As Boolean)

    yt.Initialize(key)

    'For details Id Video
    'You have as Return:
    '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.
    'yt.DetailsVideo(id, Me,  "details_page")


    'yt.SearchVideo(maxresult, search, order, "", "", Me, "search_video")
    'yt.SearchVideoPage(nextpage, prevpage, maxresult, search, order, "", "", Me, "scroll_search_video")

    'yt.ReadingChannel(maxresult, channelId, order, "", Me, "reading_channel")
    'yt.ReadingChannelPage(nextpage, prevpage, maxresult, channelId, order, "", Me, "scroll_reading_channel")

    'yt.ReadingPlayList( maxresult, playlist, Me, "reading_playlist")
    yt.ReadingPlayListPage(nextpage, prevpage,maxresult, playlist, Me, "scroll_reading_playlist")

    'yt.SearchChannel( maxresult, search, "", "", Me, "search_channel")
    'yt.SearchChannelPage(nextpage, prevpage, maxresult, search, "", "", Me, "scroll_search_channel")

    'yt.SearchPlayList(maxresult, search, "", "", "", Me, "search_playlist")
    'yt.SearchPlayListPage(nextpage, prevpage, maxresult, search, "", "", "", Me, "scroll_search_playlist")






End Sub

Sub details_page(DVideo As DetailsVideo)

       LogColor("Title: " & DVideo.title(0), Colors.Blue)
        Log("Description: " & DVideo.description(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 search_video(SVideo As SearchVideo)



    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.description(p1) )
        Log("Pubblished At: " &  SVideo.publishedAt(p1) )
        Log("Url Pictures: " &  SVideo.urlpicture(p1) )
        Log("ID Video: " & SVideo.idVideo(p1) )
        Log("Next Page: " & SVideo.nextpage(p1))
        Log("Prev Page: " & SVideo.prevpage(p1))
    Next



End Sub

Sub reading_channel(RChannel As ReadChannel)

    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.description(p1) )
        Log("Pubblished At: " &  RChannel.publishedAt(p1) )
        Log("Url Pictures: " &  RChannel.urlpicture(p1) )
        Log("ID Channel: " &  RChannel.idChannel(p1) )
        Log("Play List ID: " & RChannel.playlistid(p1) )
    Next

End Sub




Sub reading_playlist(RPList As ReadingPlayList)

    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.description(p1) )
        Log("Pubblished At: " &  RPList.publishedAt(p1) )
        Log("Url Pictures: " &  RPList.urlpicture(p1) )
        Log("ID Video: " & RPList.idVideo(p1) )
    Next

End Sub

Sub search_channel(SChannel As SearchChannel)

    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.description(p1) )
        Log("Pubblished At: " &  SChannel.publishedAt(p1) )
        Log("Url Pictures: " &  SChannel.urlpicture(p1) )
        Log("ID Channel: " &  SChannel.ChannelId(p1) )
    Next

End Sub



Sub search_playlist(SPList As SearchPlayList)

    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.description(p1) )
        Log("Pubblished At: " &  SPList.publishedAt(p1) )
        Log("Url Pictures: " &  SPList.urlpicture(p1) )
        Log("ID PlayList: " &  SPList.PlayListId(p1) )
    Next

End Sub



'**********Scroll

Sub scroll_search_video(Svideo As SearchVideo)

        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.description(p1) )
        Log("Pubblished At: " &  Svideo.publishedAt(p1) )
        Log("Url Pictures: " &  Svideo.urlpicture(p1) )
        Log("ID Video: " & Svideo.idVideo(p1) )
        Log("Next Page: " & Svideo.nextpage(p1))
        Log("Prev Page: " & Svideo.prevpage(p1))
        If p1 = 0 Then
            nextpage = Svideo.nextpage(p1)
            prevpage = Svideo.prevpage(p1)
        End If
    Next

 

End Sub


Sub scroll_reading_channel(RChannel As ReadChannel)

    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.description(p1) )
        Log("Pubblished At: " &  RChannel.publishedAt(p1) )
        Log("Url Pictures: " &  RChannel.urlpicture(p1) )
        Log("ID Channel: " &  RChannel.idChannel(p1) )
        Log("Play List ID: " & RChannel.playlistid(p1) )
        If p1 = 0 Then
            nextpage = RChannel.nextpage(p1)
            prevpage = RChannel.prevpage(p1)
        End If
    Next

End Sub

Sub scroll_reading_playlist(RPList As ReadingPlayList)

    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.description(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
    Next

End Sub

Sub scroll_search_channel(SChannel As SearchChannel)

    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.description(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
    Next

End Sub

Sub scroll_search_playlist(SPList As SearchPlayList)

    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.description(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
    Next

End Sub

'Next Page
Sub Activity_Click

    Log("*********************")
    'yt.SearchVideoPage(nextpage, "", maxresult, search, order, "", "", Me, "scroll_search_video")
    'yt.ReadingChannelPage(nextpage, "", maxresult, channelId, order, "", Me, "scroll_reading_channel")
    'yt.ReadingPlayListPage(nextpage, "",maxresult, playlist, Me, "scroll_reading_playlist")
    'yt.SearchChannelPage(nextpage, "", maxresult, search, "", "", Me, "scroll_search_channel")
    yt.SearchPlayListPage(nextpage, "", maxresult, search, "", "", "", Me, "scroll_search_playlist")


End Sub

'Previous Page
Sub Activity_LongClick
    Log("*********************")
    'yt.SearchVideoPage("", prevpage, maxresult, search, order, "", "", Me,  "scroll_search_video")
    'yt.ReadingChannelPage("", prevpage, maxresult, channelId, order, "", Me, "scroll_reading_channel")
    'yt.ReadingPlayListPage("", prevpage,maxresult, playlist, Me, "scroll_reading_playlist")
    'yt.SearchChannelPage("", prevpage, maxresult, search, "", "", Me, "scroll_search_channel")
    yt.SearchPlayListPage("", prevpage, maxresult, search, "", "", "", Me, "scroll_search_playlist")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

This example that you can download ( Apk ) utilize also ULV By Informatix and Universal Image Loader By Don Mandred



IF YOU TRY APK --> CLICK HERE
IN ATTACHMENT CLASS COMPATIBLE FOR B4X ( B4A, B4i )


 

Attachments

  • youtube.bas
    33.6 KB · Views: 489
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Looks great! Before I buy your library: Have you checked whether this library fulfils all requirements by Google?
I made a Youtube app with speech-driven search some time ago, but Google blocked it.

Nowadays they are very tough on app developers who violate their terms and conditions...
I know at first hand. This week I had to negotiate fiercely with their Play Store team to get an app re-instated. They are rule- and law-makers, ministry-of-justice, public prosecutor, police, judge and jury, all rolled into one...

Youtube is one of Google's prime activities, so there is a need to be extremely careful.
i don't know what you can use this library, but the same has been developed using the official API. So the problem is not the library but the use that you will do the same
 

rafaelbr20

Member
Licensed User
Longtime User
Hi ! I´m using the Library and i have a question.

I saw in log that Youtube Api returns a json with 3 image sizes, but your library shows only the High size. I need to use the image medium size, but how can i get this ?

See attached image !

The problem is the High size has a black line on top and at bottom side, see ..
 

Attachments

  • Captura de tela 2016-07-18 09.21.45.png
    Captura de tela 2016-07-18 09.21.45.png
    52.8 KB · Views: 191
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Hi ! I´m using the Library and i have a question.

I saw in log that Youtube Api returns a json with 3 image sizes, but your library shows only the High size. I need to use the image medium size, but how can i get this ?

See attached image !

The problem is the High size has a black line on top and at bottom side, see ..

High Size url :https://i.ytimg.com/vi/BQdVgRYhnNA/hqdefault.jpg

hqdefault.jpg



Medium Size url: https://i.ytimg.com/vi/BQdVgRYhnNA/mqdefault.jpg

mqdefault.jpg

If you need Medium Size you write:
B4X:
RChannel.urlpicture(p1).Replace("hqdefault.jpg","mqdefault.jpg")

If you need Default Size you write:
B4X:
RChannel.urlpicture(p1).Replace("hqdefault.jpg","default.jpg")
 

MarcoRome

Expert
Licensed User
Longtime User
Thank you for your answer. One more question, if I may: Does your library play "Live" Youtube streams, like: ...www.youtube.com/watch?v=0arz-vCGQ0Y
Erel's library does this.
This is necessary a Player or more simple you can call this:
B4X:
Private i As Intent
    i.Initialize(i.ACTION_VIEW, "https://www.youtube.com/watch?v=0arz-vCGQ0Y" )
    i.putExtra("force_fullscreen",True)
    i.SetComponent("com.google.android.youtube/.UrlActivity")
    StartActivity(i)
 

MarcoRome

Expert
Licensed User
Longtime User
The whole idea of buying and using your library is not to have to use intents to start the Youtube app.
Erel's library can play "Live" Youtube streams, so isn't it possible that you also add this ability to your library?

If you want YOU CAN create a wrapper of any library you want, with all functions you want. Or if you do not have the capacity at this site we have excellent writers of libraries (@DonManfred , @Johan Schoeman , etc) that you can pay to write the libraries as you wish.
 

MarcoRome

Expert
Licensed User
Longtime User
There are several mistakes in this code.
1. You should never disable strict mode.
2. You create a new HttpClient every time the activity is created.
3. Response.GetString is deprecated and should not be used (because it accesses the network on the main thread).

The solution is very simple. You should use OkHttpUtils2 instead of HttpClient.

Hi Erel, sorry what mean you comment ?
 

victormedranop

Well-Known Member
Licensed User
Longtime User
Hi, is the a hay to order descendent by date ?
last added first. i'm using yt.ReadingChannel(50,channel,"","date",Me,"scroll_reading_channel")
but got an error.
"message": "Invalid string value: 'date'. Allowed values: [any, long, medium, short]",

thanks
 

MarcoRome

Expert
Licensed User
Longtime User
Hi, is the a hay to order descendent by date ?
last added first. i'm using yt.ReadingChannel(50,channel,"","date",Me,"scroll_reading_channel")
but got an error.
"message": "Invalid string value: 'date'. Allowed values: [any, long, medium, short]",

thanks
Hi Vic, is wrong parameter

upload_2017-8-25_16-58-18.png



you write:
B4X:
yt.ReadingChannel(50,channel,"","date",Me,"scroll_reading_channel")

The correct code is:

B4X:
yt.ReadingChannel(50,channel,"date","any",Me,"scroll_reading_channel")
 
Top