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