Reading "likes" data from YouTube video
in
Programming Questions
•
11 months ago
Can anyone help me rewrite my code to create a getDislikes function as well as a getLikes function?
I need my video to play from the number of likes plus thel number of dislikes multiplied by the set amount of milliseconds.
Would really appreciate anyone who can help me rewrite this code to get a getDislikes function to multiply with the getLikes function. Very new to this, hope someone can help me out. Thank you.
- void setup()
- {
- size(800, 600, P2D);
- loadVideo("sheep2.mov");
- }
- void script()
- {
- playVideoFrom(75130 * getLikes("http://www.youtube.com/watch?v=5Isg9f8mumk"));
- delay(12504);
- }
- int getLikes(String url)
- {
- int likes = 0;
- String[] lines = loadStrings(url);
- for (int i=0; i<lines.length ;i++) {
- if (lines[i].contains(" dislikes")) {
- int likesStart = lines[i].indexOf(">")+1;
- int likesEnd = lines[i].indexOf("</span");
- String likesString = lines[i].substring(likesStart,likesEnd);
- likes = int(likesString.replace(",",""));
- int dislikesStart = lines[i].indexOf(">",likesEnd+10)+1;
- int dislikesEnd = lines[i].indexOf("</span",dislikesStart);
- String dislikesString = lines[i].substring(dislikesStart,dislikesEnd);
- int dislikes = int(dislikesString.replace(",",""));
- println(likes);
- println(dislikes);
- }
- }
- return likes;
- }
I need my video to play from the number of likes plus thel number of dislikes multiplied by the set amount of milliseconds.
Would really appreciate anyone who can help me rewrite this code to get a getDislikes function to multiply with the getLikes function. Very new to this, hope someone can help me out. Thank you.
1