Snippets
  • Uploaded By: entropy
  • Added: 2 years ago
  • Updated: 8 hours ago
  • mIRC Version: 7.52+
  • Hits: 2,083
  • Size: 4.49KB
  • Downloads: 89
  • Review By: entropy



YouTube Script v4.4

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

Syntax: !yt [search] or paste a youtube link in any channel.
Screenshot...

    
  4    0  Login to Vote.


Source Code:
  1.  
  2. ; YouTube v4.4 - by entropy 2020
  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. ; Then, "%yt_key = INSERT_KEY_HERE" insert key here (on line 81)
  7.  
  8. ; ============================ YouTube Menus
  9.  
  10. menu channel {
  11. -
  12. YouTube Status $chr(9) $replace($group(#yt).status,o,O) {
  13. $iif($group(#yt).status == on,.disable,.enable) #yt
  14. echo 4 -a * YouTube is now: $replace($group(#yt).status,o,O)
  15. }
  16. -
  17. }
  18.  
  19. ;============================= YouTube Events
  20.  
  21. #yt on
  22. on *:input:#:{ if (/* !iswm $1 && $server) { triggeryt # $strip($1-) } }
  23. on *:text:*:#:{ triggeryt # $strip($1-) }
  24. on *:action:*:#:{ triggeryt # $strip($1-) }
  25. #yt end
  26.  
  27. ;============================= YouTube Trigger
  28.  
  29. alias -l triggeryt {
  30. if ($wildtok($2-,*https://www.youtube.com/watch?v=*,1,32)) { youtube $1 $v1 }
  31. elseif ($wildtok($2-,*https://youtu.be/*,1,32)) { youtube $1 $v1 }
  32. elseif (?yt iswm $2 && $left($2,1) isin @!. && $3) { ytsearch $1 $3- }
  33. }
  34.  
  35. ;============================= YouTube View Video
  36.  
  37. alias -l youtube {
  38. sockclose yt
  39. sockopen -e yt youtube.com 443
  40. %_chan = $1
  41. sockmark yt $2-
  42. }
  43. on *:sockopen:yt:{
  44. if ($sockerr) { return }
  45. sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.1
  46. sockwrite -nt $sockname Host: www.youtube.com
  47. sockwrite -nt $sockname Connection: Close
  48. sockwrite -nt $sockname Accept-Language: en-us
  49. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  50. sockwrite -nt $sockname $str($crlf,2)
  51. }
  52. on *:sockread:yt:{
  53. if ($sockerr) { return }
  54. var %b
  55. sockread -f %b
  56. tokenize 32 $replace(%b,<,$+($chr(32),<),>,$+(>,$chr(32)))
  57. if (Location: == $1) { sockclose $sockname | youtube %_sockname %_chan $2- | return }
  58. elseif (*"Video unavailable"* iswm $1-) { sockclose $sockname | msg %_chan [YouTube] $c No such video! }
  59. elseif ($1-) {
  60. var %a = 1, %b
  61. while ($gettok($1-,%a,123)) {
  62. %b = $v1
  63. if (*"lengthSeconds\":\"* iswm %b && !%_length) { set -u5 %_length $duration($remove($gettok(%b,$calc($findtok(%b,$wildtok(%b,*lengthSeconds*,1,34),1,34) + 2),34),\),3) }
  64. if (*"text":"* iswm %b && !%_xtitle) { set -u5 %_xtitle $gettok($gettok(%b,3,34),1--1,45) }
  65. if (*"simpleText":"* iswm %b && !%_views) { set -u5 %_views $gettok($gettok(%b,3,34),1,32) }
  66. if (*"label":"* dislikes"* iswm %b && !%_dislikes) { set -u5 %_dislikes $gettok($gettok(%b,3,34),1,32) }
  67. if (*"label":"* likes"* iswm %b && !%_likes) { set -u5 %_likes $gettok($gettok(%b,3,34),1,32) }
  68. inc %a
  69. }
  70. }
  71. if (%_length != $null && %_views != $null && %_xtitle && %_likes != $null && %_dislikes != $null) { sockclose $sockname | msg %_chan [YouTube] $c $replace(%_xtitle,&#39;,',&quot;,",&amp;,&) $c Views: %_views $c Length: %_length $c Up: %_likes $c Down: %_dislikes }
  72. }
  73.  
  74. ;============================= YouTube Search
  75.  
  76. alias -l ytsearch {
  77. sockclose yout
  78. sockopen -e yout googleapis.com 443
  79. set -u5 %_chan $1
  80. sockmark yout $replace($2-,$chr(32),+)
  81. %yt_key = INSERT_KEY_HERE
  82. }
  83. on *:sockopen:yout:{
  84. if ($sockerr) { return }
  85. sockwrite -nt $sockname GET $+(https://www.googleapis.com/youtube/v3/search?part=snippet&q=,$sock($sockname).mark,&key=,%yt_key) HTTP/1.1
  86. unset %yt_key
  87. sockwrite -nt $sockname Host: googleapis.com
  88. sockwrite -nt $sockname Connection: Close
  89. sockwrite -nt $sockname Accept-Language: en-us
  90. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  91. sockwrite -nt $sockname $str($crlf,2)
  92. }
  93. on *:sockread:yout:{
  94. if ($sockerr) { return }
  95. var %a
  96. sockread -f %a
  97. tokenize 32 %a
  98. if ($1) {
  99. if (*"reason": "keyInvalid"* iswm $1-) { msg %_chan [YouTube Search] $c Invalid Key! | sockclose $sockname }
  100. if (*"title": "*",* iswm $1-) { set -u5 %_title $replace($remove($gettok($1-,2-,32),",$chr(44)),&apos;,',&quot;,",&amp;,&) }
  101. 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 }
  102. }
  103. }
  104. alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
  105. alias -l c { return $chr(9679) }


Comments
No Comments.

Login to Comment.