youtubescript


SUBMITTED BY: Guest

DATE: Feb. 7, 2014, 7:34 p.m.

FORMAT: Text only

SIZE: 18.5 kB

HITS: 845

  1. ;YouTube Script (Parse Vids and Search) v5.2
  2. ;Made by nick1
  3. ;Last edit November 27 2013
  4. ;For help/setup type /YouTube in mIRC
  5. ;2D0 -- Open to suggestions!
  6. ;EDITS -- bug fixes (no search limit set, bolded search words), code cleanup since last version, removed checkboxes, added badword line
  7. alias -l yversion { return v5.2 }
  8. menu status,channel,query { YouTube:youtube }
  9. alias YouTube { dialog -m YouTube YouTube }
  10. dialog Youtube {
  11. title "YouTube v5.2"
  12. size -1 -1 253 166
  13. option dbu
  14. icon $mircdirYoutube.ico, 0
  15. link "View Script On Hawkee", 1, 3 2 59 8
  16. button "Exit", 7, 86 153 72 12, cancel
  17. tab "About", 10, 2 9 245 141
  18. link "YouTube Script (Parse Vids and Search) v5.2 -- Post Bugs and Feature Requests Here", 24, 23 26 208 8, tab 10
  19. text "Last updated on November 27 2013", 19, 7 66 95 8, tab 10
  20. text "Please post suggestions, complaints, or bugs on the hawkee link (or in chat)", 20, 7 37 188 8, tab 10
  21. text "!commands will notice the user; @commands will be public to the channel", 13, 7 101 175 8, tab 10
  22. text "Default behavior is to run on every channel for every nick. Use the Nick and Channel Settings Tabs to change it for invidividual channels or nicks.", 65, 7 80 208 14, tab 10
  23. link "Click here to chat (leave a message for nick1)", 66, 58 50 110 8, tab 10
  24. text "Use the Basic Options Tab to adjust which parts of the script will run and basic formatting options.", 23, 7 118 207 13, tab 10
  25. button "Check for Updates", 21, 109 64 54 12, tab 10
  26. tab "Basic Options", 2
  27. box "Search Commands/Options", 60, 7 52 209 29, tab 2
  28. text "youtube <search terms>; ytsearch <search>; ysearch <search terms>", 62, 10 60 175 8, tab 2
  29. box "Disable Options", 5, 7 23 209 27, tab 2
  30. check "Disable Search - Disables search commands below", 11, 11 29 133 10, tab 2 flat
  31. check "Disable Parse - Disables the script from automatically sending info", 14, 11 38 175 10, tab 2 flat
  32. box "Output Options", 9, 7 83 209 64, tab 2
  33. check "Disable Views - Removes 'Views: <Views>'", 15, 11 90 123 10, tab 2
  34. check "Disable Length - Removes 'Length: <Length>'", 16, 11 99 130 10, tab 2
  35. check "Disable User - Removes 'User: <User>'", 17, 11 108 113 10, tab 2
  36. check "Disable Formatting - Removes Colors and Bold", 22, 11 117 127 10, tab 2
  37. edit "", 58, 99 69 15 10, tab 2 limit 1
  38. text "Number of search results displayed:", 25, 10 70 87 8, tab 2
  39. check "Enable Date - Adds 'Uploaded: <Date>'", 57, 11 126 120 10, tab 2
  40. check "Enable Rating - Adds 'Rating: <x/5>'", 59, 11 136 106 9, tab 2
  41. tab "Channel Settings", 3
  42. list 6, 8 56 223 87, tab 3 sort size extsel vsbar
  43. edit "", 8, 9 26 155 25, tab 3 multi autohs autovs
  44. text "List of channels the script will NOT run on", 12, 48 50 101 6, tab 3
  45. button "Add", 4, 190 25 37 12, tab 3
  46. button "Remove", 63, 190 42 37 12, tab 3
  47. button "Click here to enter #channels ...", 64, 10 27 153 23, tab 3
  48. tab "Nick Settings", 26
  49. text "List of nicks the script will NOT run for", 70, 48 50 101 6, tab 26
  50. list 71, 8 56 223 87, tab 26 sort size extsel vsbar
  51. button "Remove", 72, 190 42 37 12, tab 26
  52. button "Add", 73, 190 25 37 12, tab 26
  53. edit "", 69, 9 26 155 25, tab 26 multi autohs autovs
  54. button "Click here to enter Nicks ...", 74, 10 27 153 23, tab 26
  55. text "This script created by nick1", 18, 179 2 66 8
  56. }
  57. on *:dialog:youtube:init:0: {
  58. FillChannelBox
  59. FillNickBox
  60. $iif(%_youtube.nocolor == true,did -c youtube 22,noop)
  61. did -a youtube 58 $iif(%_youtube.limit == $null,1,%_youtube.limit)
  62. $iif(%_youtube.noviews == true,did -c youtube 15,noop)
  63. $iif(%_youtube.nolength == true,did -c youtube 16,noop)
  64. $iif(%_youtube.nouser == true,did -c youtube 17,noop)
  65. $iif(%_youtube.date == true,did -c youtube 57,noop)
  66. $iif(%_youtube.rating == true,did -c youtube 59,noop)
  67. $iif($group(#search) != on,did -c youtube 11,noop)
  68. $iif($group(#parse) != on,did -c youtube 14,noop)
  69. }
  70. alias FillChannelBox {
  71. did -r youtube 6
  72. var %y 1
  73. while (%y <= $numtok(%youtubefetch,44)) {
  74. did -a youtube 6 $gettok(%youtubefetch,%y,44)
  75. inc %y
  76. }
  77. }
  78. alias FillNickBox {
  79. did -r youtube 71
  80. var %y 1
  81. while (%y <= $numtok(%nolinks,44)) {
  82. did -a youtube 71 $gettok(%nolinks,%y,44)
  83. inc %y
  84. }
  85. }
  86. on *:dialog:youtube:edit:58: {
  87. if (($did(58).text < 1) || ($did(58).text !isnum) && ($did(58).text != $null)) {
  88. did -r youtube 58
  89. noop $input(Enter a number between 1 and 9, owd, Invalid input!)
  90. }
  91. elseif ($did(58).text != $null) { set %_youtube.limit $did(58).text }
  92. }
  93. on *:dialog:youtube:sclick:*: {
  94. if (($did == 1) || ($did == 24)) { run http://www.hawkee.com/snippet/8577/ }
  95. elseif ($did == 66) { server -m irc.rizon.net:6667 -jn #rsbot_help }
  96. elseif ($did == 22) { set %_youtube.nocolor $iif($did(22).state,true,false) }
  97. elseif ($did == 15) { set %_youtube.noviews $iif($did(15).state,true,false) }
  98. elseif ($did == 16) { set %_youtube.nolength $iif($did(16).state,true,false) }
  99. elseif ($did == 17) { set %_youtube.nouser $iif($did(17).state,true,false) }
  100. elseif ($did == 57) { set %_youtube.date $iif($did(57).state,true,false) }
  101. elseif ($did == 59) { set %_youtube.rating $iif($did(59).state,true,false) }
  102. elseif ($did == 11) { $iif($group(#search) == on,.disable,.enable) #search }
  103. elseif ($did == 21) { yupdate }
  104. elseif ($did == 14) { $iif($group(#parse) == on,.disable,.enable) #parse }
  105. elseif ($did == 4) {
  106. set %youtubefetch $addtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  107. did -r youtube 8
  108. FillChannelBox
  109. }
  110. elseif ($did == 73) {
  111. set %nolinks $addtok(%nolinks,$did(69),44)
  112. did -r youtube 69
  113. FillNickBox
  114. }
  115. elseif ($did == 63) {
  116. if ($did(8) != $null) {
  117. set %youtubefetch $remtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
  118. did -r youtube 8
  119. }
  120. if ($did(6).seltext != $null) { set %youtubefetch $remtok(%youtubefetch,$did(6).seltext,44) }
  121. FillChannelBox
  122. }
  123. elseif ($did == 3) { did -t youtube 4 }
  124. elseif ($did == 26) { did -t youtube 73 }
  125. elseif ($did == 72) {
  126. if ($did(69) != $null) {
  127. set %nolinks $remtok(%nolinks,$did(69),44)
  128. did -r youtube 69
  129. }
  130. if ($did(71).seltext != $null) { set %nolinks $remtok(%nolinks,$did(71).seltext,44) }
  131. FillNickBox
  132. }
  133. }
  134. raw 408:*: msg $2 $remove($strip($13-),$chr(9),$chr(8))
  135. alias urlencode { return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B) }
  136. on $*:text:/^[!@](disableyt|offyt|disableyoutube|offyoutube)(\s|$)/Si:?: {
  137. if ($2) {
  138. if ($me ison $2) {
  139. if ($nick isop $2) {
  140. msg $nick 4Youtube has been10 disabled on $+(,$2,)
  141. set %youtubefetch $addtok(%youtubefetch,$2,44)
  142. }
  143. else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to disable youtube there }
  144. }
  145. else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
  146. }
  147. elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
  148. }
  149. on $*:text:/^[!@](enableyt|onyt|enableyoutube|onyoutube)(\s|$)/Si:?: {
  150. if ($2) {
  151. if ($me ison $2) {
  152. if ($nick isop $2) {
  153. msg $nick 4Youtube has been10 enabled on $+(,$2,)
  154. set %youtubefetch $remtok(%youtubefetch,$2,44)
  155. }
  156. else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to enable youtube there }
  157. }
  158. else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
  159. }
  160. elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
  161. }
  162. #search on
  163. on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)(\s|$)/Si:*: {
  164. $iif($istok(%youtubefetch,$chan,44),halt,noop)
  165. $iif($istok(%nolinks,$nick,44),halt,noop)
  166. if ($($+(%,botflood.,$nick),2)) {
  167. if ($($+(%,botflood.,$nick),2) >= 50) {
  168. ignore -u60 $address($nick,2)
  169. msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  170. halt
  171. }
  172. elseif ($($+(%,botflood.,$nick),2) >= 40) {
  173. msg $chan $+($nick,$chr(44)) Please do not flood the bot.
  174. inc -z $+(%,botflood.,$nick) 20
  175. halt
  176. }
  177. else { inc -z $+(%,botflood.,$nick) 25 }
  178. }
  179. else { inc -z $+(%,botflood.,$nick) 25 }
  180. var %ticks $ticks
  181. if ($2) {
  182. set $+(%,youtube.,%ticks,.msgtype) $iif($chan,$iif($left($strip($1),1) == @,msg $chan,notice $nick),msg $nick)
  183. set $+(%,youtube.,%ticks,.search) $2-
  184. set $+(%,youtube.,%ticks,.query) $urlencode($2-)
  185. sockopen $+(youtube.,%ticks) gdata.youtube.com 80
  186. }
  187. elseif ($2 == $null) {
  188. notice $nick 4Incorrect Syntax - Use10 $1 <search term>
  189. }
  190. }
  191. on *:input:*:{
  192. $iif($istok(%nolinks,$active,44),return,noop)
  193. $iif($istok(%youtubefetch,$active,44),return,noop)
  194. var %ticks $ticks
  195. if (($remove($1,$left($strip($1),1)) == ysearch) || ($remove($1,$left($strip($1),1)) == ytsearch) || ($remove($1,$left($strip($1),1)) == youtube) || ($remove($1,$left($strip($1),1)) == yt) || ($remove($1,$left($strip($1),1)) == youtubesearch)) {
  196. if ($left($1,1) != /) {
  197. if ($2 != $null) {
  198. set $+(%,youtube.,%ticks,.msgtype) msg $active
  199. set $+(%,youtube.,%ticks,.search) $2-
  200. set $+(%,youtube.,%ticks,.query) $urlencode($2-)
  201. sockopen $+(youtube.,%ticks) gdata.youtube.com 80
  202. }
  203. elseif ($2 == $null) {
  204. .timerYTInputSyntax -m 1 100 echo -at 4Incorrect Syntax - Use10 $1 <search term>
  205. }
  206. }
  207. }
  208. elseif ((*youtube.com* iswm $1-) || (*youtu.be* iswm $1-)) {
  209. if ($left($1,1) != /) {
  210. var %i 1
  211. while (%i <= $numtok($1-,32)) {
  212. if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  213. set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
  214. var %tag $($+(%,youtube.,%ticks,.url),2)
  215. var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
  216. var %tag $deltok($deltok(%tag,2,35),2,38)
  217. set $+(%,youtube.,%ticks,.tag) $remove(%tag,?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
  218. }
  219. inc %i
  220. }
  221. if ($($+(%,youtube.,%ticks,.tag),2) == $null) {
  222. unset $+(%,youtube.,%ticks,.*)
  223. }
  224. else {
  225. set $+(%,youtube.,%ticks,.msgtype) msg $active
  226. set $+(%,youtube.,%ticks,.nick) $nick
  227. set $+(%,youtube.,%ticks,.chan) $chan
  228. set $+(%,youtube.,%ticks,.network) $network
  229. sockopen $+(youtube.,%ticks) gdata.youtube.com 80
  230. }
  231. }
  232. }
  233. }
  234. #search end
  235. #parse on
  236. on $*:text:/youtu(.be|be.com)/Si:*: {
  237. $iif($istok(%youtubefetch,$chan,44),halt,noop)
  238. $iif($istok(%nolinks,$nick,44),halt,noop)
  239. if ($($+(%,botflood.,$nick),2)) {
  240. if ($($+(%,botflood.,$nick),2) >= 50) {
  241. ignore -u60 $address($nick,2)
  242. msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
  243. halt
  244. }
  245. elseif ($($+(%,botflood.,$nick),2) >= 40) {
  246. msg $chan $+($nick,$chr(44)) Please do not flood the bot.
  247. inc -z $+(%,botflood.,$nick) 20
  248. halt
  249. }
  250. else {
  251. inc -z $+(%,botflood.,$nick) 10
  252. }
  253. }
  254. else { inc -z $+(%,botflood.,$nick) 10 }
  255. var %i 1
  256. var %ticks $ticks
  257. while (%i <= $numtok($1-,32)) {
  258. if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
  259. set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
  260. var %tag $($+(%,youtube.,%ticks,.url),2)
  261. var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
  262. var %tag $deltok($deltok(%tag,2,35),2,38)
  263. set $+(%,youtube.,%ticks,.tag) $remove(%tag,?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
  264. }
  265. inc %i
  266. }
  267. set $+(%,youtube.,%ticks,.msgtype) msg $iif($chan,$v1,$nick)
  268. if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) {
  269. set $+(%,youtube.,%ticks,.nick) $nick
  270. set $+(%,youtube.,%ticks,.chan) $chan
  271. set $+(%,youtube.,%ticks,.network) $network
  272. sockopen $+(youtube.,%ticks) gdata.youtube.com 80
  273. }
  274. }
  275. #parse end
  276. on *:sockopen:youtube*: {
  277. var %ticks $remove($sockname,youtube.)
  278. var %x sockwrite -nt $sockname
  279. if ($($+(%,youtube.,%ticks,.search),2) != $null) {
  280. %x GET $+(/feeds/api/videos?q=,$($+(%,youtube.,%ticks,.query),2),&v=2&prettyprint=true&max-results=,$iif(%_youtube.limit == $null,1,%_youtube.limit)) HTTP/1.1
  281. }
  282. else {
  283. %x GET $+(/feeds/api/videos/,$($+(%,youtube.,%ticks,.tag),2),?v=2&prettyprint=true) HTTP/1.1
  284. }
  285. %x Host: gdata.youtube.com
  286. %x $crlf
  287. }
  288. alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
  289. on *:SOCKREAD:youtube*: {
  290. if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  291. else {
  292. var %ticks $remove($sockname,youtube.)
  293. var %sockreader
  294. sockread %sockreader
  295. if (*<title>* iswm %sockreader) {
  296. set $+(%,youtube.,%ticks,.title) $replace($nohtml(%sockreader),&quot;,",&#39;,',",",&,&,',',",")
  297. if ($($+(%,youtube.,%ticks,.search),2) != $null) {
  298. var %i 0
  299. while (%i <= $numtok($($+(%,youtube.,%ticks,.search),2),32)) {
  300. inc %i
  301. set $+(%,youtube.,%ticks,.title) $regsubex($($+(%,youtube.,%ticks,.title),2), /\b( $gettok($($+(%,youtube.,%ticks,.search),2),%i,32) )\b/gix, $+($chr(2), \1, $chr(2)))
  302. }
  303. }
  304. ;Badword replacement below--useful for bots that kick on badword list. Replace or add words to censor <word,replacement>
  305. set $+(%,youtube.,%ticks,.title) $replace($($+(%,youtube.,%ticks,.title),2),faggot,f****t,black,n****r)
  306. }
  307. elseif (*<id>* iswm %sockreader) { set $+(%,youtube.,%ticks,.tag) $gettok($nohtml(%sockreader),4,58) }
  308. elseif (*<name>* iswm %sockreader) { set $+(%,youtube.,%ticks,.user) $nohtml(%sockreader) }
  309. elseif (*<yt:duration seconds='* iswm %sockreader) {
  310. var %t $duration($gettok(%sockreader,2,39),3)
  311. if (($gettok(%t,2,58) == 00) && ($gettok(%t,1,58) == 00)) {
  312. %t = $puttok(%t,0,2,58)
  313. }
  314. if (($left($gettok(%t,2,58),1) == 0) && ($right($gettok(%t,2,58),1) != 0) && ($right($gettok(%t,2,58),1) isnum)) {
  315. if ($gettok(%t,1,58) == 00) {
  316. %t = $puttok(%t,$right($gettok(%t,2,58),1),2,58)
  317. }
  318. }
  319. if (($left($gettok(%t,1,58),1) == 0) && ($right($gettok(%t,1,58),1) != 0) && ($right($gettok(%t,1,58),1) isnum)) {
  320. %t = $puttok(%t,$right($gettok(%t,1,58),1),1,58)
  321. }
  322. $iif($gettok(%t,1,58) == 00,%t = $gettok(%t,2-3,58),noop)
  323. set $+(%,youtube.,%ticks,.time) %t
  324. }
  325. elseif (*<yt:uploaded>* iswm %sockreader) { set $+(%,youtube.,%ticks,.date) $gettok($nohtml(%sockreader),1,84) }
  326. elseif (*<gd:rating* iswm %sockreader) { set $+(%,youtube.,%ticks,.rating) $round($gettok(%sockreader,2,39),1) $+ /5 }
  327. elseif (*viewCount='* iswm %sockreader) {
  328. set $+(%,youtube.,%ticks,.viewcount) $bytes($gettok(%sockreader,4,39),bd)
  329. set %_youtube.last $($+(%,youtube.,%ticks,.tag),2)
  330. var %msg 1,0You0,4Tube $&
  331. $iif($($+(%,youtube.,%ticks,.search),2) == $null,$null,10Link:4 http://youtu.be/ $+ $($+(%,youtube.,%ticks,.tag),2)) $&
  332. 10Title:4 $($+(%,youtube.,%ticks,.title),2) $&
  333. $iif(%_youtube.noviews == true,$null,10Views:4 $($+(%,youtube.,%ticks,.viewcount),2)) $&
  334. $iif(%_youtube.nolength == true,$null,10Length:4 $($+(%,youtube.,%ticks,.time),2)) $&
  335. $iif(%_youtube.rating == true,$iif($($+(%,youtube.,%ticks,.rating),2) == $null,$null,10Rating:4 $($+(%,youtube.,%ticks,.rating),2)),$null) $&
  336. $iif(%_youtube.date == true,10Uploaded:4 $($+(%,youtube.,%ticks,.date),2),$null) $&
  337. $iif(%_youtube.nouser == true,$null,10User:4 $($+(%,youtube.,%ticks,.user),2))
  338. $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
  339. inc $+(%,youtube.,%ticks,.number)
  340. if ((%_youtube.limit == $($+(%,youtube.,%ticks,.number),2)) || ($($+(%,youtube.,%ticks,.search),2) == $null)) {
  341. unset $+(%,youtube.,$remove($sockname,youtube.),*)
  342. sockclose $sockname
  343. }
  344. }
  345. elseif (*</feed>* iswm %sockreader) {
  346. if ($($+(%,youtube.,%ticks,.number),2) == $null) {
  347. var %msg 1,0You0,4Tube 10No relevant results were found. Try different search terms.
  348. $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
  349. }
  350. unset $+(%,youtube.,$remove($sockname,youtube.),*)
  351. sockclose $sockname
  352. }
  353. }
  354. }
  355. on *:sockclose:youtube*: { unset $+(%,youtube.,$remove($sockname,youtube.),*) }
  356. on *:start: .timerYTUpdate 1 60 yupdate
  357. alias yupdate {
  358. echo -atc info 12[04YouTube12] Checking for updates...
  359. sockopen yupdate www.hawkee.com 80
  360. }
  361. on *:sockopen:yupdate: {
  362. sockwrite -nt $sockname GET /snippet/8577/ HTTP/1.1
  363. sockwrite -nt $sockname Host: www.hawkee.com
  364. sockwrite -nt $sockname $crlf
  365. }
  366. on *:SOCKREAD:yupdate: {
  367. if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
  368. sockread %sockreader
  369. if (*<title>* iswm %sockreader) {
  370. var %x $gettok($nohtml(%sockreader),7,32)
  371. echo -atc info 12[04YouTube12] Current: $yversion Latest: %x Status: $iif($yversion == %x,Up to date,Please update at www.hawkee.com/snippet/8577/)
  372. unset %sockreader
  373. sockclose $sockname
  374. }
  375. }

comments powered by Disqus