Snippets
  • Uploaded By: entropy
  • Added: 3 years ago
  • Updated: 8 days ago
  • mIRC Version: 7.52+
  • Hits: 4,675
  • Size: 6.01KB
  • Downloads: 252
  • Review By: entropy



YouTube Script v5.3

This snippet looks up youtube urls and also searches for matching videos.

Paste a youtube link in any channel (or channels specified).

Type: !yt <search> to search for youtube videos.
Screenshot...

    
  4    1  Login to Vote.


Source Code:
  1.  
  2. ; YouTube v5.2 - (2/20/21) by entropy 2021
  3.  
  4. ; You will need a GOOGLE API (Youtube) Key for the youtube search to work.
  5. ; Get one here: https://developers.google.com/youtube/v3/getting-started
  6. ; For channels, you can use "#" as all channels, or a list of channels: #test,#test2,#test3 etc.
  7.  
  8. ; ============================ YouTube Events
  9.  
  10. #youtube on
  11. on *:input:%yt_chans:{ if (/* !iswm $1 && $server) { triggeryt # $strip($1-) } }
  12. on *:text:*:%yt_chans:{ triggeryt # $strip($1-) }
  13. on *:action:*:%yt_chans:{ triggeryt # $strip($1-) }
  14. #youtube end
  15.  
  16. ; ============================ YouTube Menus
  17.  
  18. menu channel,status,menubar {
  19. -
  20. YouTube v5.2
  21. .YouTube Status $chr(9) $replace($group(#youtube).status,o,O) {
  22. $iif($group(#youtube).status == on,.disable,.enable) #youtube
  23. echo 4 -a * YouTube is now: $replace($group(#youtube).status,o,O)
  24. }
  25. .-
  26. .Channels $chr(9) %yt_chans { %yt_chans = $input(Channels (sep by comma)?,5,Channels,%yt_chans) | if ($! != $null) { %yt_chans = $! } }
  27. .-
  28. .API Key $chr(9) %yt_key { var %a = $input(Input API Key?,5) | if ($! != $null) { %yt_key = $! } }
  29. -
  30. }
  31.  
  32. ; ============================ Lookup Aliases
  33.  
  34. on *:unload:{
  35. unset %yt_chans %yt_key
  36. }
  37.  
  38. alias -l triggeryt {
  39. if ($wildtok($2-,*https://www.youtube.com/watch?v=*,1,32)) { you $1 $gettok($v1,2,61) }
  40. elseif ($wildtok($2-,*https://youtu.be/*,1,32)) { you $1 $gettok($v1,-1,47) }
  41. elseif (?yt iswm $2 && $left($2,1) isin @!. && $3) { ytsearch $1 $3- }
  42. }
  43.  
  44. alias -l you {
  45. sockclose youtube
  46. sockopen -e4 youtube youtube.com 443
  47. sockmark youtube $replace($2-,$chr(32),+)
  48. %_title = ""
  49. %_length = ""
  50. %_views = ""
  51. %_likes = ""
  52. %_dislikes = ""
  53. %_chan = $1
  54. %_nouser = ""
  55. }
  56.  
  57. ;============================= YouTube Play
  58.  
  59. on *:sockopen:youtube:{
  60. if ($sockerr) { return }
  61. sockwrite -nt $sockname GET https://www.youtube.com/watch?v= $+ $sock($sockname).mark HTTP/1.1
  62. sockwrite -nt $sockname Host: youtube.com
  63. sockwrite -nt $sockname Connection: Close
  64. sockwrite -nt $sockname Accept-Language: en-us
  65. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  66. sockwrite -nt $sockname $str($crlf,2)
  67. }
  68. on *:sockread:youtube:{
  69. if ($sockerr) { return }
  70. sockread -f &b
  71. if (* views"* iswm $bvar(&b,1-).text) {
  72. var %a = $bvar(&b,1-).text, %b = 1, %y
  73. while ($gettok(%a,%b,123)) {
  74. %y = $v1
  75. if (*"status":"LOGIN_REQUIRED"* iswm %y) { %_nouser = $ctime }
  76. if (*"text":"*"}]},"viewCount":* iswm %y) { %_title = $gettok(%y,3,34) }
  77. if (*"simpleText":"* views"},"shortViewCount":* iswm %y && !%_views) { %_views = $gettok($gettok(%y,3,34),1,32) }
  78. inc %b
  79. }
  80. }
  81. if (*"label":"like this video along with * other people"}* iswm $bvar(&b,1-).text && %_likes == $null) {
  82. var %y = $replace($bvar(&b,1-).text,:,$+($chr(32),:,$chr(32)),}},$+($chr(32),}})), %first = $findtok(%y,"like,1,32), %last = $findtok(%y,people",1,32), %all = $gettok($gettok(%y,$+(%first,-,%last),32),6,32)
  83. if ($remove(%all,$chr(44)) isnum) { %_likes = %all }
  84. }
  85. if (*"label":"dislike this video along with * other people"}* iswm $bvar(&b,1-).text && %_dislikes == $null) {
  86. var %y = $replace($bvar(&b,1-).text,:,$+($chr(32),:,$chr(32)),}},$+($chr(32),}})), %first = $findtok(%y,"dislike,1,32), %last = $findtok(%y,people",1,32), %all = $gettok($gettok(%y,$+(%first,-,%last),32),6,32)
  87. if ($remove(%all,$chr(44)) isnum) { %_dislikes = %all }
  88. }
  89. if (*"lengthSeconds":"* iswm $bvar(&b,1-).text && !%_length) {
  90. var %a = 1, %b, %c = $bvar(&b,1-).text
  91. while ($gettok(%c,%a,44)) { %b = $v1 | if (*"lengthSeconds":"*"* iswm %b) { %_length = $duration($remove(%b,"lengthSeconds":","),3) | break } | inc %a }
  92. }
  93. }
  94.  
  95. on *:sockclose:youtube:{ endit }
  96.  
  97. alias -l endit {
  98. if (!%_title) { msg %_chan [YouTube] $c No such video! }
  99. elseif (%_nouser) { msg %_chan [YouTube] $c Video flagged as innopropriate for some users }
  100. else { msg %_chan [YouTube] $c Title: $replace(%_title,&#39;,',&quot;,",&amp;,&,\u0026,&) $c Views: %_views $c Length: $iif(%_length,%_length,NA) $c Up: $iif(%_likes != $null,%_likes,NA) $c Down: $iif(%_dislikes != $null,%_dislikes,NA) }
  101. unset %_chan %_title %_views %_length %_likes %_dislikes %_nouser
  102. }
  103.  
  104. alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
  105. alias -l c { return $chr(9679) }
  106.  
  107. ;============================= YouTube Search
  108.  
  109. alias -l ytsearch {
  110. sockclose yout
  111. sockopen -e4 yout googleapis.com 443
  112. set -u5 %_chan $1
  113. sockmark yout $replace($2-,$chr(32),+)
  114. }
  115. on *:sockopen:yout:{
  116. if ($sockerr) { return }
  117. sockwrite -nt $sockname GET $+(https://www.googleapis.com/youtube/v3/search?part=snippet&q=,$sock($sockname).mark,&key=,%yt_key) HTTP/1.1
  118. sockwrite -nt $sockname Host: googleapis.com
  119. sockwrite -nt $sockname Connection: Close
  120. sockwrite -nt $sockname Accept-Language: en-us
  121. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  122. sockwrite -nt $sockname $str($crlf,2)
  123. }
  124. on *:sockread:yout:{
  125. if ($sockerr) { return }
  126. var %a
  127. sockread -f %a
  128. tokenize 32 %a
  129. if ($1) {
  130. if (*"reason": "keyInvalid"* iswm $1- || !%yt_key) { msg %_chan [YouTube Search] $c Invalid Key! | sockclose $sockname | return }
  131. if (*"title": "*",* iswm $1-) { set -u5 %_title $replace($remove($gettok($1-,2-,32),',$chr(44)),&apos;,',&#39;,',&quot;,",&amp;,&,",$null,\u0026,&amp;) }
  132. if (*"url": "*",* iswm $1-) { set -u5 %_link $+(https://www.youtube.com/watch?v=,$gettok($gettok($1-,2,32),-2,47)) | msg %_chan [YouTube Search] $c %_title $c Link: %_link | sockclose $sockname }
  133. }
  134. }
  135.  


Comments (2)
February 16th, 2021 - By: Charsi
its not working even i tok api key from googleapi.
February 16th, 2021 - By: entropy
Admin
Fixed.

Login to Comment.