View difference between Paste ID: siZWjRhK and ia022rDG
SHOW: | | - or go back to the newest paste.
1-
;YouTube Script (Parse Vids and Search) v6.3
1+
;YouTube Script (Parse Vids and Search) v6.4
2
;Made by nick1
3-
;Last edit May 06, 2016
3+
;Last edit June 20, 2016
4
;For help/setup type /YouTube in mIRC
5
;2D0 -- You tell me in the comments! http://hawkee.com/snippet/8577/
6-
;EDITS -- Update check message only appears if needs an update, fixed &feature=youtu.be bug, doesn't parse channel links
6+
;EDITS -- Fixed bug where youtube.com would say invalid video (and cleaned up some other code in the parse section)
7-
;EDITS -- better variable cleanup, multiple search results displayed
7+
8
alias -l yversion { return v6.4 }
9-
alias -l yversion { return v6.3 }
9+
10
11
menu status,channel,query {
12
  YouTube:youtube
13
}
14
15
alias YouTube { dialog -m YouTube YouTube }
16
17
dialog Youtube {
18
  title "YouTube v6.4"
19-
  title "YouTube v6.3"
19+
20
  option dbu
21
  icon $mircdirYoutube.ico, 0
22
  link "View Script On Hawkee", 1, 3 2 59 8
23
  button "Exit", 7, 88 181 72 12, cancel
24
  tab "About", 10, 2 9 235 169
25
  link "YouTube Script (Parse Vids and Search) v6.4 -- Post Bugs and Feature Requests Here", 24, 16 26 208 8, tab 10
26-
  link "YouTube Script (Parse Vids and Search) v6.3 -- Post Bugs and Feature Requests Here", 24, 16 26 208 8, tab 10
26+
  text "Last updated on June 20 2016", 19, 7 66 95 8, tab 10
27-
  text "Last updated on May 06 2016", 19, 7 66 95 8, tab 10
27+
28
  text "!commands will notice the user; @commands will be public to the channel", 13, 7 93 175 8, tab 10
29
  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 114 208 14, tab 10
30
  link "Click here to chat (leave a message for nick1)", 66, 58 50 110 8, tab 10
31
  text "Use the Basic Options Tab to adjust which parts of the script will run and basic formatting options.", 23, 7 142 195 13, tab 10
32
  button "Check for Updates", 21, 102 64 54 12, tab 10
33
  tab "Basic Options", 2
34
  box "Search Commands/Options", 60, 7 52 209 29, tab 2
35
  text "youtube <search terms>; ytsearch <search>; ysearch <search terms>", 62, 10 60 175 8, tab 2
36
  box "Disable Options", 5, 7 23 209 27, tab 2
37
  check "Disable Search - Disables search commands below", 11, 11 29 133 10, tab 2 flat
38
  check "Disable Parse - Disables the script from automatically sending info", 14, 11 38 175 10, tab 2 flat
39
  box "Output Options", 9, 7 83 209 93, tab 2
40
  check "Disable Views - Removes 'Views: <Views>'", 15, 11 90 123 10, tab 2
41
  check "Disable Length - Removes 'Length: <Length>'", 16, 11 99 130 10, tab 2
42
  check "Disable User - Removes 'User: <User>'", 17, 11 108 113 10, tab 2
43
  check "Disable Formatting - Removes Colors and Bold", 22, 11 117 127 10, tab 2
44
  edit "", 58, 99 69 15 10, tab 2 limit 1
45
  text "Number of search results displayed:", 25, 10 70 87 8, tab 2
46
  check "Enable Date - Adds 'Uploaded: <Date>'", 57, 11 126 120 10, tab 2
47
  check "Enable Likes - Adds 'Likes: <Likes>", 27, 11 135 130 10, tab 2
48
  check "Enable Dislikes - Adds 'Dislikes: <Dislikes>", 28, 11 144 130 10, tab 2
49
  check "Enable Description - Adds 'Description <Description>", 29, 11 153 139 10, tab 2
50
  check "Enable Notice Mode (Does Not Message Channel)", 30, 11 163 139 10, tab 2
51
  tab "Channel Settings", 3
52
  list 6, 8 56 220 116, tab 3 sort size extsel vsbar
53
  edit "", 8, 9 26 155 25, tab 3 multi autohs autovs
54
  text "List of channels the script will NOT run on", 12, 48 50 101 6, tab 3
55
  button "Add", 4, 190 25 37 12, tab 3
56
  button "Remove", 63, 190 42 37 12, tab 3
57
  button "Click here to enter #channels ...", 64, 10 27 153 23, tab 3
58
  tab "Nick Settings", 26
59
  text "List of nicks the script will NOT run for", 70, 48 50 101 6, tab 26
60
  list 71, 8 56 220 116, tab 26 sort size extsel vsbar
61
  button "Remove", 72, 190 42 37 12, tab 26
62
  button "Add", 73, 190 25 37 12, tab 26
63
  edit "", 69, 9 26 155 25, tab 26 multi autohs autovs
64
  button "Click here to enter Nicks ...", 74, 10 27 153 23, tab 26
65
  text "This script created by nick1", 18, 171 2 66 8
66
}
67
68
on *:dialog:youtube:init:0: {
69
  FillChannelBox
70
  FillNickBox
71
  $iif(%_youtube.nocolor == true,did -c youtube 22,noop)
72
  did -a youtube 58 $iif(%_youtube.limit == $null,1,%_youtube.limit)
73
  $iif(%_youtube.noviews == true,did -c youtube 15,noop)
74
  $iif(%_youtube.nolength == true,did -c youtube 16,noop)
75
  $iif(%_youtube.nouser == true,did -c youtube 17,noop)
76
  $iif(%_youtube.date == true,did -c youtube 57,noop)
77
  $iif(%_youtube.likes == true,did -c youtube 27,noop)
78
  $iif(%_youtube.dislikes == true,did -c youtube 28,noop)
79
  $iif(%_youtube.description == true,did -c youtube 29,noop)
80
  $iif(%_youtube.notices == true,did -c youtube 30,noop)
81
  $iif($group(#search) != on,did -c youtube 11,noop)
82
  $iif($group(#parse) != on,did -c youtube 14,noop)  
83
}
84
alias FillChannelBox {
85
  did -r youtube 6
86
  var %y 1
87
  while (%y <= $numtok(%youtubefetch,44)) {
88
    did -a youtube 6 $gettok(%youtubefetch,%y,44)
89
    inc %y
90
  }
91
}
92
alias FillNickBox {
93
  did -r youtube 71
94
  var %y 1
95
  while (%y <= $numtok(%nolinks,44)) {
96
    did -a youtube 71 $gettok(%nolinks,%y,44)
97
    inc %y
98
  }
99
}
100
on *:dialog:youtube:edit:58: {
101
  if (($did(58).text < 1) || ($did(58).text !isnum) && ($did(58).text != $null)) {
102
    did -r youtube 58
103
    noop $input(Enter a number between 1 and 9, owd, Invalid input!)
104
  }
105
  elseif ($did(58).text != $null) { set %_youtube.limit $did(58).text }
106
}
107
on *:dialog:youtube:sclick:*: {
108
  if (($did == 1) || ($did == 24)) { run http://hawkee.com/snippet/8577/ }
109
  elseif ($did == 66) { server -m irc.rizon.net:6667 -jn #rsbot_help }
110
  elseif ($did == 22) { set %_youtube.nocolor $iif($did(22).state,true,false) }
111
  elseif ($did == 15) { set %_youtube.noviews $iif($did(15).state,true,false) }
112
  elseif ($did == 16) { set %_youtube.nolength $iif($did(16).state,true,false) }
113
  elseif ($did == 17) { set %_youtube.nouser $iif($did(17).state,true,false) }
114
  elseif ($did == 57) { set %_youtube.date $iif($did(57).state,true,false) }
115
  elseif ($did == 27) { set %_youtube.likes $iif($did(27).state,true,false) }
116
  elseif ($did == 28) { set %_youtube.dislikes $iif($did(28).state,true,false) }
117
  elseif ($did == 29) { set %_youtube.description $iif($did(29).state,true,false) }
118
  elseif ($did == 30) { set %_youtube.notices $iif($did(30).state,true,false) }
119
  elseif ($did == 11) { $iif($group(#search) == on,.disable,.enable) #search }
120
  elseif ($did == 21) { yupdate }
121
  elseif ($did == 14) { $iif($group(#parse) == on,.disable,.enable) #parse }
122
  elseif ($did == 4) {
123
    set %youtubefetch $addtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
124
    did -r youtube 8
125
    FillChannelBox
126
  }
127
  elseif ($did == 73) {
128
    set %nolinks $addtok(%nolinks,$did(69),44)
129
    did -r youtube 69
130
    FillNickBox
131
  }
132
  elseif ($did == 63) {
133
    if ($did(8) != $null) {
134
      set %youtubefetch $remtok(%youtubefetch,$iif(($left($did(8),1) == $chr(35)),$did(8),$+($chr(35),$did(8))),44)
135
      did -r youtube 8
136
    }
137
    if ($did(6).seltext != $null) { set %youtubefetch $remtok(%youtubefetch,$did(6).seltext,44) }
138
    FillChannelBox
139
  }
140
  elseif ($did == 3) { did -t youtube 4 }
141
  elseif ($did == 26) { did -t youtube 73 }
142
  elseif ($did == 72) {
143
    if ($did(69) != $null) {
144
      set %nolinks $remtok(%nolinks,$did(69),44)
145
      did -r youtube 69
146
    }
147
    if ($did(71).seltext != $null) { set %nolinks $remtok(%nolinks,$did(71).seltext,44) }
148
    FillNickBox
149
  }
150
}
151
152
raw 408:*: msg $2 $remove($strip($13-),$chr(9),$chr(8))
153
154
alias urlencode { return $replacex($regsubex($$1-,/([^\w\s])/Sg,$+(%,$base($asc(\t),10,16,2))),$chr(32),+,$chr(43),%2B) }
155
156
on $*:text:/^[!@](disableyt|offyt|disableyoutube|offyoutube)(\s|$)/Si:?: {
157
  if ($2) {
158
    if ($me ison $2) {
159
      if ($nick isop $2) {
160
        msg $nick 4Youtube has been10 disabled on $+(,$2,)
161
        set %youtubefetch $addtok(%youtubefetch,$2,44)
162
      }
163
      else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to disable youtube there }
164
    }
165
    else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
166
  }
167
  elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
168
}
169
on $*:text:/^[!@](enableyt|onyt|enableyoutube|onyoutube)(\s|$)/Si:?: {
170
  if ($2) {
171
    if ($me ison $2) {
172
      if ($nick isop $2) {
173
        msg $nick 4Youtube has been10 enabled on $+(,$2,)
174
        set %youtubefetch $remtok(%youtubefetch,$2,44)
175
      }
176
      else { msg $nick 4Sorry, you must be an10 op of $+(,$2,) to enable youtube there }
177
    }
178
    else { msg $nick 4Sorry, I am not10 currently in $+(,$2,) }
179
  }
180
  elseif ($2 == $null) { msg $nick 4Incorrect Syntax - Use10 $1 <#channel> }
181
}
182
183
#search on
184
on $*:text:/^[!@]y(outube|t|tsearch|search|ousearch|outubesearch)(\s|$)/Si:*: {
185
  $iif($istok(%youtubefetch,$chan,44),halt,noop)
186
  $iif($istok(%nolinks,$nick,44),halt,noop)
187
  if ($($+(%,botflood.,$nick),2)) {
188
    if ($($+(%,botflood.,$nick),2) >= 50) { 
189
      ignore -u60 $address($nick,2) 
190
      msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
191
      halt 
192
    }
193
    elseif ($($+(%,botflood.,$nick),2) >= 40) { 
194
      msg $chan $+($nick,$chr(44)) Please do not flood the bot. 
195
      inc -z $+(%,botflood.,$nick) 20 
196
      halt 
197
    }
198
    else { inc -z $+(%,botflood.,$nick) 25 }
199
  }
200
  else { inc -z $+(%,botflood.,$nick) 25 }
201
  var %ticks $ticks
202
  if ($2) {
203
    if ($chan) {
204
      if (($left($strip($1),1) == @) && (%_youtube.notices != true)) { set $+(%,youtube.,%ticks,.msgtype) msg $chan }
205
      else { set $+(%,youtube.,%ticks,.msgtype) notice $nick }
206
    }
207
    else { set $+(%,youtube.,%ticks,.msgtype) msg $nick }
208
    set $+(%,youtube.,%ticks,.search) $2-
209
    set $+(%,youtube.,%ticks,.query) $urlencode($2-)
210
    sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
211
  }
212
  elseif ($2 == $null) { 
213
    notice $nick 4Incorrect Syntax - Use10 $1 <search term> 
214
  }
215
}
216
217
on *:input:*:{
218
  $iif($istok(%nolinks,$active,44),return,noop)
219
  $iif($istok(%youtubefetch,$active,44),return,noop)
220
  var %ticks $ticks
221
  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)) {
222
    if ($left($1,1) != /) {
223
      if ($2 != $null) {
224
        set $+(%,youtube.,%ticks,.msgtype) msg $active
225
        set $+(%,youtube.,%ticks,.search) $2-
226
        set $+(%,youtube.,%ticks,.query) $urlencode($2-)
227
        sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
228
      }
229
      elseif ($2 == $null) {
230
        .timerYTInputSyntax -m 1 100 echo -at 4Incorrect Syntax - Use10 $1 <search term> 
231
      }
232
    }
233
  }
234
  elseif ((*youtube.com* iswm $1-) || (*youtu.be* iswm $1-)) {
235
    if ($left($1,1) != /) {
236
      var %i 1
237
      while (%i <= $numtok($1-,32)) {
238
        if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
239
          if (*/playlist* iswm $($+($,%i),2)) { halt }
240
          set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
241
          var %tag $($+(%,youtube.,%ticks,.url),2)
242
          var %tag $iif($numtok(%tag,46) > 1,$gettok(%tag,$calc($numtok(%tag,46)-1) - $numtok(%tag,46),46),%tag)
243
          var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
244
          var %tag $deltok($deltok(%tag,2,35),2,38)
245
          if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
246
          set $+(%,youtube.,%ticks,.tag) $remove(%tag,com/watch?v=,youtube.,$chr(40),$chr(41),?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
247
        }
248
        inc %i
249
      }
250
      if (($($+(%,youtube.,%ticks,.tag),2) == %_youtube.last) || ($($+(%,youtube.,%ticks,.tag),2) == $null) || ($($+(%,youtube.,%ticks,.tag),2) == com) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
251-
      if (($($+(%,youtube.,%ticks,.tag),2) == $null) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
251+
252
      }
253
      else {
254
        set $+(%,youtube.,%ticks,.msgtype) $iif(%_youtube.notices == true,echo -a,msg $active)
255
        set $+(%,youtube.,%ticks,.nick) $nick
256
        set $+(%,youtube.,%ticks,.chan) $chan
257
        set $+(%,youtube.,%ticks,.network) $network
258
        sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
259
      }
260
    }
261
  }
262
}
263
264
#search end
265
266
#parse on
267
on $*:text:/youtu(.be|be.com)/Si:*: {
268
  $iif($istok(%youtubefetch,$chan,44),halt,noop)
269
  $iif($istok(%nolinks,$nick,44),halt,noop)
270
  if ($($+(%,botflood.,$nick),2)) {
271
    if ($($+(%,botflood.,$nick),2) >= 50) { 
272
      ignore -u60 $address($nick,2) 
273
      msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot. 
274
      halt 
275
    }
276
    elseif ($($+(%,botflood.,$nick),2) >= 40) {
277
      msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
278
      inc -z $+(%,botflood.,$nick) 20 
279
      halt 
280
    }
281
    else { 
282
      inc -z $+(%,botflood.,$nick) 10 
283
    }
284
  }
285
  else { inc -z $+(%,botflood.,$nick) 10 }
286
  var %i 1
287
  var %ticks $ticks
288
  while (%i <= $numtok($1-,32)) {
289
    if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
290
      if (*/playlist* iswm $($+($,%i),2)) { halt }
291
      set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
292
      var %tag $($+(%,youtube.,%ticks,.url),2)
293
      var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
294
      var %tag $deltok($deltok(%tag,2,35),2,38)
295
      if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
296
      set $+(%,youtube.,%ticks,.tag) $remove(%tag,com/watch?v=,youtube.,?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
297
    }
298
    inc %i
299
  }
300
  if ($chan) {
301
    if (%_youtube.notices != true) { set $+(%,youtube.,%ticks,.msgtype) msg $chan }
302
    else { set $+(%,youtube.,%ticks,.msgtype) notice $nick }
303
  }
304
  else { set $+(%,youtube.,%ticks,.msgtype) msg $nick }
305
  if (($($+(%,youtube.,%ticks,.tag),2) == %_youtube.last) || ($($+(%,youtube.,%ticks,.tag),2) == $null) || ($($+(%,youtube.,%ticks,.tag),2) == com) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
306-
  if (($($+(%,youtube.,%ticks,.tag),2) == %_youtube.last) || ($($+(%,youtube.,%ticks,.tag),2) == $null) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
306+
307
  }
308
  else {
309
    set $+(%,youtube.,%ticks,.nick) $nick
310
    set $+(%,youtube.,%ticks,.chan) $chan
311
    set $+(%,youtube.,%ticks,.network) $network
312
    sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
313
  }
314
}
315-
  else { .timerYoutubeVarDelete 1 1 unset $+(%,youtube.,%ticks,.*) }
315+
316
  $iif($istok(%youtubefetch,$chan,44),halt,noop)
317
  $iif($istok(%nolinks,$nick,44),halt,noop)
318
  if ($($+(%,botflood.,$nick),2)) {
319
    if ($($+(%,botflood.,$nick),2) >= 50) { 
320
      ignore -u60 $address($nick,2) 
321
      msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot. 
322
      halt 
323
    }
324
    elseif ($($+(%,botflood.,$nick),2) >= 40) {
325
      msg $chan $+($nick,$chr(44)) Please do not flood the bot.  
326
      inc -z $+(%,botflood.,$nick) 20 
327
      halt 
328
    }
329
    else { 
330
      inc -z $+(%,botflood.,$nick) 10 
331
    }
332
  }
333
  else { inc -z $+(%,botflood.,$nick) 10 }
334
  var %i 1
335
  var %ticks $ticks
336
  while (%i <= $numtok($1-,32)) {
337
    if ((*youtube.com* iswm $($+($,%i),2)) || (*youtu.be* iswm $($+($,%i),2))) {
338
      set $+(%,youtube.,%ticks,.url) $strip($($+($,%i),2))
339
      var %tag $($+(%,youtube.,%ticks,.url),2)
340
      var %tag $iif($numtok(%tag,46) > 1,$gettok(%tag,$calc($numtok(%tag,46)-1) - $numtok(%tag,46),46),%tag)
341
      var %tag $iif($matchtok(%tag,v=,1,38),$v1,%tag)
342
      var %tag $deltok($deltok(%tag,2,35),2,38)
343
      if (*youtu.be* iswm %tag) { var %tag $gettok(%tag,1,63) }
344
      set $+(%,youtube.,%ticks,.tag) $remove(%tag,$chr(40),$chr(41),?,m.,v=,/watch?src_vid=,https://,http://,www.,/v/,youtube.com,youtu.be,youtu.be/,/watch?v=,/watch,?v=,$chr(31),#!,/)
345
    }
346
    inc %i
347
  }
348
  set $+(%,youtube.,%ticks,.msgtype) msg $iif($chan,$v1,$nick)
349
  if (($($+(%,youtube.,%ticks,.tag),2) == %_youtube.last) || ($($+(%,youtube.,%ticks,.tag),2) == $null) || ($($+(%,youtube.,%ticks,.tag),2) == com) || (*/channel/* iswm $($+(%,youtube.,%ticks,.url),2)) || (*/user/* iswm $($+(%,youtube.,%ticks,.url),2))) {
350
    unset $+(%,youtube.,%ticks,.*)
351-
  if (($($+(%,youtube.,%ticks,.tag),2) != %_youtube.last) && ($($+(%,youtube.,%ticks,.tag),2) != $null)) {
351+
352
  else {
353
    set $+(%,youtube.,%ticks,.nick) $nick
354
    set $+(%,youtube.,%ticks,.chan) $chan
355
    set $+(%,youtube.,%ticks,.network) $network
356
    sockopen -e $+(youtube.,%ticks) www.googleapis.com 443
357-
  else { .timerYoutubeVarDelete 1 1 unset $+(%,youtube.,%ticks,.*) }
357+
358
}
359
360
#parse end
361
362
on *:sockopen:youtube*: { 
363
  var %ticks $remove($sockname,youtube.)
364
  var %x sockwrite -nt $sockname
365
  if (($($+(%,youtube.,%ticks,.search),2) != $null) && ($($+(%,youtube.,%ticks,.round2),2) != true)) {
366
    var %temp_search0 /youtube/v3/search?safeSearch=none&order=relevance&part=snippet&q=
367
    %x GET $+(%temp_search0,$($+(%,youtube.,%ticks,.query),2),&maxResults=,$iif(%_youtube.limit == $null,1,%_youtube.limit),&key=,$yapi) HTTP/1.1
368
  }
369
  else {
370
    var %temp_search1 $(/youtube/v3/videos?part=contentDetails%2Cstatistics%2Csnippet&id=,0)
371
    var %temp_search2 &maxResults=1&fields=items $+ $chr(40) $+ $(contentDetails%2Csnippet%2Cstatistics,0) $+ $chr(41)
372
    %x GET $+(%temp_search1,$($+(%,youtube.,%ticks,.tag),2),%temp_search2,&key=,$yapi) HTTP/1.1
373
  }
374
  %x Host: www.googleapis.com
375
  %x $crlf
376
}
377
alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }
378
alias yinfo {
379
  var %step1 errRemoval $gettok($1-,2-,58) errRemoval
380
  return $replace($gettok(%step1,$+(2-,$calc($numtok(%step1,34) - 1)),34),\r\n,$chr(32),\n,$chr(32),\","))
381
}
382
on *:SOCKREAD:youtube*: { 
383
  if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
384
  else {
385
    var %ticks $gettok($sockname,2,46)
386
    var %sockreader
387
    sockread %sockreader
388
    if ((*"title": * iswm %sockreader) && ($($+(%,youtube.,%ticks,.title),2) == $null)) {
389
      set $+(%,youtube.,%ticks,.title) $yinfo(%sockreader)
390
      if ($($+(%,youtube.,%ticks,.search),2) != $null) {
391
        var %i 0
392
        while (%i <= $numtok($($+(%,youtube.,%ticks,.search),2),32)) {
393
          inc %i
394
          set $+(%,youtube.,%ticks,.title) $regsubex($($+(%,youtube.,%ticks,.title),2), /\b( $gettok($($+(%,youtube.,%ticks,.search),2),%i,32) )\b/gix, $+($chr(2), \1, $chr(2)))
395
        }
396
      }
397
      ;Badword replacement below--useful for bots that kick on badword list. Replace or add words to censor <word,replacement>
398
      set $+(%,youtube.,%ticks,.title) $replace($($+(%,youtube.,%ticks,.title),2),faggot,f****t,nigger,n****r)
399
    }
400
    elseif (*"videoId": * iswm %sockreader) {
401
      var %temp $ticks
402
      set $+(%,youtube.,%temp,.round2) true
403
      set $+(%,youtube.,%temp,.search) $($+(%,youtube.,%ticks,.search),2)
404
      set $+(%,youtube.,%temp,.query) $($+(%,youtube.,%ticks,.query),2)
405
      set $+(%,youtube.,%temp,.msgtype) $($+(%,youtube.,%ticks,.msgtype),2)
406
      set $+(%,youtube.,%temp,.tag) $yinfo(%sockreader)
407
      sockopen -e $+(youtube.,%temp) www.googleapis.com 443
408
      inc $+(%,youtube.,%ticks,.number)
409
      if (%_youtube.limit == $($+(%,youtube.,%ticks,.number),2)) {
410
        unset $+(%,youtube.,$remove($sockname,youtube.),*)
411
        sockclose $sockname
412
      }
413
    }
414
    elseif (*channelTitle": * iswm %sockreader) { set $+(%,youtube.,%ticks,.user) $yinfo(%sockreader) }
415
    elseif (*"duration": * iswm %sockreader) { 
416
      set $+(%,youtube.,%ticks,.time) $regsubex($duration($calc($replace( $remove($yinfo(%sockreader), P, T), W, *604800+, D, *86400+, H, *3600+, M, *60+, S,*1)), 3), /^[0:]+, )
417
    }
418
    elseif (*"publishedAt": * iswm %sockreader) { set $+(%,youtube.,%ticks,.date) $gettok($yinfo(%sockreader),1,84) }
419
    elseif ((*"description": * iswm %sockreader) && ($($+(%,youtube.,%ticks,.description),2) == $null)) {
420
      var %wrong errRemoval ", errRemoval
421
      var %desc $yinfo(%sockreader)
422
      if (($gettok(%sockreader,4,34) == $null) || (%desc == %wrong)) { set $+(%,youtube.,%ticks,.description) N/A }
423
      else { set $+(%,youtube.,%ticks,.description) $iif($numtok(%desc,32) > 10,$+($gettok(%desc,1-8,32),...),%desc) }
424
    }
425
    elseif (*"viewCount": * iswm %sockreader) { set $+(%,youtube.,%ticks,.viewcount) $bytes($yinfo(%sockreader),bd) }
426
    elseif (*"likeCount": * iswm %sockreader) { set $+(%,youtube.,%ticks,.likes) $bytes($yinfo(%sockreader),bd) } 
427
    elseif (*"dislikeCount": * iswm %sockreader) || (($($+(%,youtube.,%ticks,.viewcount),2) != $null) && (*}* iswm %sockreader)) { 
428
      set $+(%,youtube.,%ticks,.dislikes) $bytes($yinfo(%sockreader),bd)
429
      set %_youtube.last $($+(%,youtube.,%ticks,.tag),2)
430
      $iif($($+(%,youtube.,%ticks,.viewcount),2) == 301,set $+(%,youtube.,%ticks,.viewcount) 301+,noop)
431
      var %msg 1,0You0,4Tube $&
432
        $iif($($+(%,youtube.,%ticks,.search),2) ==  $null,$null,10Link:4 http://youtu.be/ $+ $($+(%,youtube.,%ticks,.tag),2)) $&
433
        10Title:4 $($+(%,youtube.,%ticks,.title),2) $&
434
        $iif(%_youtube.noviews == true,$null,10Views:4 $($+(%,youtube.,%ticks,.viewcount),2)) $&
435
        $iif(%_youtube.nolength == true,$null,10Length:4 $($+(%,youtube.,%ticks,.time),2)) $&
436
        $iif(%_youtube.date == true,10Uploaded:4 $($+(%,youtube.,%ticks,.date),2),$null) $&
437
        $iif(%_youtube.nouser == true,$null,10User:4 $($+(%,youtube.,%ticks,.user),2)) $&
438
        $iif(%_youtube.likes == true,10Likes:4 $($+(%,youtube.,%ticks,.likes),2),$null) $&
439
        $iif(%_youtube.dislikes == true,10Dislikes:4 $($+(%,youtube.,%ticks,.dislikes),2),$null) $&
440
        $iif(%_youtube.description == true,10Description:4 $($+(%,youtube.,%ticks,.description),2),$null)
441
      var %msg = $remove(%msg,$chr(9))
442
      $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
443
      unset $+(%,youtube.,$remove($sockname,youtube.),*)
444
      sockclose $sockname
445
    }
446
    elseif (*"totalResults": 0,* iswm %sockreader) {
447
      var %msg 1,0You0,4Tube 10No relevant results were found. Try different search terms.
448
      $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
449
450
      unset $+(%,youtube.,$remove($sockname,youtube.),*)
451
      sockclose $sockname
452
    }
453
    elseif (*"items": []* iswm %sockreader) {
454
      var %msg 1,0You0,4Tube 10This video was removed or is no longer available.
455
      $($+(%,youtube.,%ticks,.msgtype),2) $iif(%_youtube.nocolor == true,$strip(%msg),%msg)
456
      unset $+(%,youtube.,$remove($sockname,youtube.),*)
457
      sockclose $sockname
458
    }
459
  }
460
}
461
on *:sockclose:youtube*: { unset $+(%,youtube.,$remove($sockname,youtube.),*) }
462
on *:start: .timerYTUpdate 1 60 yupdate
463
alias yupdate {
464
  unset %youtube.* | unset %ysearch.*
465
  ;echo -atc info 12[04YouTube12] Checking for updates and clearing variables...
466
  sockopen yupdate hawkee.com 80
467
}
468
on *:sockopen:yupdate: {  
469
  var %x sockwrite -nt $sockname
470
  %x GET /snippet/8577/ HTTP/1.1
471
  %x Host: hawkee.com
472
  %x $crlf
473
}
474
on *:SOCKREAD:yupdate: { 
475
  if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
476
  sockread %sockreader
477
  if (*<title>* iswm %sockreader) {
478
    var %x $remove($gettok($nohtml(%sockreader),7-,32),- mIRC)
479
    if ($yversion != %x) {
480
      echo -atc info 12[04YouTube12] Current: $yversion Latest: %x Status: Please check for updates at http://hawkee.com/snippet/8577/
481
    }
482
    unset %sockreader
483
    sockclose $sockname
484
  }
485
}