06-02-2020, 16:00 +0200
Forum: Overviewworkscript announcements
This script show (or not) title, author, description, views, rating, and last comment if exists
AuthorPost
HackeMate  04-12-2009, 12:37   | YouTube info Homepage
Member since 05/2008
6 Posts
Location: Spain
It was updated, now handles 302 redirects

Reading the header' script you can configure what it should send to channel. So you can put it in your native language too
To enable it: .chanset #channel +ourtube

                                                                                                                              
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
#
# ourTube.tcl --
# This file search the web target and show relevant information about.
# Is posible define a YouTube account and the bot will log in. Useful
# when the link are for adult people i.e. It will show the first link
# that finds in a whole phrase.
#
# Copyright (c) 2007-2009 Eggdrop Spain 12-april-2009
#   HackeMate (Sentencia) Sentencia@eggdrop.es
#
# This program is free software; you can redistribute it and/or
# modify it _only for your own use_
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Please, use the email to contact with the author for let him know about all
# what you could do. Everyone wants develop his software as well.
#
#                   Thank you for feed my empiric life.
#
# If you like, you can contact with the author to suggest him features. By the
# way, do not ask him to make Login, he is working on that.

# This is what you need to get this script work:
# Type in partyline: .chanset #channel +ourtube

# Changelog:
#   Fixes:
#       Resolved Tcl error [otPub]: can't read "views": no such variable
#       Resolved eternal ignore-protection  issue
#
#   Added features:
#       Now will forward to new location 302 http code received when pasting
#       http://youtube. links
#       Explicit message when 404 error (not found)
#       All non 200, 302, 303, 404 errors will stop the procedure showing proper reason

setudef flag ourtube
global ourtube tcl_platform

# (1) Enable or (0) disable colors
set ourtube(colors) 1

# Flood Protection: after show a link, will ignore all links few seconds
# This means 1 link per 10 seconds.
set ourtube(rest) 10

# What language you can receive the youTube data? (if works heh)
set ourtube(lang) en

# This is the final output message what you will read in your channel.
# You can configure all fields that your eggdrop will show.
# <title> will return the title of the video
# <author> It was the author himself who had uploaded the video
# <views> How many views the video has
# <rating> His rating
# <description> Information by author - This may be disabled because it can
#               contain spam
# <comment> Will show the last comment if exists - Same as description, take care
#           with spam.

set ourtube(output) "02<title>02. (by <author>) <views> views, <rating> rating. Last comment: <comment>"

# This is not required to edit, or yes.

set ourtube(author) "HackeMate"
set ourtube(contact) "HackeMate <Sentencia@eggdrop.es>"
set ourtube(fileName) [file tail [info script]]
set ourtube(projectName) "ourTube"
set ourtube(version) "1.0.1"
set ourtube(package.http) [package require http]
set ourtube(protection) ""
if {$tcl_platform(os) eq "Linux"} {
    set platfrm "X11"
} else {
    set platfrm $tcl_platform(os)
}
http::config -useragent "Mozilla/5.0 ($platfrm; U; $tcl_platform(os) $tcl_platform(machine); $ourtube(lang); rv:1.9.0.3) ourTube 1.0" -accept "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"

bind pubm - * otPub

