YouTube Get the latest video

Java Version: 1.8.0_211-b12
OS Version: Windows 10 10.0 (x86)
Panel Version: 1.0.0
PhantomBot Version: 3.0.0

Is there any code for custom commands for me to make my latest youtube video. and the bot links my latest video from youtube.

it is doable if you build the bot yourself but maybe if we get enough votes the devs might add it into the bot but here is the smily code needed to be added into the youtube API java file

public String[] GetUserInfo(String channelId, String search) {
    com.gmt2001.Console.debug.println("Query = [" + search + "]");
    
    search = search.replaceAll("[^a-zA-Z0-9 ]", "");
    search = search.replace(" ", "%20");
        
    JSONObject jsonObject = GetData(request_type.GET, "https://www.googleapis.com/youtube/v3/search?channelId=" + channelId + "&key=" + apikey + "&part=snippet,id&order=date&maxResults=1&type=video&q=" + search);

    if (jsonObject.getBoolean("_success")) {
        if (jsonObject.getInt("_http") == 200) {
            updateQuota(2L);
            JSONArray items = jsonObject.getJSONArray("items");
            if (items.length() > 0) {
                JSONObject item = items.getJSONObject(0);
                JSONObject id = item.getJSONObject("id");
                JSONObject snippet = item.getJSONObject("snippet");

                com.gmt2001.Console.debug.println("ChannelID API Success");
                return new String[] { id.getString("videoId"), snippet.getString("title"), snippet.getString("publishedAt") };
            } else {
                com.gmt2001.Console.debug.println("ChannelID API Fail: Length == 0");
                return new String[] { "", "", ""};
            }
        } else {
            com.gmt2001.Console.debug.println("ChannelID API Fail: HTTP Code " + jsonObject.getInt("_http"));
            return new String[] { "", "", ""};
        }
    } else {
        com.gmt2001.Console.debug.println("ChannelID API Fatal Error");
        return new String[] { "", "", ""};
    }
}

once that is added you could make a custom script like this below

(function () {
    // /**
    //  * @event command
    //  */
    $.bind('command', function (event) {
        var sender = event.getSender().toLowerCase(),
            command = event.getCommand(),
            argsString = event.getArguments();

        if (command.equalsIgnoreCase('latestyt')) {

            data = $.youtube.GetUserInfo('UCuKJ0LqxI8t2a9ATl1rWBGA', argsString);
            videoId = data[0];
            videoTitle = data[1];
            videoDate = data[2];

            $.say($.whisperPrefix(sender) + videoDate + ' |  ' + videoTitle + ' | https://youtu.be/' + videoId);
        }
    });

    // /**
    //  * @event initReady
    //  */
    $.bind('initReady', function () {
        $.registerChatCommand('./custom/latestyt.js', 'latestyt', 7);
    });
})();

ScreenShot
image

1 Like

What would i need to download to paste that code into?

give this a read and add it into the youtubev3api file

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.