Snippets
  • Uploaded By: entropy
  • Added: 4 years ago
  • Updated: 8 months ago
  • mIRC Version: 7.52+
  • Hits: 5,718
  • Size: 5.88KB
  • Downloads: 322
  • Review By: entropy



YouTube Script v5.5

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


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.