Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace eval youtubetitle {
- setudef flag no[namespace tail [namespace current]]
- # Режим вывода информации. 1 - основная информация; 2 - плюс описание:
- variable rej 2
- # Если эти слова встретятся в заголовке, то информация выводиться не будет:
- variable ignor {wordtoignore1 wordtoignore2}
- # Максимальная длина описания/комментария:
- variable limit 300
- # Антифлуд в секундах:
- variable timer 10
- # Этот параметр менять нельзя:
- variable clock 0
- bind pubm - * [namespace current]::pub
- if {![catch {package require tls} err]} {::http::register https 443 ::tls::socket}
- proc pub {nick host hand chan text} {
- variable timer; variable clock; variable rej; variable ignor; variable limit
- if {[channel get $chan no[namespace tail [namespace current]]]} {return}
- set text [string trim [string map {"https://youtu.be/" "https://www.youtube.com/watch?v=" "http://youtu.be/" "https://www.youtube.com/watch?v="} [string map { {} "http://" "https://"} [stripcodes cubr $text]]]]; set url [lsearch -inline [split $text] *https://*youtube*watch*]; if {$url == ""} {return} elseif {[expr [clock seconds]-$clock] < $timer} {return}; set clock [clock seconds]
- ::http::config -urlencoding utf-8 -useragent "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.6.30 Version/10.62"
- if {[catch {set parsing [::http::geturl "$url&hl=ru" -binary true -timeout 10000]} error]} {return} elseif {[http::ncode $parsing] == "404"} {return} elseif {[http::status $parsing] == "ok"} {set data [regsub -all -- {\n|\r|\t|\v} [encoding convertfrom utf-8 [::http::data $parsing]] ""]; regsub -all -- {\s+} $data " " data}
- ::http::cleanup $parsing; if {![info exists data]} {return}
- set title ""; set length 0; set views ""; set author ""; set date ""; set desc ""; set category ""; set errormsg ""; set verifymsg ""
- regexp -- {<div id="watch-player-unavailable-message-container">(.*?)</div>} $data -> errormsg; if {$errormsg != ""} {::ccs::put_msgdest $chan $errormsg; return}
- regexp -- {<div id="verify-details">(.*?)</div>} $data -> verifymsg; if {$verifymsg != ""} {::ccs::put_msgdest $chan $verifymsg; return}
- regexp {<meta name="title" content="(.*?)">} $data -> title; foreach _ $ignor { if {[string match -nocase *$_* $title]} {return} }
- if {[regexp {<meta itemprop="duration" content="PT(\d+)M(\d+)S">} $data "" minutes seconds]} { if {[string length $minutes] == 1} {set minutes "0$minutes"}; if {[string length $seconds] == 1} {set seconds "0$seconds"}; set length $minutes:$seconds }
- regexp {<div class="yt-user-info"><a .*?>(.*?)</a>} $data -> author; if {$author == ""} {regexp {<div class="yt-user-info"> <a .*?>(.*?)</a>} $data -> author}
- regexp {<strong class="watch-time-text">Опубликовано: (.*?)</strong>} $data -> date; if {$date == ""} {regexp {<strong class="watch-time-text">Дата загрузки: (.*?)</strong>} $data -> date}
- if {$date != ""} {set slo1 " $::gcolor(14)([webstrip $date])\017"} else {set slo1 ""}
- regexp {Категория </h4> <ul class="content watch-info-tag-list">(.*?)</ul>} $data -> category; if {[webstrip $category] == ""} {set category "не указана"} else {set category [string tolower [webstrip $category]]}
- regexp {<div class="watch-view-count">(.*?)</div>} $data -> views; if {[string match -nocase *нет* $views]} {set views 0}
- if {$views != ""} {set slo2 "$::gcolor(14) | $::gcolor(3)просмотров: $::gcolor(14) [webstrip [string map {" views" "" " view" "" " просмотров" "" " просмотра" "" " просмотр" "" " и более" ""} $views]]"} else {set slo2 ""}
- if {[regexp -nocase -- {title="Мне понравилось".*?<span.*?>(.*?)</span>.*?title="Мне не понравилось".*?<span.*?>(.*?)</span>} $data -> like dislike]} { if {[string match -nocase *нет* $like]} {set like 0}; if {[string match -nocase *нет* $dislike]} {set dislike 0}; set likes " ($::gcolor(8)[webstrip $like] $::gcolor(14)понравилось, $::gcolor(4)[webstrip $dislike] $::gcolor(14)не понравилось)" } else {set likes "."}
- if {$rej != 1} { regexp {<p id="eow-description".*?>(.*?)</p>} $data -> desc; regsub -all -- {<br />} $desc " " desc; set desc [webstrip $desc]; regsub -all {(\W{4,250})} $desc " " desc
- if {[string match -nocase "*no description available*" $desc] || [string match -nocase "*нет описания*" $desc] || [string match -nocase "*описание отсутствует*" $desc]} {set desc ""} else { if {[string length $desc] >= $limit} {set desc "[string range $desc 0 $limit] ..."} } }
- if {[webstrip $title] != ""} {
- set ser "*85.173*"
- if {$nick == "Servo"} {return}
- if {$host == $ser} {return}
- if {[string match $ser $host]} {return}
- putserv "PRIVMSG $chan \002[webstrip $title]\002 $::gcolor(14)($length)$::gcolor(5) ©\017 [webstrip $::gcolor(4)$author]$slo1 | $::gcolor(3)Категория: $::gcolor(14)[webstrip $category]$slo2 $likes"
- #::ccs::put_msgdest $chan "\002[webstrip $title]\002 $::gcolor(14)($length)$::gcolor(5) ©\017 [webstrip $author]$slo1 | $::gcolor(4)Категория: [webstrip $::gcolor(5)$category]$slo2$likes"
- if {$rej !=1 && $desc != ""} {putserv "PRIVMSG $chan $::gcolor(3)Описание: $::gcolor(14)[webstrip $desc]"}
- }
- }
- proc webstrip {t} {
- regsub -all -nocase -- {<.*?>} $t "" t
- set t [string map -nocase {{!} {!} {–} {-} {&quot;} {"} {—} {-} {»} {»} {«} {«} {"} {"} {<} {<} {>} {>} { } { } {&} {&} {©} {©} {©} {©} {•} {•} {·} {-} {§} {§} {®} {®} ‖ || & & [ ( \ / ] ) { ( } ) £ Ј ¨ Ё © © « « ­ ® ® ¡ Ў ¿ ї ´ ґ · · ¹ 1 » » ¼ ј ½ Ѕ ¾ ѕ À А Á Б Â В Ã Г Ä Д Å Е Æ Ж Ç З È И É Й Ê К Ë Л Ì М Í Н Î О Ï П Ð Р Ñ С Ò Т Ó У Ô Ф Õ Х Ö Ц × Ч Ø Ш Ù Щ Ú Ъ Û Ы Ü Ь Ý Э Þ Ю ß Я à а á б â в ã г ä д å е æ ж ç з è и é й ê к ë л ì м í н î о ï п ð р ñ с ò т ó у ô ф õ х ö ц ÷ ч ø ш ù щ ú ъ û ы ü ь ý э þ ю ° ° ɪ i ˌ . ū u ī i ˈ ' ɔ o ² 2 º 0 ' ' } $t]
- set t [string map -nocase {¡ \xA1 ¤ \xA4 ¢ \xA2 £ \xA3 ¥ \xA5 ¦ \xA6 § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB ¬ \xAC ­ \xAD ® \xAE ¯ \xAF ° \xB0 ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5 ¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF × \xD7 ÷ \xF7 À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4 Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9 Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3 Ô \xD4 Õ \xD5 Ö \xD6 Ø \xD8 Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2 ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7 è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC í \xED î \xEE ï \xEF ð \xF0 ñ \xF1 ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6 ø \xF8 ù \xF9 ú \xFA û \xFB ü \xFC ý \xFD þ \xFE ÿ \xFF} $t]
- regsub -all -- {&#([0-9]{1,5});} $t "" t; regsub -all -nocase -- {&([a-z]{1,5});} $t "" t; regsub -all -- {\uFEFF} $t "" t; regsub -all -- {\<[^\>]*\>|\t} $t "" t; regsub -all {http://\S+} $t "" t; regsub -all {https://\S+} $t "" t; regsub -all {\W{10,250}} $t " " t; regsub -all {_{5,250}} $t " " t; regsub -all {\s+} $t " " t; return [string trim $t]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement