FichteFoll

mIRC - YouTube announce

May 3rd, 2011
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.55 KB | None | 0 0
  1. ; *************** YOUTUBE Title *****************
  2. ; How to install:
  3. ; - Save this as a ".mirc" script file and run /load on it (see mIRC help).
  4. ; - Or, browse "Tools > Scripts Editor" select the "Remote" tab,
  5. ;   "File > New...", paste these contents and save it anywhere
  6. ;
  7. ; How to use:
  8. ; - Set %eccol to an echo color of your choice (mine is 14).
  9. ; - Do nothing, it will already display every youtube link's video title
  10. ;   for you.
  11. ; - However, if you want to announce this fancy title to everyone else,
  12. ;   just add the channel you want it to announce to to a global "%ytannounce"
  13. ;   variable. Multiple channels are separated by ... anything (I'm using spaces).
  14. ; - If there for some reason is another bot on a channel announcing stuff like
  15. ;   this, add it to a global "%ytnodisplay" variable, same rules apply.
  16. ;
  17. ; 2013-06-16, FichteFoll
  18. ; (and some other guy I don't know because I found this somewhere)
  19. ; ***********************************************
  20.  
  21. #youtube on
  22.  
  23. on *:INPUT:*: {
  24.   $on_yt_say($chan,$1-)
  25. }
  26.  
  27. on *:TEXT:*:*: {
  28.   $on_yt_say($chan,$1-)
  29. }
  30.  
  31.  
  32. alias -l on_yt_say {
  33.   var %chan = $1
  34.   if (%chan isin %ytnodisplay) return
  35.  
  36.   ; $regml(1): host (youtube.com/..., youtuberepeat.com/... or youtu.be/); $regml(2): id
  37.   noop $regex($strip($2-),.*(youtube(?:repeat)?\.(?:com|de)\/(?:watch\/?\?(?:[\w_]+?=[-\w+%_]*?&)*?v=|v\/)|youtu.be\/)([-\w_|~]{11}).*)
  38.   if ($regml(0) == 0) return
  39.  
  40.   ; vars for later callbacks
  41.   set %youtubechan %chan
  42.   set %youtubeerr $true
  43.   set %youtubemsg $false
  44.   var %youtubeid = $regml(2)
  45.  
  46.   if (%chan isin %ytannounce) set %youtubemsg $true
  47.   ; this one does not work, don't ask me why
  48.   if (%chan isin %ytspecialonly and $regex($regml(1),youtu\.be)) set %youtubemsg $true
  49.  
  50.   ; open the socket
  51.   if (!$sock(youtube)) {
  52.     sockopen youtube www.youtube.com 80 | sockmark youtube $+(#,>,%youtubeid)
  53.   }
  54. }
  55.  
  56. on *:sockopen:youtube: {
  57.   sockwrite -n $sockname GET $+(/watch?v=,$gettok($sock(youtube).mark,2,62)) HTTP/1.0
  58.   sockwrite -n $sockname Host: www.youtube.com
  59.   sockwrite -n $sockname $crlf
  60. }
  61.  
  62. on *:sockread:youtube: {
  63.   var %x | sockread %x
  64.   if ($regex(%x,<meta name="title" content="([^\"]+)">)) {
  65.     set %youtubetitle $regml(1)
  66.     set %youtubeerr $false
  67.     ;set %youtubetitle $replace($regml(1),&amp;,&,&quot;,")
  68.     ;$regex(%youtubetitle,&#(\d*?);)
  69.     ;var %i = 1
  70.     ;while ($regml(%i) != $null) {
  71.     ;%youtubetitle = $replace(%youtubetitle,&# $+ $regml(%i) $+ ;,$chr(%i))
  72.     ;inc %i
  73.     ;}
  74.   }
  75.   ;elseif ($regex(%x,<strong class="watch-view-count">(.+)</strong><br>))  set %youtubeviews $regml(1)
  76.   ;elseif ($regex(%x,<span class="watch-video-date">(.+)</span>))  set %youtubedate $regml(1)
  77.   ;elseif ($regex(%x,<div class="action-bar-ratings-stats yt-uix-tooltip" title="(.+)"> ))  set %youtuberating $regml(1)
  78.   ;elseif ($regex(%x,<a id="watch-username" class="inline-block" href="/user/(.+)">))  set %youtubeuser $regml(1)
  79. }
  80.  
  81. on *:sockclose:youtube: {
  82.   ;msg #CHANNEL $chr(91) $+ YouTube $+ $chr(93) " $+ %youtubetitle $+ " --- %youtubeviews views $&
  83.     ;  ( %youtuberating ) uploaded %youtubedate by %youtubeuser ---
  84.   ;if ($chan isin %ytspecialonly and !$isunicode(%youtubetitle)) halt
  85.   if (%youtubeerr == $false) {
  86.     if (%youtubemsg == $true) {
  87.       msg %youtubechan 5[YouTube-Title]  $+ %youtubetitle $+ 
  88.     }
  89.     else {
  90.       echo %eccol %youtubechan [YouTube-Title]  $+ %youtubetitle $+ 
  91.     }
  92.   }
  93.   else {
  94.     echo %eccol %youtubechan --- [YouTube-Title not found]
  95.   }
  96.   ;unset %youtube*
  97. }
  98.  
  99. #youtube end
  100. ; ************************************************
Advertisement
Add Comment
Please, Sign In to add comment