New big update for Youtube Parser: video stats and much more

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:

  • Title
  • Link
  • 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:

  • View
  • Like
  • Dislike
  • 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.

Of course the library is available also on jCenter so you can easily add the dependency on Gradle.

dependencies {
  compile ''

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, 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.


Parser parser = new Parser();

// --> channel id = UCVHFbqXqoYvEWM1Ddxl0QDg
//The maximum number of result to show is 50
//ORDER_TYPE --> by date: "Parser.ORDER_DATE" or by number of views: "ORDER_VIEW_COUNT"  
String url = parser.generateRequest(CHANNEL_ID, 20, Parser.ORDER_DATE, API_KEY);
parser.onFinish(new Parser.OnTaskCompleted() {

    public void onTaskCompleted(ArrayList<Video> list, String nextPageToken) {
      //what to do when the parsing is done
      //the ArrayList contains all video data. For example you can use it for your adapter

    public void onError() {
        //what to do in case of error

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.

String url = parser.generateMoreDataRequest(CHANNEL_ID, 20, Parser.ORDER_DATE, API_KEY, nextToken);

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.


VideoStats videoStats = new VideoStats();
String url = videoStats.generateStatsRequest(videoId, API_KEY);
videoStats.onFinish(new VideoStats.OnTaskCompleted() {
  public void onTaskCompleted(Statistics stats) {
      //Here you can set the statistic to a Text View for instance

      //for example:
      String body = "Views: " + stats.getViewCount() + "\n" +
                    "Like: " + stats.getLikeCount() + "\n" +
                    "Dislike: " + stats.getDislikeCount() + "\n" +
                    "Number of comment: " + stats.getCommentCount() + "\n" +
                    "Number of favourite: " + stats.getFavoriteCount();
  public void onError() {
      //what to do in case of error

That’s all! Please let me know if you notice any bug or if you have any advice that can improve this library.