Advertisement
Guest User

Untitled

a guest
May 5th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.80 KB | None | 0 0
  1.  if (($arguments->{body} =~ m/youtube\.com\/watch\?[^v]*v=([a-zA-Z0-9-_]*)/i)||($arguments->{body} =~ m/youtu\.be\/([a-zA-Z0-9-_]*)/i)) {
  2.    $message = do_youtube($1);
  3.  }
  4.  
  5.  
  6. sub do_youtube { # This function is called anytime a Youtube URL is encountered.
  7.   $ytid = $_[0];
  8.   if (int($ytlock{'YT!'.$ytid}) < time) {
  9.     $ytlock{'YT!'.$ytid} = time + 5*60;
  10.     if (length($ytlock{'YTC!'.$ytid}) > 1) {
  11.       $message = $ytlock{'YTC!'.$ytid};
  12.     }
  13.     else
  14.     {
  15.       $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');
  16.       $rbody = $response->decoded_content;
  17.       $ytline = "fail";
  18.       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) {
  19.         $duration = $2;
  20.         $ytline = $1;
  21.         $views = $3;
  22.         $likes = $4;
  23.         $dislikes = $5;
  24.         if (int($likes) == 0) {
  25.           $likes = 1;
  26.         }
  27.         $percentage = int((int($likes) / int(int($likes) + int($dislikes)))*100);
  28.         $views = numprettify($views);
  29.         $duration =~ s/^PT(\d+H)?(\d+M)?(\d+S)?$/$1:$2:$3/;
  30.         $duration =~ s/[HMS]*//g;
  31.         ($hours, $minutes, $seconds) = split(":", $duration);
  32.         $hours = int($hours);
  33.         $minutes = int($minutes);
  34.         $seconds = int($seconds);
  35.         $subject = " visningar";
  36.         if (int($hours) > 0) {
  37.           if (int($minutes) < 10) {
  38.             $minutes = "0".$minutes;
  39.           }
  40.           if (int($seconds) < 10) {
  41.             $seconds = "0".$seconds;
  42.           }
  43.           $fulldur = "[".$hours.":".$minutes.":".$seconds."] ";
  44.         }
  45.         else
  46.         {
  47.           if (int($seconds) < 10) {
  48.             $seconds = "0".$seconds;
  49.           }
  50.           $fulldur = "[".$minutes.":".$seconds."] ";
  51.           if ($fulldur eq "[0:00] ") {
  52.             $fulldur = "[S\xC4NDNING] ";
  53.             $subject = " tittare";
  54.           }
  55.         }
  56.         $ytline =~ s/\\//sgi;
  57.         $ytline =~ s/ä/\xE4/sg;
  58.         $ytline =~ s/å/\xE5/sg;
  59.         $ytline =~ s/ö/\xF6/sg;
  60.         $ytline =~ s/Ä/\xC4/sg;
  61.         $ytline =~ s/Å/\xC5/sg;
  62.         $ytline =~ s/Ö/\xD6/sg;
  63.         $ytline = $ytline . " - " . $fulldur . $views . $subject . " (Gillas: ".$percentage."\%)";
  64.       }
  65.       unless ($ytline eq "fail") {
  66.         $ytlock{'YTC!'.$ytid} = $ytline;
  67.         $message = $ytline;
  68.       }
  69.     }
  70.   }
  71.   return $message;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement