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