Snippets
  • Uploaded By: entropy
  • Added: 2 years ago
  • Updated: 2 months ago
  • mIRC Version: 7.52+
  • Hits: 2,514
  • Size: 4.7KB
  • Downloads: 127
  • Review By: entropy



YouTube Script v4.5

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.5 - 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 82)
  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 off
  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 -e46 yt youtube.com 443
  40. set -u5 %_rchan $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 %_rsockname %_rchan $gettok($2-,1,38) }
  58. elseif (*"Video unavailable"* iswm $1-) { sockclose $sockname | msg %_rchan [YouTube] $c No such video! }
  59. elseif (*"status":"LOGIN_REQUIRED"* iswm $1-) { sockclose $sockname | msg %_rchan [YouTube] $c Video flagged as innopropriate for some users }
  60. elseif ($1-) {
  61. var %a = 1, %b
  62. while ($gettok($1-,%a,123)) {
  63. %b = $v1
  64. 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) }
  65. if (*"text":"* iswm %b && !%_xtitle) { set -u5 %_xtitle $replace($gettok($gettok(%b,3,34),1--1,45),\u0026,&) }
  66. if (*"simpleText":"* iswm %b && !%_views) { set -u5 %_views $gettok($gettok(%b,3,34),1,32) }
  67. if (*"label":"* dislikes"* iswm %b && !%_dislikes) { set -u5 %_dislikes $gettok($gettok(%b,3,34),1,32) }
  68. if (*"label":"* likes"* iswm %b && !%_likes) { set -u5 %_likes $gettok($gettok(%b,3,34),1,32) }
  69. inc %a
  70. }
  71. }
  72. if (%_length != $null && %_views != $null && %_xtitle && %_likes != $null && %_dislikes != $null) { sockclose $sockname | msg %_rchan [YouTube] $c $replace(%_xtitle,&#39;,',&quot;,",&amp;,&) $c Views: %_views $c Length: %_length $c Up: %_likes $c Down: %_dislikes }
  73. }
  74.  
  75. ;============================= YouTube Search
  76.  
  77. alias -l ytsearch {
  78. sockclose yout
  79. sockopen -e yout googleapis.com 443
  80. set -u5 %_chan $1
  81. sockmark yout $replace($2-,$chr(32),+)
  82. %yt_key = INSERT_KEY_HERE
  83. }
  84. on *:sockopen:yout:{
  85. if ($sockerr) { return }
  86. sockwrite -nt $sockname GET $+(https://www.googleapis.com/youtube/v3/search?part=snippet&q=,$sock($sockname).mark,&key=,%yt_key) HTTP/1.1
  87. unset %yt_key
  88. sockwrite -nt $sockname Host: googleapis.com
  89. sockwrite -nt $sockname Connection: Close
  90. sockwrite -nt $sockname Accept-Language: en-us
  91. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  92. sockwrite -nt $sockname $str($crlf,2)
  93. }
  94. on *:sockread:yout:{
  95. if ($sockerr) { return }
  96. var %a
  97. sockread -f %a
  98. tokenize 32 %a
  99. if ($1) {
  100. if (*"reason": "keyInvalid"* iswm $1-) { msg %_chan [YouTube Search] $c Invalid Key! | sockclose $sockname | return }
  101. if (*"title": "*",* iswm $1-) { set -u5 %_title $replace($remove($gettok($1-,2-,32),",$chr(44)),&apos;,',&quot;,",&amp;,&) }
  102. 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 }
  103. }
  104. }
  105. alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
  106. alias -l c { return $chr(9679) }
  107.  


Comments
No Comments.

Login to Comment.