forked from DanielVoipan/TCL-eggdrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.tcl
422 lines (381 loc) · 20.5 KB
/
youtube.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
##########################################################################################
# Youtube Title 2.0
# - fetches and displays video information when a YouTube link is posted in channel.
# - displays title, date and rating of posted video links.
# - supports also HTTPS links.
#
# UPDATES/CHANGES:
# - (2.0) http package no longer needed. Now You can specify your Youtube php source (get it from tclscripts.net)
# - (1.9.1) changed hosting
# - (1.9) added stars for like display instead of procentages
# - (1.8) added anti-flood support
# - (1.8) added youtube search (it will get info from the first youtube video)
# - (1.8) added support for music.youtube links
# - (1.8) shows total links/searches processed by the website
# - (1.7) shows info about duration/length
# - (1.6) multiple output methods of showing the infos configurable via channel
# - (1.6) multi-language support configurable via channel
# - (1.6) supports eggdrop version less than 1.8.*
# - (1.6) options/settings are now case sensitive
#
# To activate - .chanset #channel +ytitle | BlackTools : .set +ytitle
# To activate Youtube search - .chanset #channel +ytsearch | BlackTools : .set +ytsearch
#
# To chose a different language .set ytlang <RO> / <EN> / <FR> / <ES> / <IT>
#
# BLaCkShaDoW ProductionS
# _ _ _ _ _ _ _ _ _ _ _ _ _ _
# / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \
# ( t | c | l | s | c | r | i | p | t | s | . | n | e | t )
# \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
# #TCL-HELP @ Undernet.org
#
##########################################################################################
###
# Channel flags
# - to activate the script: .set +ytitle or .chanset #channel +ytitle
#
# - to change script language:
# .set ytlang <ro/en/fr/es/it> or .chanset #channel ytlang <ro/en/fr/es/it>
#
# - to set script color
# .set ytcolor <0/1> ; 1 - colors ; 0 - no colors
#
###
###
# Set the website where from where information will be take from (without http://)
# You can download the "youtube php source" from tclscripts.net if you want different website
###
set ytitle(website_url) "domaine"
###
# If you put the files in a subdirectory of the website (rather then directy in public_html or www) please specify here the directory
# if not, leave here ""
###
set ytitle(website_subdirectory) "folder_name"
###
# YOUTUBE SEARCH COMMAND
#
###
set ytitle(youtube_search_cmd) "yt"
###
# WHAT FLAGS CAN SEARCH VIA COMMAND ? (default -|-)
#
###
set ytitle(youtube_search_flags) "-|-"
###
# FLOOD PROTECTION
#Set the number of minute(s) to ignore flooders, 0 to disable flood protection
###
set ytitle(ignore_prot) "1"
###
# FLOOD PROTECTION
#Set the number of requests within specifide number of seconds to trigger flood protection.
# By default, 3:10, which allows for upto 3 queries in 10 seconds. 3 or more quries in 10 seconds would cuase
# the forth and later queries to be ignored for the amount of time specifide above.
###
set ytitle(flood_prot) "3:10"
###
# Language setting
# - what language you want to receive the youTube data
# ( RO / EN / ES / FR / IT )
#
set ytitle(default_lang) "ES"
###
# Colors setting
# - what format you want to receive the youTube data
# (1) Enable or (0) disable colors
#
set ytitle(colors) "1"
##########################################################################################
package require tls
package require http
###
# Bindings
# - using commands
###
bind pubm - * check:youtube
bind ctcp - ACTION check:youtube:me
bind pub $ytitle(youtube_search_flags) $ytitle(youtube_search_cmd) search:youtube
setudef flag ytitle
setudef str ytlang
setudef str ytcolor
setudef flag ytsearch
###
# Functions
# Do NOT touch unless you know what you are doing
###
###
proc search:youtube {nick host hand chan arg} {
if {![channel get $chan ytsearch]} {
return
}
set flood_protect [youtube:flood:prot $chan $host]
if {$flood_protect == "1"} {
return
}
set text [lrange [split $arg] 0 end]
if {$text == ""} {
return
}
set text [join $text "+"]
youtube:get:title $text $nick $chan 1
}
###
proc check:youtube {nick host hand chan arg} {
set arg [split $arg]
if {![channel get $chan ytitle]} {
return
}
set flood_protect [youtube:flood:prot $chan $host]
if {$flood_protect == "1"} {
return
}
foreach word $arg {
set youtube_link "$word"
if {[string match -nocase "*youtube.com/watch*" $youtube_link] || [string match -nocase "*youtu.be*" $youtube_link]} {
youtube:get:title $youtube_link $nick $chan 0
}
}
}
###
proc tls:socket args {
set opts [lrange $args 0 end-2]
set host [lindex $args end-1]
set port [lindex $args end]
::tls::socket -servername $host {*}$opts $host $port
}
###
proc youtube:get:title {link nick chan type} {
global ytitle
set live 0
if {$ytitle(website_subdirectory) != ""} {
set l "/$ytitle(website_subdirectory)/index.php"
} else {
set l "/index.php"
}
set ipq [http::config -useragent "lynx"]
http::register https 443 [list tls::socket]
if {$type == "0"} {
set ipq [http::geturl "https://$ytitle(website_url)$l?link=$link" -timeout 50000]
} else {
set ipq [http::geturl "https://$ytitle(website_url)$l?search=$link" -timeout 50000]
}
set getipq [http::data $ipq]
set output [split $getipq "\n"]
http::cleanup $ipq
set title [string map { "&" "&"
"'" "'"
""" "\""
} [lindex $output 0]]
set title [concat $title]
set views [lindex $output 1]
if {$views == ""} { set views "N/A" }
set split_views [split $views " "]
set views [lindex $split_views 0]
set views [string map {" " "."} $views]
set likes [lindex $output 2]
set dontlike [concat [lindex $output 3]]
set bywho [concat [lindex $output 4]]
set update [lindex $output 5]
set duration [lindex $output 6]
set total_links [lindex $output 8]
set get_link [lindex $output 7]
set duration [string map {"PT" ""} $duration]
set minutes [lindex [split $duration "M"] 0]
set seconds [concat [string map {"S" ""} [lindex [split $duration "M"] 1]]]
set scan [clock scan $update -format {%Y-%m-%d}]
set update [clock format $scan -format {%d/%m/%Y}]
set like_bar [youtube:like_bar $likes $dontlike $chan]
if {$views == ""} { set views "N/A" }
youtube:tell $nick $chan $type [list $title $bywho $views $like_bar $dontlike $update $minutes $seconds $total_links $get_link]
}
###
proc youtube:tell {nick chan search arg} {
global black ytitle
set inc 0
foreach s $arg {
set inc [expr $inc + 1]
set replace(%msg.$inc%) $s
}
set getlang [youtube:getlang $chan]
if {$arg == "1"} {
if {[info exists black(ytitle.$getlang.3)]} {
set reply [string map [array get replace] $black(ytitle.$getlang.3)]
putserv "PRIVMSG $chan :$reply"
}
return
}
set setcolor [youtube:getcolor $chan]
if {$search == "1"} {
if {$setcolor == "1"} {
set type 5
} else { set type 4 }
if {[info exists black(ytitle.$getlang.$type)]} {
set reply [string map [array get replace] $black(ytitle.$getlang.$type)]
putserv "PRIVMSG $chan :$reply"
}
} else {
if {$setcolor == "1"} {
set type 2
} else { set type 1 }
if {[info exists black(ytitle.$getlang.$type)]} {
set reply [string map [array get replace] $black(ytitle.$getlang.$type)]
putserv "PRIVMSG $chan :$reply"
}
}
}
###
proc youtube:getlang {chan} {
global black ytitle
set getlang [string tolower [channel get $chan ytlang]]
if {$getlang == ""} {
set lang "en"
} else {
if {[info exists black(ytitle.$getlang.1)]} {
set lang $getlang
} else {
set lang $ytitle(default_lang)
}
}
return [string tolower $lang]
}
###
proc youtube:getcolor {chan} {
global ytitle
set getcolor [string tolower [channel get $chan ytcolor]]
if {$getcolor == ""} {
set type $ytitle(colors)
} else {
set type $getcolor
}
return $type
}
###
proc check:youtube:me {nick host hand chan keyword arg} {
check:youtube $nick $host $hand $chan $arg
return
}
###
proc youtube:flood:prot {chan host} {
global ytitle
set number [scan $ytitle(flood_prot) %\[^:\]]
set timer [scan $ytitle(flood_prot) %*\[^:\]:%s]
if {[info exists ytitle(flood:$host:$chan:act)]} {
return 1
}
foreach tmr [utimers] {
if {[string match "*youtube:remove:flood $host $chan*" [join [lindex $tmr 1]]]} {
killutimer [lindex $tmr 2]
}
}
if {![info exists ytitle(flood:$host:$chan)]} {
set ytitle(flood:$host:$chan) 0
}
incr ytitle(flood:$host:$chan)
utimer $timer [list youtube:remove:flood $host $chan]
if {$ytitle(flood:$host:$chan) > $number} {
set ytitle(flood:$host:$chan:act) 1
utimer [expr $ytitle(ignore_prot) * 60] [list youtube:expire:flood $host $chan]
return 1
} else {
return 0
}
}
###
proc youtube:remove:flood {host chan} {
global ytitle
if {[info exists ytitle(flood:$host:$chan)]} {
unset ytitle(flood:$host:$chan)
}
}
###
proc youtube:expire:flood {host chan} {
global ytitle
if {[info exists ytitle(flood:$host:$chan:act)]} {
unset ytitle(flood:$host:$chan:act)
}
}
set ytitle(projectName) "Youtube Title"
set ytitle(author) "BLaCkShaDoW"
set ytitle(website) "wWw.TCLScriptS.NeT"
set ytitle(version) "v2.0"
###
proc youtube:like_bar {like dislike chan} {
global ytitle
set like [string map {"%" ""} $like]
set dislike [string map {"%" ""} $dislike]
set setcolor [youtube:getcolor $chan]
if {$like > $dislike} {
set dif [expr ($like - $dislike)]
} else {
set dif [expr ($dislike - $like)]
}
set like_star "★"
set dislike_star "☆"
set dif [expr {double(round(1000*$dif))/1000.0}]
if {[expr {round($dif / 10)}] > 10} {
set red 10
set green [expr {10 - $red}]
} else {
set red [expr {round($dif / 10)}]
set green [expr {10 - $red}]
}
if {$like > $dislike} {
if {$red > $green} {
set temp $green
set green $red
set red $temp
}
}
if {$setcolor == "1"} {
set output \00303[string repeat [youtube:format_star $like_star] $green]\003\00304[string repeat [youtube:format_star $dislike_star] $red]\003
} else {
set output [string repeat [youtube:format_star $like_star] $green][string repeat [youtube:format_star $dislike_star] $red]
}
return $output
}
###
proc youtube:format_star {string} {
set map {}
foreach {entity number} [regexp -all -inline {&#(\d+)} $string] {
lappend map $entity [format \\u%04x [scan $number %d]]
}
set string [string map [subst -nocomm -novar $map] $string]
return $string
}
#Languages
# Romanian
set black(ytitle.ro.1) "\002\[YouTube\]\002 Titlu:\002 %msg.1%\002 | Publicat de:\002 %msg.2%\002 | Durata:\002 %msg.7%m%msg.8%s\002 | Data:\002 %msg.6%\002 | Vizionari:\002 %msg.3%\002 | Apreciere: %msg.4% - \[\002%msg.9%\002\] -"
set black(ytitle.ro.2) "\[\002You\0030,4Tube\003\002\003\] \00310Titlu:\0034 %msg.1% \003| \00310Publicat de:\0034 %msg.2% \003| \00310Durata:\0034 %msg.7%m%msg.8%s\003 | \00310Data:\0034 %msg.6% \003| \00310Vizionari:\0034 %msg.3% \003| \00310Apreciere:\003 %msg.4% - \[\00304%msg.9%\003\] -"
set black(ytitle.ro.3) "\002\[YouTube\]\002 Acest videoclip nu exista."
set black(ytitle.ro.4) "\002\[YouTube\]\002 Titlu:\002 %msg.1%\002 | Publicat de:\002 %msg.2%\002 | Durata:\002 %msg.7%m%msg.8%s\002 | Data:\002 %msg.6%\002 | Vizionari:\002 %msg.3%\002 | Apreciere: %msg.4% | Legatura: \002%msg.10%\002 - \[\002%msg.9%\002\] -"
set black(ytitle.ro.5) "\[\002You\0030,4Tube\003\002\003\] \00310Titlu:\0034 %msg.1% \003| \00310Publicat de:\0034 %msg.2% \003| \00310Durata:\0034 %msg.7%m%msg.8%s\003 | \00310Data:\0034 %msg.6% \003| \00310Vizionari:\0034 %msg.3% \003| \00310Apreciere:\003 %msg.4% | \00310Legatura: \0034%msg.10%\003 - \[\00304%msg.9%\003\] -"
# English
set black(ytitle.en.1) "\002\[YouTube\]\002 Title:\002 %msg.1%\002 | Uploaded by:\002 %msg.2%\002 | Length:\002 %msg.7%m%msg.8%s\002 | Date:\002 %msg.6%\002 | Views:\002 %msg.3%\002 | Like: %msg.4% - \[\002%msg.9%\002\] -"
set black(ytitle.en.2) "\[\002You\0030,4Tube\003\002\003\] \00310Title:\0034 %msg.1% \003| \00310Uploaded by:\0034 %msg.2% \003| \00310Length:\0034 %msg.7%m%msg.8%s\003 | \00310Date:\0034 %msg.6% \003| \00310Views:\0034 %msg.3% \003| \00310Like:\003 %msg.4% - \[\00304%msg.9%\003\] -"
set black(ytitle.en.3) "\002\[YouTube\]\002 This video does not exist."
set black(ytitle.en.4) "\002\[YouTube\]\002 Title:\002 %msg.1%\002 | Uploaded by:\002 %msg.2%\002 | Length:\002 %msg.7%m%msg.8%s\002 | Date:\002 %msg.6%\002 | Views:\002 %msg.3%\002 | Like: %msg.4% | Link:\002 %msg.10%\002- \[\002%msg.9%\002\] -"
set black(ytitle.en.5) "\[\002You\0030,4Tube\003\002\003\] \00310Title:\0034 %msg.1% \003| \00310Uploaded by:\0034 %msg.2% \003| \00310Length:\0034 %msg.7%m%msg.8%s\003 | \00310Date:\0034 %msg.6% \003| \00310Views:\0034 %msg.3% \003| \00310Like:\003 %msg.4% | \00310Link: \0034%msg.10%\003 - \[\00304%msg.9%\003\] -"
# French
set black(ytitle.fr.1) "\002\[YouTube\]\002 Titre:\002 %msg.1%\002 | Telecharge par:\002 %msg.2%\002 | Duree:\002 %msg.7%m%msg.8%s\002 La date:\002 %msg.6%\002 | Vues:\002 %msg.3%\002 | J'aime: %msg.4% - \[\002%msg.9%\002\] -"
set black(ytitle.fr.2) "\[\002You\0030,4Tube\003\002\003\] \00310Titre:\0034 %msg.1% \003| \00310Telecharge par:\0034 %msg.2% \003| \00310Duree:\0034 %msg.7%m%msg.8%s\003 | \00310La date:\0034 %msg.6% \003| \00310Vues:\0034 %msg.3% \003| \00310J'aime:\003 %msg.4% - \[\00304%msg.9%\003\] -"
set black(ytitle.fr.3) "\002\[YouTube\]\002 Cette video n'existe pas."
set black(ytitle.fr.4) "\002\[YouTube\]\002 Titre:\002 %msg.1%\002 | Telecharge par:\002 %msg.2%\002 | Duree:\002 %msg.7%m%msg.8%s\002 La date:\002 %msg.6%\002 | Vues:\002 %msg.3%\002 | J'aime: %msg.4% | Lien:\002 %msg.10%\002- \[\002%msg.9%\002\] -"
set black(ytitle.fr.5) "\[\002You\0030,4Tube\003\002\003\] \00310Titre:\0034 %msg.1% \003| \00310Telecharge par:\0034 %msg.2% \003| \00310Duree:\0034 %msg.7%m%msg.8%s\003 | \00310La date:\0034 %msg.6% \003| \00310Vues:\0034 %msg.3% \003| \00310J'aime:\003 %msg.4% | \00310Lien: \0034%msg.10%\003 - \[\00304%msg.9%\003\] -"
# Spanish
set black(ytitle.es.1) "\002\[YouTube\]\002 Titulo:\002 %msg.1%\002 | Cargado por:\002 %msg.2%\002 | Duracion:\002 %msg.7%m%msg.8%s\002 | Fecha:\002 %msg.6%\002 | Visualizaciones:\002 %msg.3%\002 | Gustos: %msg.4% - \[\002%msg.9%\002\] -"
set black(ytitle.es.2) "\[\002You\0030,4Tube\003\002\003\] \00310Titulo:\0034 %msg.1% \003| \00310Cargado por:\0034 %msg.2% \003| \00310Duracion:\0034 %msg.7%m%msg.8%s\003 | \00310Fecha:\0034 %msg.6% \003| \00310Visualizaciones:\0034 %msg.3% \003| \00310Gustos:\003 %msg.4% - \[\00304%msg.9%\003\] -"
set black(ytitle.es.3) "\002\[YouTube\]\002 Este video no existe."
set black(ytitle.es.4) "\002\[YouTube\]\002 Titulo:\002 %msg.1%\002 | Cargado por:\002 %msg.2%\002 | Duracion:\002 %msg.7%m%msg.8%s\002 | Fecha:\002 %msg.6%\002 | Visualizaciones:\002 %msg.3%\002 | Gustos: %msg.4% | Enlazar:\002 %msg.10%\002- \[\002%msg.9%\002\] -"
set black(ytitle.es.5) "\[\002You\0030,4Tube\003\002\003\] \00310Titulo:\0034 %msg.1% \003| \00310Cargado por:\0034 %msg.2% \003| \00310Duracion:\0034 %msg.7%m%msg.8%s\003 | \00310Fecha:\0034 %msg.6% \003| \00310Visualizaciones:\0034 %msg.3% \003| \00310Gustos:\003 %msg.4% | \00310Enlazar: \0034%msg.10%\003 - \[\00304%msg.9%\003\] -"
# Italian
set black(ytitle.it.1) "\002\[YouTube\]\002 Titolo:\002 %msg.1%\002 | Caricato da:\002 %msg.2%\002 | Durata:\002 %msg.7%m%msg.8%s\002 | Data:\002 %msg.6%\002 | Visualizzazioni:\002 %msg.3%\002 | Piace: %msg.4% - \[\002%msg.9%\002\] -"
set black(ytitle.it.2) "\[\002You\0030,4Tube\003\002\003\] \00310Titolo:\0034 %msg.1% \003| \00310Caricato da:\0034 %msg.2% \003| \00310Durata:\0034 %msg.7%m%msg.8%s\003 | \00310Data:\0034 %msg.6% \003| \00310Visualizzazioni:\0034 %msg.3% \003| \00310Piace:\003 %msg.4% - \[\00304%msg.9%\003\] -"
set black(ytitle.it.3) "\002\[YouTube\]\002 Questo video non esiste."
set black(ytitle.it.4) "\002\[YouTube\]\002 Titolo:\002 %msg.1%\002 | Caricato da:\002 %msg.2%\002 | Durata:\002 %msg.7%m%msg.8%s\002 | Data:\002 %msg.6%\002 | Visualizzazioni:\002 %msg.3%\002 | Piace: %msg.4% | Collegamento:\002 %msg.10%\002 - \[\002%msg.9%\002\] -"
set black(ytitle.it.5) "\[\002You\0030,4Tube\003\002\003\] \00310Titolo:\0034 %msg.1% \003| \00310Caricato da:\0034 %msg.2% \003| \00310Durata:\0034 %msg.7%m%msg.8%s\003 | \00310Data:\0034 %msg.6% \003| \00310Visualizzazioni:\0034 %msg.3% \003| \00310Piace:\003 %msg.4% | \00310Collegamento: \0034%msg.10%\003 - \[\00304%msg.9%\003\] -"
putlog "\002$ytitle(projectName) $ytitle(version)\002 coded by $ytitle(author) ($ytitle(website)): Loaded."
##############
##########################################################
## END #
##########################################################