Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (($arguments->{body} =~ m/youtube\.com\/watch\?[^v]*v=([a-zA-Z0-9-_]*)/i)||($arguments->{body} =~ m/youtu\.be\/([a-zA-Z0-9-_]*)/i)) {
- $message = do_youtube($1);
- }
- sub do_youtube { # This function is called anytime a Youtube URL is encountered.
- $ytid = $_[0];
- if (int($ytlock{'YT!'.$ytid}) < time) {
- $ytlock{'YT!'.$ytid} = time + 5*60;
- if (length($ytlock{'YTC!'.$ytid}) > 1) {
- $message = $ytlock{'YTC!'.$ytid};
- }
- else
- {
- $response = $ua->get('https://www.googleapis.com/youtube/v3/videos?id='.$ytid.'&key='.$botytkey.'&fields=items(snippet(title),contentDetails(duration),statistics(viewCount,likeCount,dislikeCount))&part=snippet,contentDetails,statistics');
- $rbody = $response->decoded_content;
- $ytline = "fail";
- if ($rbody =~ m/^\{\n\s\"items\"\:\s\[\n\s\s\{\n\s\s\s\"snippet\"\:\s\{\n\s\s\s\s\"title\"\:\s\"(.*)\"\n\s\s\s\}\,\n\s\s\s\"contentDetails\"\:\s\{\n\s\s\s\s\"duration\"\:\s\"([PTHMS0123456789]*)\"\n\s\s\s\}\,\n\s\s\s\"statistics\"\:\s\{\n\s\s\s\s\"viewCount\"\:\s\"(\d*)\"\,\n\s\s\s\s\"likeCount\"\:\s\"(\d*)\"\,\n\s\s\s\s\"dislikeCount\"\:\s\"(\d*)\"\n\s\s\s\}\n\s\s\}\n\s\]\n\}$/s) {
- $duration = $2;
- $ytline = $1;
- $views = $3;
- $likes = $4;
- $dislikes = $5;
- if (int($likes) == 0) {
- $likes = 1;
- }
- $percentage = int((int($likes) / int(int($likes) + int($dislikes)))*100);
- $views = numprettify($views);
- $duration =~ s/^PT(\d+H)?(\d+M)?(\d+S)?$/$1:$2:$3/;
- $duration =~ s/[HMS]*//g;
- ($hours, $minutes, $seconds) = split(":", $duration);
- $hours = int($hours);
- $minutes = int($minutes);
- $seconds = int($seconds);
- $subject = " visningar";
- if (int($hours) > 0) {
- if (int($minutes) < 10) {
- $minutes = "0".$minutes;
- }
- if (int($seconds) < 10) {
- $seconds = "0".$seconds;
- }
- $fulldur = "[".$hours.":".$minutes.":".$seconds."] ";
- }
- else
- {
- if (int($seconds) < 10) {
- $seconds = "0".$seconds;
- }
- $fulldur = "[".$minutes.":".$seconds."] ";
- if ($fulldur eq "[0:00] ") {
- $fulldur = "[S\xC4NDNING] ";
- $subject = " tittare";
- }
- }
- $ytline =~ s/\\//sgi;
- $ytline =~ s/ä/\xE4/sg;
- $ytline =~ s/å/\xE5/sg;
- $ytline =~ s/ö/\xF6/sg;
- $ytline =~ s/Ä/\xC4/sg;
- $ytline =~ s/Å/\xC5/sg;
- $ytline =~ s/Ö/\xD6/sg;
- $ytline = $ytline . " - " . $fulldur . $views . $subject . " (Gillas: ".$percentage."\%)";
- }
- unless ($ytline eq "fail") {
- $ytlock{'YTC!'.$ytid} = $ytline;
- $message = $ytline;
- }
- }
- }
- return $message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement