Snippets
  • Uploaded By: entropy
  • Added: 1 year ago
  • Updated: 1 month ago
  • mIRC Version: 7.52+
  • Hits: 1,674
  • Size: 4.04KB
  • Downloads: 62
  • Review By: entropy



YouTube Script v4.3

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.3 - 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.  
  7. ;============================= YouTube Events
  8.  
  9. #yt off
  10. on *:input:#:{ if (/* !iswm $1 && $server) { triggeryt # $strip($1-) } }
  11. on *:text:*:#:{ triggeryt # $strip($1-) }
  12. on *:action:*:#:{ triggeryt # $strip($1-) }
  13. #yt end
  14.  
  15. ;============================= YouTube Trigger
  16.  
  17. alias -l triggeryt {
  18. if ($wildtok($2-,*https://www.youtube.com/watch?v=*,1,32)) { youtube $1 $v1 }
  19. elseif ($wildtok($2-,*https://youtu.be/*,1,32)) { youtube $1 $v1 }
  20. elseif (?yt iswm $2 && $left($2,1) isin @!. && $3) { ytsearch $1 $3- }
  21. }
  22.  
  23. ;============================= YouTube View Video
  24.  
  25. alias -l youtube {
  26. sockclose yt
  27. sockopen -e yt youtube.com 443
  28. %_chan = $1
  29. sockmark yt $2-
  30. }
  31. on *:sockopen:yt:{
  32. if ($sockerr) { return }
  33. sockwrite -nt $sockname GET $sock($sockname).mark HTTP/1.1
  34. sockwrite -nt $sockname Host: www.youtube.com
  35. sockwrite -nt $sockname Connection: Close
  36. sockwrite -nt $sockname Accept-Language: en-us
  37. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  38. sockwrite -nt $sockname $str($crlf,2)
  39. }
  40. on *:sockread:yt:{
  41. if ($sockerr) { return }
  42. var %a
  43. sockread -f %a
  44. tokenize 32 $replace(%a,<,$+($chr(32),<),>,$+(>,$chr(32)))
  45. if (Location: == $1) { sockclose $sockname | youtube %_chan $2- | return }
  46. if (* aria-label="dislike this video along with * iswm $1- && $remove($nohtml($1-),$chr(44)) isnum) {
  47. %down = $nohtml($1-)
  48. msg %_chan [YouTube] $c $replace(%title,&#39;,',&quot;,",&amp;,&) $c Views: %views $c Up: %up $c Down: %down
  49. unset %title %views %up %down %_chan
  50. sockclose $sockname
  51. }
  52. if (* aria-label="like this video along with * iswm $1- && $remove($nohtml($1-),$chr(44)) isnum) { %up = $nohtml($1-) }
  53. if (* class="watch-view-count"> * iswm $1-) {
  54. var %start = $findtok($1-,class="watch-view-count">,1,32)
  55. var %end = $findtok($1-,views,1,32)
  56. %views = $remove($gettok($1-,$+(%start,-,%end),32),class="watch-view-count">,views)
  57. }
  58. if (<title> isin $1- && <title>YouTube</title> !isin $1) {
  59. var %start = $findtok($1-,<title>,1,32), %end = $findtok($1-,</title>,1,32)
  60. %title = $remove($gettok($1-,$+(%start,-,%end),32),<title>,</title>,- YouTube)
  61. if (*Error 404* iswm %title) { msg %_chan [YouTube] $c Error 404 (Not Found) | unset %title %_chan }
  62. }
  63. }
  64.  
  65. ;============================= YouTube Search
  66.  
  67. alias -l ytsearch {
  68. sockclose yout
  69. sockopen -e yout googleapis.com 443
  70. %_chan = $1
  71. sockmark yout $replace($2-,$chr(32),+)
  72. %yt_key = INSERT_KEY_HERE
  73. }
  74. on *:sockopen:yout:{
  75. if ($sockerr) { return }
  76. sockwrite -nt $sockname GET $+(https://www.googleapis.com/youtube/v3/search?part=snippet&q=,$sock($sockname).mark,&key=,%yt_key) HTTP/1.1
  77. sockwrite -nt $sockname Host: googleapis.com
  78. sockwrite -nt $sockname Connection: Close
  79. sockwrite -nt $sockname Accept-Language: en-us
  80. sockwrite -nt $sockname Content-Type: text/html; charset=utf-8
  81. sockwrite -nt $sockname $str($crlf,2)
  82. }
  83. on *:sockread:yout:{
  84. if ($sockerr) { return }
  85. var %a
  86. sockread -f %a
  87. tokenize 32 %a
  88. if ($1) {
  89. if (*"reason": "keyInvalid"* iswm $1-) { msg %_chan [YouTube Search] $c Invalid Key! | unset %_chan | sockclose $sockname }
  90. if (*"title": "*",* iswm $1-) { %_title = $replace($remove($gettok($1-,2-,32),",$chr(44)),&#39;,',&quot;,",&amp;,&) }
  91. if (*"url": "*",* iswm $1-) { %_link = $+(https://www.youtube.com/watch?v=,$gettok($gettok($1-,2,32),-2,47)) | msg %_chan [YouTube Search] $c %_title $c Link: %_link | unset %_title %_link %_chan | sockclose $sockname }
  92. }
  93. }
  94. alias -l nohtml { return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,) }
  95. alias -l c { return $chr(9679) }


Comments
No Comments.

Login to Comment.