Snippets
  • Uploaded By: entropy
  • Added: 1 year ago
  • Updated: 5 months ago
  • mIRC Version: 7.52+
  • Hits: 1,209
  • Size: 6.31KB
  • Downloads: 34
  • Review By: entropy



YouTube Script v3.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...

  
  3    0  Login to Vote.


Source Code:
  1. ; YouTube Script v3.5 - by entropy 2019
  2. ; Syntax: !yt <search> or paste a youtube link in any channel.
  3.  
  4. #youtube on
  5. on *:text:*:#:{ doyoutube $1- }
  6. on *:input:#:{ if ($server && /* !iswm $1) { doyoutube $1- } }
  7.  
  8. alias -l doyoutube {
  9. if ($wildtok($1-,*https://www.youtube.com/watch?v=*,1,32)) { var %a = $v1 | youtube # %a }
  10. elseif ($wildtok($1-,*https://youtu.be/*,1,32)) { var %a = $v1 | youtube # %a }
  11. elseif (?yt iswm $1 && $left($1,1) isin @!.) { youtubesearch # $2- }
  12. }
  13. alias -l youtube {
  14. sockclose youtube
  15. sockopen -e youtube youtube.com 443
  16. %youtubechannel = $1
  17. %site = $2
  18. unset %duration
  19. }
  20.  
  21. on *:sockopen:youtube:{
  22. if ($sockerr) { return }
  23. sockwrite -nt $sockname GET %site HTTP/1.1
  24. sockwrite -nt $sockname Host: www.youtube.com
  25. sockwrite -nt $sockname Connection: Close
  26. sockwrite -nt $sockname Accept-Language: en-us
  27. sockwrite -nt $sockname Content-Type: text/html
  28. sockwrite -nt $sockname $str($crlf,2)
  29. }
  30.  
  31. on *:sockread:youtube:{
  32. if ($sockerr) { return }
  33. var %a
  34. sockread -f %a
  35. tokenize 32 %a
  36. ;echo -s > $1-
  37.  
  38. if (Location: == $1) { sockclose $sockname | youtube %youtubechannel $2- | return }
  39.  
  40. if (* aria-label="dislike this video along with * iswm $1- && $remove($nohtml($1-),$chr(44)) isnum) {
  41. %down = $nohtml($1-)
  42. sockclose $sockname
  43. endyoutube
  44. }
  45. if (* aria-label="like this video along with * iswm $1- && $remove($nohtml($1-),$chr(44)) isnum) {
  46. %up = $nohtml($1-)
  47. }
  48. if (*</ul></div></div></div><div id="watch8-sentiment-actions"><div id="watch7-views-info"><div class="watch-view-count">* views</div>* iswm $1-) {
  49. %views = $remove($nohtml($1-),views)
  50. }
  51.  
  52. if (<title> isin $1- && <title>YouTube</title> !isin $1) {
  53. var %p = $replace($1-,>,$+(>,$chr(32)),<,$+($chr(32),<))
  54. var %end = $findtok(%p,</title>,1,32)
  55. dec %end 3
  56. var %z = $gettok(%p,$+(2-,%end),32)
  57. var %z = $remove(%z,<title>,</title>,- YouTube)
  58. %line = %z
  59. }
  60. }
  61. on *:sockclose:youtube:{ endyoutube }
  62.  
  63. alias -l endyoutube {
  64. if (%line) {
  65. if ($len(%line) >= 50) { %line = $+($gettok(%line,1-50,32),...) }
  66. msg %youtubechannel [YouTube] $chr(9679) $replace($html(%line),",",&,&) $chr(9679) Views: $iif(%views,$v1,NA) $chr(9679) Up: $iif(%up,$v1,0) $chr(9679) Down: $iif(%down,$v1,0)
  67. }
  68. else { msg %youtubechannel [YouTube] $chr(9679) No such video! }
  69. unset %line %views %up %down %youtubechannel %site %duration
  70. }
  71.  
  72. alias -l nohtml {
  73. return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g,)
  74. }
  75. alias -l html {
  76. var %a = 1, %b, %n, %c, %total = $1-
  77. while ($gettok(%total,%a,59)) {
  78. %b = $v1
  79. %n = $+(&,$gettok(%b,-1,38))
  80. if (&#* iswm %n) {
  81. %c = $remove(%n,$chr(59),$chr(38),$chr(35))
  82. %total = $replace(%total,%n,$chr(%c))
  83. }
  84. inc %a
  85. }
  86. return $remove(%total,;)
  87. }
  88.  
  89.  
  90. ; YouTube Search
  91. alias -l youtubesearch {
  92. sockclose youtubesearch
  93. sockopen -e youtubesearch youtube.com 443
  94. %youtubechannel = $1
  95. %search = $replace($2-,$chr(35),$+($chr(37),23))
  96. }
  97. on *:sockopen:youtubesearch:{
  98. if ($sockerr) { msg %youtubechannel [YouTube] $chr(9679) Open ERROR! | unset %youtubechannel %search | return }
  99. sockwrite -nt $sockname GET $+(/results?search_query=,$replace(%search,$chr(32),+)) HTTP/1.1
  100. sockwrite -nt $sockname Host: www.youtube.com
  101. sockwrite -nt $sockname Connection: Close
  102. sockwrite -nt $sockname Content-Type: text/html
  103. sockwrite -nt $sockname Accept-Language: en-us
  104. sockwrite -nt $sockname $crlf
  105. }
  106. on *:sockread:youtubesearch:{
  107. if ($sockerr) { msg %youtubechannel [YouTube] $chr(9679) Read ERROR! | unset %youtubechannel %search | return }
  108. var %a
  109. sockread -f %a
  110. tokenize 32 %a
  111. ;tokenize 32 $replace($mid(%a,1,4000),$chr(62),$+($chr(62),$chr(32)),$chr(60),$+($chr(32),$chr(60)))
  112.  
  113. if ($1) {
  114. if (*:* iswm $nohtml($1-)) {
  115. var %a = $wildtok($nohtml($1-),*:*,1,32), %b = $wildtok($nohtml($1-),*:*,2,32)
  116. %duration = $remove($gettok($iif(%a == Duration:,%b,%a),1,46),a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
  117. ;echo 09 -a > %duration
  118. }
  119. if (*<h3 class="yt-lockup-title "><a href="/watch?v=*" * iswm $1-) {
  120. %video = $nohtml($gettok($+(https://www.youtube.com,$remove($5,href=,")),1,$asc(&)))
  121.  
  122. %line = $replace($gettok($nohtml($6-),1-,46),- Duration:,$chr(32))
  123.  
  124. %line = $replace(%line,ft.,ft,feat.,feat)
  125.  
  126. %line = $gettok(%line,1,46)
  127. if ($gettok(%line,-1,32) isnum) { %line = $gettok(%line,1--2,32) }
  128.  
  129. ;echo 07 -s > %line
  130. if (*:* iswm $gettok(%line,-1,32)) {
  131. %duration = $v2
  132. %line = $remove(%line,$v2)
  133. }
  134. else { %duration = NA }
  135.  
  136. if (* PlaylistYouTube* iswm %line) { %line = $replace(%line,playlistyoutube,$+(playlistyoutube,$chr(32))) }
  137. if (* Playlist* iswm %line) { %line = $replace(%line,playlist,$+(playlist,$chr(32))) }
  138.  
  139. %line = $gettok(%line,1- $+ $calc( $findtok(%line,playlistyoutube,1,32) - 1),32)
  140. %line = $gettok(%line,1- $+ $calc( $findtok(%line,playlist,1,32) - 1),32)
  141.  
  142. if ($gettok(%line,-1,32) == -) { %line = $gettok(%line,1--2,32) }
  143.  
  144. %line = $remove(%line,class="yt-uix-tile-link,yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink,title="," rel="spf-prefetch" aria-describedb,")
  145.  
  146. if ($gettok(%line,1,32) == spf-link) { %line = $gettok(%line,3--1,32) }
  147. if (y=description- isin $1-) { %line = $remove(%line,y=description-) }
  148.  
  149. if ($len(%line) >= 50) { %line = $+($gettok(%line,1-50,32),...) }
  150.  
  151. %line = $gettok(%line,1,124)
  152.  
  153. msg %youtubechannel [YouTube Search] $chr(9679) $replace($html($nohtml(%line)),",",&,&,",",&,&) $chr(9679) Duration: %duration $chr(9679) URL: $replace(%video,&,&)
  154. set -u5 %finished yes
  155. sockclose $sockname
  156. endyoutubesearch
  157. }
  158. if (</html> isin $1-) { endyoutubesearch }
  159. }
  160. }
  161.  
  162. alias -l endyoutubesearch {
  163. if (!%finished) { msg %youtubechannel [YouTube Search] $chr(9679) No such video! }
  164. unset %youtubechannel %video %line %search %finished %duration
  165. }
  166. #youtube end


Comments
No Comments.

Login to Comment.