Finally I’ve released a new big update for YoutubeParser. For people who don’t know what I’m talking about, don’t worry now I’m going to explain all.
YoutubeParser is the first Android library that I ever wrote. With this library it is possible to get information of videos from Youtube channels. These information are:
- Thumbnail, with three different image size.
After a year I’ve released this new big update, named 2.0, that introduces a bunch of new things. First of all, now it is possible to load more than 50 videos from the same channel. 50 is the maximum number of videos that can be retrieved with a single request.
Furthermore you can also get the statistics of a video:
- Favorite Count
- Comment Count
The source code of the library is on Github together with a sample application that shows what you can do with the library.
- Click here to view the library on Github
- Click here to show the code of the sample app
- Click here to download the app
Of course the library is available also on jCenter so you can easily add the dependency on Gradle.
Now let’s look how it works. First of all you need to create a new Parser Object and then you have to create the url to load the data by using the method generateRequest. This method takes as parameter four values:
- The Channel ID of a Youtube Channel. For example, for this link youtube.com/channel/UCVHFbqXqoYvEWM1Ddxl0QDg, the Channel ID is: UCVHFbqXqoYvEWM1Ddxl0QDg
- The maximum number of videos to show. This value can be maximum 50.
- The type of ordering of the videos. It is possible to choose between two different type of ordering: by date or by views. To select the chosen value you have to use the constants: Parser.ORDER_DATE and Parser.ORDER_VIEW_COUNT
- The API Key. The key is a BROSWER API KEY and to create it you can follow this guide
If the data are correctly retrieved, you can do your stuff inside the onTaskCompleted. Here you have two variable: an ArrayList of Video items that you can use to populate your view for instance and a token that is necessary to load more data (see below for more details).
If there are some error on the process, you can handle the situation in the onError() method.
If you want to retrieved more videos from the same channel, the procedure is the same of the above case. The only difference is the method that generate the url; here you have to add the token retrieved from the above procedure.
To get the statistics of a single video, the procedure is equivalent of the previous. As you can guess, the first thing to do is to generate the url with the generateStatsRequest method. The parameter of this method are:
- The ID of a Youtube Video
- The API Key
Also here you can handle the result in the onTaskCompleted method and any error in the onError() method.
That’s all! Please let me know if you notice any bug or if you have any advice that can improve this library.