proc otPub {nick uhost hand chan text} {

    if {![channel get $chan ourtube]} {
        return
    }
    global ourtube
    regsub -all -- {17|02|37|26|03(\d{1,2})?(,\d{1,2})?} $text "" arg

    set webTarget [lsearch -inline [split $arg] {*http://*youtube*/watch?*}]
    if {([info exists ourtube(protection)]) && ([string is digit -strict $ourtube(protection)])} {
        set rest [expr [clock seconds]-$ourtube(protection)]
        if {$rest >= $ourtube(rest)} {
            set ourtube(protection) ""
        }
    } else {
        set ourtube(protection) ""
    }
    if {$webTarget ne ""} {
        if {! [regexp -nocase {^(http://)?([^/:]+)(:([0-9]+))?(/.*)?$} $webTarget]} {
            otLog "Unsupported URL: $webTarget"
            return
        }
        if {$ourtube(protection) ne ""} {
            otLog "Resting... (flood protection) [duration [expr ([clock seconds]-$ourtube(protection))]] left"
            return
        }
        set ourtube(protection) [clock seconds]
        otLog "Getting $webTarget ... from $nick on $chan"
        set data [otGet $webTarget]
        if {!$ourtube(colors)} {
            regsub -all -- {17|02|37|26|03(\d{1,2})?(,\d{1,2})?} $data "" data
        }
        if {[string length $data] == 0} {
            set data "I was not able to reach Youtube's link. Probably I get a timeout. Try again."
        }
        otLog "$data"
        putserv "PRIVMSG $chan :$data"
        utimer $ourtube(rest) [list set ourtube(protection) ""]
    }

}

proc otGet {web {relocation ""}} {
    global ourtube
    set token [http::geturl $web -timeout 4000]
    upvar #0 $token state
    set lastcode $state(http)
    regexp {[0-9]{3}} $lastcode ncode
    if {$ncode eq ""} {
        set ncode $lastcode
    }
    switch -- $ncode {
        "200" {
        }
        "302" {
            foreach {flag value} $state(meta) {
                if {$flag eq "Location"} {
                    # Due to invalid youtube link but valid url syntax we can
                    # receive an url forward. this handles that
                    http::cleanup $token
                    otLog "$web forwards us to $value"
                    return [otGet $value "(Relocated)"]
                }
            }
        }
        "303" {
            otLog "This video does not exists."
            http::cleanup $token
            return "That video does not exists. Server responded: $lastcode"
        }
        "404" {
            otLog "$web - No such webpage."
            http::cleanup $token
            return "$web - No such webpage"
        }
        default {
            http::cleanup $token
            otLog "unforeseen circumstances. Server responded: $lastcode"
            return "unforeseen circumstances. Server responded: $lastcode"
        }
    }
    set data [string map {"&quot\;" "\"" "&amp\;quot\;" "\"" "&amp;" "&"} $state(body)]

    http::cleanup $token
    set author ""
    set description ""
    set views ""
    set rating ""
    regexp {<title>(.*?)</title>} $data "" title
    regexp {class="hLink fn n contributor">(.*?)</a><br>} $data "" author
    regexp {<meta name=\"description\" content=\"(.*?)\">.*} $data "" description
    regexp {<span id=\"watch-view-count\">(.*?)</span>} $data "" views
    regexp {<div id=\"defaultRatingMessage\">(.*?)</span>.*} $data "" rating
    # This is not so smart way. I know, sorry about :)
    set comments ""
    set description ""
    regexp {<div id="recent_comments" class="comments">(.*?)<div id="div_comment_form_id} $data "" comments
    if {$comments ne ""} {
        regexp { rel="nofollow">(.*?)</a>} $comments "" user
        regexp {<span class="watch-comment-time">(.*?)</span>} $comments "" timeago
        regexp {<div class="watch-comment-body">(.*?)</div>} $comments "" comment
        set comment [string map {\n " " "<br>" ""} $comment]
        regsub -all -- {\<[^\>]*\>|\t} $comment "" comment
        regsub -all {\s+} $comment " " comment
        set comment "\<$user [string trim $timeago]\> [string trim $comment]"
    } else {
        set comment ""
    }
    regsub -all -- {\<[^\>]*\>|\t} $title "" title
    regsub -all -- {\<[^\>]*\>|\t} $description "" description
    regsub -all -- {\<[^\>]*\>|\t} $views "" views
    regsub -all -- {\<[^\>]*\>|\t} $rating "" rating
    set rating [lindex [split $rating] 0]
    set title "$relocation $title"
    set title [string trim $title]
    if {![string is digit -strict $views]} {
        set views "no"
    }
    if {![string is digit -strict $rating]} {
        set rating "no"
    }
    if {$comment eq ""} {
        set comment "This video doesn't have any comments until now"
    }
    if {$description eq ""} {
        set description "This video doesn't have any description"
    }
    set output [string map [list "<title>" $title "<author>" $author "<description>" $description "<views>" $views "<rating>" $rating "<comment>" $comment] $ourtube(output)]
    return $output
}

# upvar #0 $token state
proc otLog {arg} {
    global ourtube
    putlog "$ourtube(projectName): $arg"
}
otLog "$ourtube(fileName) $ourtube(version) Loaded - by $ourtube(author)"


I'm the Player2
This post was edited 5 times, last on 04-23-2009, 13:42 by HackeMate
  The user has attached a file: ourTube.tcl (Save, 8,279 Bytes, downloaded 186 times)
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen | Time: 199.6 msec, CPU time: 91.6 msec, 30 Database queries in 137.4 msec | 8.4 kB (45 kB) | Timezone: +0200