Allow people to vote in videos/streams on youtube

Hello. I currently have some code working that reads a discussion page and looks for a keyword (!type), i’m wondering how exactly would i turn it into a thing to read: (preferably stream comments) or video comments.

import processing.net.*;
int counter = 0;
void setup(){size(1600,1000);}
void draw(){
counter = 0;
String[] page = loadStrings("REPLACE THIS WITH DISCUSSION URL");
for (int i = 0; i < page.length; i++){
String search = "!type ";
String toBeSearched = page[i];
int index = toBeSearched.indexOf(search);
String search2 = "comment-text-toggle hid";
int index2 = toBeSearched.indexOf(search2);
if(index>0) search = "comment-renderer-text-content";
if(index>0) index = toBeSearched.indexOf(search);
if(index>0){counter++;}
if(index>0){text(page[i].substring(index+30, index2-18),100,counter*50);}
}
}

It works well with the discussion page, I just want something less permanent to allow viewers to use

1 Like

I’m not sure what you mean by stream comments – are you trying to create a bot that reads YouTube comments and then posts the responses to YouTube? Or are you trying to compile a report on something (like the keyword “shoes”) and then put the information… where?

1 Like

Never mind, I managed to get a version of this to work for youtube comments:

import processing.net.*;
int counter = 0;
int minute;
int[] counts = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int[] resetcounts = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
String[] names = {"flip","regeneration","zombie","witch","spider","creeper","skeleton","blindness","levitation","slowness","poison"};
String[] commands = {
"tp @a ~ ~ ~ ~180 ~",
"effect give @a minecraft:regeneration 10 1",
"execute at @a as @a run summon minecraft:zombie",
"execute at @a as @a run summon minecraft:witch",
"execute at @a as @a run summon minecraft:spider",
"execute at @a as @a run summon minecraft:creeper",
"execute at @a as @a run summon minecraft:skeleton",
"effect give @a minecraft:blindness 20 1",
"effect give @a minecraft:levitation 1 10",
"effect give @a minecraft:slowness 20 0",
"effect give @a minecraft:poison 10 0"};
String desiredname;
int desiredid;
String[] temporary;
void setup(){size(10,10);
String[] page = loadStrings("https://www.youtube.com/watch?v=CKuK41VMv0E&lc=all");
minute = minute();
counts = resetcounts;

counter = 0;
for (int i = 0; i < page.length; i++){
for (int x = 0; x < counts.length; x++){
String prefix = "!";
String search = prefix + names[x];
String toBeSearched = page[i];
int index = toBeSearched.indexOf(search);
String search2 = "seconds ago";
if (index>0) index = toBeSearched.indexOf(search2);
if(index>0){counts[x]++;}
}
}
int desiredvalue = max(counts);
if (desiredvalue>0){
for (int x = 0; x < counts.length; x++){
if (counts[x] == desiredvalue){desiredname = names[x];}
if (counts[x] == desiredvalue){desiredid = x;}  
}
print(desiredname);
println(" has been chosen to run");
}
if (desiredvalue==0){print("No votes in the past minute.");}
if (desiredvalue>0){temporary = split(commands[desiredid], '#');}
if (desiredvalue>0){saveStrings("/Users/mac/Library/Application Support/minecraft/saves/Datapack test/datapacks/demo/data/demo/functions/init.mcfunction",temporary);}
}

Thanks for trying to help me anyways though

2 Likes