View Single Post
Old 05-27-2014, 11:57 AM  
MONGi
Member
 
Join Date: May 2012
Posts: 72
Default

Hello,

first a thanks to Yil for the support

The script are extended with the function I want.

If anyone can use it:

Code:
# settings

# xferlog location
set xfs(xferlog) "../logs/xferlog"

# output file location
set xfs(outfile) "../logs/xferlog.results"

# directory containing any of those will be ignored
# Case-sensitive
set xfs(skip)[list "_requests" "_incomplete"]

# part of the directory to strip
# Not case-sensitive
set xfs(strip)[list "cd1" "cd2" "cd3" "cd4" "cd5" "cd6" "cd7" "cd8" "cd9" "disc1" "disc2" "disc3" "extra" "covers" "samples" "sample" "vobsubs" "subtitles" "subtitle" "subs" "subpack" "codec"]

# display upload stats too ?
set xfs(upstats) false

# output format (csv,html,text)
set xfs(output) "text"

# only display release name ?
set xfs(rlsn_only) false

########################################################
########################################################
########################################################

proc xferstats {} {
    global xfs

    # init
    set i 0
    set rls ""
    set users ""
    set count ""
    set datetime ""

    set ifp [open $xfs(xferlog) r]
    while {![eof $ifp]} {
        set line [gets $ifp]
        regsub {  } $line { } line
        set log [split $line { }]
        incr i

        set direction [lindex $log end-6]
        set user [lindex $log end-4]
        set date [lrange $log 3 3]
        set date [clock format [clock scan $date] -format {%Y.%m.%d - %H:%M:%S}]	
        set filen [lrange $log 8 end-9]
        set filen [string range $filen 0 [expr [string last / $filen]-1]]

        # Check for skip
        set j 0
        set skipping false
        while {$j<[llength $xfs(skip)]} {
            if {[string match "*[lindex $xfs(skip) $j]*" $filen]} {
                set skipping true
                break
            }
            incr j
        }
        if {$skipping} { continue }

        # Check for stripping
        set j 0
        while {$j<[llength $xfs(strip)]} {
            regsub -nocase "/[lindex $xfs(strip) $j]" $filen {} filen
            incr j
        }

        regsub -all -- "\\\[" $filen "<" filen
        regsub -all -- "\\\]" $filen ">" filen

        set pos [lsearch $rls "$filen $direction"]
        if {$pos==-1} {
            # Not found - add it
            set rls [linsert $rls end "$filen $direction"]
            set users [linsert $users end "$user"]
            set count [linsert $count end 1]
            set datetime [linsert $datetime end "$date"]		
        } else {
            set users_test [lindex $users $pos]
            if {![string match "*$user*" $users_test]} {
                set users [lreplace $users $pos $pos "$users_test $user"]
                set count [lreplace $count $pos $pos "[expr [lindex $count $pos]+1]"]
            }
        }

        set size [lindex $log 7]

        if {$i%1000==0} {
            iputs -nobuffer "[llength $rls]"
        }
    }
    close $ifp

    iputs -nobuffer "[llength $rls] releases found (upload and download)"

    set i 0
    set ofp [open $xfs(outfile) w]	
    if {$xfs(output) == "html"} {
        puts $ofp "<table>"
    }
    while {$i<[llength $rls]} {
        set rlsn [lindex $rls $i]
        regsub -all -- "<" [lindex $rls $i] "\[" rlsn
        regsub -all -- ">" $rlsn "\]" rlsn
        regsub -all -- "\[{}\]" $rlsn "" rlsn
        set arr [split $rlsn]
        set rlsn [lindex $arr 0]
        if {$xfs(rlsn_only)} {
            set rlsn [string range $rlsn [expr [string last / $rlsn]+1] end]
        }
        set direction [lindex $arr 1]
        if {$rlsn!=""} {
            if {$xfs(output) == "text"} {
                if {$direction=="o"} {
                    puts $ofp "[lindex $datetime $i]  |  User: [lindex $users $i]  |  Count: [lindex $count $i]  |  Release: $rlsn"
                } elseif {$xfs(upstats)} {
                    puts $ofp "[lindex $datetime $i]  |  User: [lindex $users $i]  |  Count: [lindex $count $i] | Release: $rlsn"
                }
            } elseif {$xfs(output) == "csv"} {
                if {$direction=="o" && $xfs(upstats)} {
                    puts $ofp "download,$rlsn,[lindex $count $i],[lindex $users $i]"
                } elseif {$direction=="o"} {
                    puts $ofp "$rlsn,[lindex $count $i],[lindex $users $i]"
                } elseif {$xfs(upstats)} {
                    puts $ofp "upload,$rlsn,[lindex $count $i],[lindex $users $i]"
                }
            } elseif {$xfs(output) == "html"} {
                if {$direction=="o" && $xfs(upstats)} {
                    puts $ofp "<tr><td>$rlsn</td><td>download</td><td>[lindex $count $i]</td><td>[lindex $users $i]</td></tr>"
                } elseif {$direction=="o"} {
                    puts $ofp "<tr><td>$rlsn</td><td>[lindex $count $i]</td><td>[lindex $users $i]</td></tr>"
                } elseif {$xfs(upstats)} {
                    puts $ofp "<tr><td>$rlsn</td><td>upload</td><td>[lindex $count $i]</td><td>[lindex $users $i]</td></tr>"
                }
            }
        }
        incr i
    }
    if {$xfs(output) == "html"} {
        puts $ofp "</table>"
    }
    close $ofp

    global ioerror
    set ioerror 0
}

iputs -nobuffer "XFERStats started..."
xferstats

Last edited by MONGi; 06-16-2014 at 09:53 AM.
MONGi is offline