Advertisement
Guest User

Untitled

a guest
Jun 14th, 2019
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 8.13 KB | None | 0 0
  1. namespace eval youtubetitle {
  2.  
  3. setudef flag no[namespace tail [namespace current]]
  4.  
  5. # Режим вывода информации. 1 - основная информация; 2 - плюс описание:
  6. variable rej     2
  7. # Если эти слова встретятся в заголовке, то информация выводиться не будет:
  8. variable ignor   {wordtoignore1 wordtoignore2}
  9. # Максимальная длина описания/комментария:
  10. variable limit   300
  11. # Антифлуд в секундах:
  12. variable timer   10
  13. # Этот параметр менять нельзя:
  14. variable clock   0
  15.  
  16. bind pubm - * [namespace current]::pub
  17.  
  18. if {![catch {package require tls} err]} {::http::register https 443 ::tls::socket}
  19.  
  20. proc pub {nick host hand chan text} {
  21. variable timer; variable clock; variable rej; variable ignor; variable limit
  22. if {[channel get $chan no[namespace tail [namespace current]]]} {return}
  23.  
  24. 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]
  25. ::http::config -urlencoding utf-8 -useragent "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.6.30 Version/10.62"
  26. 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}
  27. ::http::cleanup $parsing; if {![info exists data]} {return}
  28. set title ""; set length 0; set views ""; set author ""; set date ""; set desc ""; set category ""; set errormsg ""; set verifymsg ""
  29. regexp -- {<div id="watch-player-unavailable-message-container">(.*?)</div>} $data -> errormsg; if {$errormsg != ""} {::ccs::put_msgdest $chan $errormsg; return}
  30. regexp -- {<div id="verify-details">(.*?)</div>} $data -> verifymsg; if {$verifymsg != ""} {::ccs::put_msgdest $chan $verifymsg; return}
  31. regexp {<meta name="title" content="(.*?)">} $data -> title; foreach _ $ignor { if {[string match -nocase *$_* $title]} {return} }
  32. 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 }
  33. regexp {<div class="yt-user-info"><a .*?>(.*?)</a>} $data -> author; if {$author == ""} {regexp {<div class="yt-user-info"> <a .*?>(.*?)</a>} $data -> author}
  34. regexp {<strong class="watch-time-text">Опубликовано: (.*?)</strong>} $data -> date; if {$date == ""} {regexp {<strong class="watch-time-text">Дата загрузки: (.*?)</strong>} $data -> date}
  35. if {$date != ""} {set slo1 " $::gcolor(14)([webstrip $date])\017"} else {set slo1 ""}
  36. regexp {Категория </h4> <ul class="content watch-info-tag-list">(.*?)</ul>} $data -> category; if {[webstrip $category] == ""} {set category "не указана"} else {set category [string tolower [webstrip $category]]}
  37. regexp {<div class="watch-view-count">(.*?)</div>} $data -> views; if {[string match -nocase *нет* $views]} {set views 0}
  38. if {$views != ""} {set slo2 "$::gcolor(14) | $::gcolor(3)просмотров: $::gcolor(14) [webstrip [string map {" views" "" " view" "" " просмотров" "" " просмотра" "" " просмотр" "" " и более" ""} $views]]"} else {set slo2 ""}
  39. 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 "."}
  40. 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
  41. 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] ..."} } }
  42. if {[webstrip $title] != ""} {
  43. set ser "*85.173*"
  44. if {$nick == "Servo"} {return}
  45. if {$host == $ser} {return}
  46. if {[string match $ser $host]} {return}
  47. 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"
  48. #::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"
  49. if {$rej !=1 && $desc != ""} {putserv "PRIVMSG $chan $::gcolor(3)Описание: $::gcolor(14)[webstrip $desc]"}
  50. }
  51. }
  52.  
  53. proc webstrip {t} {
  54. regsub -all -nocase -- {<.*?>} $t "" t
  55. set t [string map -nocase {{&#33;} {!} {&ndash;} {-} {&amp;quot;} {"} {&mdash;} {-} {&raquo;} {»} {&laquo;} {«} {&quot;} {"} {&lt;} {<} {&gt;} {>} {&nbsp;} { } {&amp;} {&} {&copy;} {©} {&#169;} {©} {&bull;} {•} {&#183;} {-} {&sect;} {§} {&reg;} {®} &#8214; || &#38; & &#91; ( &#92; / &#93; ) &#123; ( &#125; ) &#163; Ј &#168; Ё &#169; © &#171; « &#173; ­ &#174; ® &#161; Ў &#191; ї &#180; ґ &#183; · &#185; 1 &#187; » &#188; ј &#189; Ѕ &#190; ѕ &#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; ю &#176; ° &#618; i &#716; . &#363; u &#299; i &#712; ' &#596; o &#178; 2 &#186; 0 &apos; ' } $t]
  56. set t [string map -nocase {&iexcl; \xA1 &curren; \xA4 &cent; \xA2 &pound; \xA3 &yen; \xA5 &brvbar; \xA6 &sect; \xA7 &uml; \xA8 &copy; \xA9 &ordf; \xAA &laquo; \xAB &not; \xAC &shy; \xAD &reg; \xAE &macr; \xAF &deg; \xB0 &plusmn; \xB1 &sup2; \xB2 &sup3; \xB3 &acute; \xB4 &micro; \xB5 &para; \xB6 &middot; \xB7 &cedil; \xB8 &sup1; \xB9 &ordm; \xBA &raquo; \xBB &frac14; \xBC &frac12; \xBD &frac34; \xBE &iquest; \xBF &times; \xD7 &divide; \xF7 &Agrave; \xC0 &Aacute; \xC1 &Acirc; \xC2 &Atilde; \xC3 &Auml; \xC4 &Aring; \xC5 &AElig; \xC6 &Ccedil; \xC7 &Egrave; \xC8 &Eacute; \xC9 &Ecirc; \xCA &Euml; \xCB &Igrave; \xCC &Iacute; \xCD &Icirc; \xCE &Iuml; \xCF &ETH; \xD0 &Ntilde; \xD1 &Ograve; \xD2 &Oacute; \xD3 &Ocirc; \xD4 &Otilde; \xD5 &Ouml; \xD6 &Oslash; \xD8 &Ugrave; \xD9 &Uacute; \xDA &Ucirc; \xDB &Uuml; \xDC &Yacute; \xDD &THORN; \xDE &szlig; \xDF &agrave; \xE0 &aacute; \xE1 &acirc; \xE2 &atilde; \xE3 &auml; \xE4 &aring; \xE5 &aelig; \xE6 &ccedil; \xE7 &egrave; \xE8 &eacute; \xE9 &ecirc; \xEA &euml; \xEB &igrave; \xEC &iacute; \xED &icirc; \xEE &iuml; \xEF &eth; \xF0 &ntilde; \xF1 &ograve; \xF2 &oacute; \xF3 &ocirc; \xF4 &otilde; \xF5 &ouml; \xF6 &oslash; \xF8 &ugrave; \xF9 &uacute; \xFA &ucirc; \xFB &uuml; \xFC &yacute; \xFD &thorn; \xFE &yuml; \xFF} $t]
  57. 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]
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement