Code Monkey home page Code Monkey logo

youtube-data-list's Introduction

youtube-data-list

Makes use of the Youtube Data list functions. Retrieve information about videos, channels, comments, playlists. Search normally or by location.

Also allows you to measure total quota used during it's instantiation.

Google provides a guide to obtaining a youtube data key. The Data API documentation is a good resource to see what information can be gathered with each list function. However, this library does not implement parameters and options that require authorization.

Some code examples:

YouTubeData3 data = new YouTubeData3("youtubeDataApiKeyHere");

// Comments posted on a video:
try {
    CommentThreadsList ctl;
    String pageToken = "";
    int pages = 0;
    do {
        ctl = ((CommentThreadsList) data.commentThreadsList().part(Parts.SNIPPET))
                .getThreadsByVideo("dQw4w9WgXcQ", pageToken);
        pageToken = ctl.getNextPageToken();

        if(ctl.hasItems()) {
            for(CommentThreadsList.Item item : ctl.getItems()) {
                if(item.hasSnippet()) {
                    CommentsList.Item.Snippet topLevelComment = item.getSnippet().getTopLevelComment().getSnippet();

                    String author = topLevelComment.getAuthorDisplayName();
                    String comment = topLevelComment.getTextDisplay();

                    System.out.printf("%s: %s\r\n", author, comment);
                }
            }
        } else {
            System.out.println("CommentThreadsList example didn't return any results.");
        }
        pages++;
    } while (ctl.getNextPageToken() != null && pages < 3);
} catch (YouTubeErrorException e) {
    System.out.println(e.getError().getMessage());
}

// Find videos near you:
try {
    SearchList sl;
    String pageToken = "";
    int pages = 0;
    do {
        // Location takes latitude,longitude and a radius using m, km, ft, or mi.
        sl = ((SearchList) data.searchList().part(Parts.SNIPPET))
                .order(SearchList.ORDER_DATE)
                .getByLocation("", pageToken, "40.2822047,-76.9154449", "1mi");
        pageToken = sl.getNextPageToken();

        if(sl.hasItems()) {
            for(SearchList.Item item : sl.getItems()) {
                if(item.hasSnippet()) {
                    SearchList.Item.Snippet snippet = item.getSnippet();

                    String date = snippet.getPublishedAt().toString();
                    String channelTitle = snippet.getChannelTitle();
                    String videoTitle = snippet.getTitle();
                    String videoId = item.getId().getVideoId();

                    System.out.printf("%s  https://youtu.be/%s (%s): %s\r\n",
                            date, videoId, channelTitle, videoTitle);
                }
            }
        } else {
            System.out.println("SearchList example didn't return any results.");
        }
        pages++;
    } while (sl.getNextPageToken() != null && pages < 3);
} catch (YouTubeErrorException e) {
    System.out.println(e.getError().getMessage());
}

// See how much quota you used!
System.out.printf("Total quota units spent this session: %,d\n\n", data.getTotalSpentCost());

youtube-data-list's People

Contributors

mattwright324 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

utsavg aydroiddev

youtube-data-list's Issues

No longer maintaining this project.

This library was in support of my other project youtube-comment-suite when I had an archaic & manual dependency management process (finding online and downloading only). It was created because using Google's official library was difficult having find all dependencies it required.

I have since replaced its use in YCS with the official YouTube API for Java by Google with the use of Maven for sane dependency management.

<dependency>
    <groupId>com.google.apis</groupId>
    <artifactId>google-api-services-youtube</artifactId>
    <version>v3-rev212-1.25.0</version>
</dependency>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.