Guest User

Updated NiNJALiB.tcl

a guest
Oct 7th, 2010
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 72.27 KB | None | 0 0
  1. namespace eval ::ioNiNJA {
  2.     variable logPath "../logs"
  3.     namespace export *
  4. }
  5.  
  6. interp alias {} IsTrue {} string is true -strict
  7. interp alias {} IsFalse {} string is false -strict
  8.  
  9.  
  10.  
  11.  
  12.  
  13. if {[catch {source "../scripts/ioNiNJA/ioNiNJA.cfg"} error]} {
  14.     putlog -error $error
  15.     return
  16. }
  17.  
  18. if {[catch {source "../scripts/ioNiNJA/themes/$ioNJ(themefile)"} error]} {
  19.     putlog -error $error
  20.     return
  21. }
  22.    
  23. if {[catch {package require http 2.7.1} error]} {
  24.     putlog -error $error
  25.     return
  26. }
  27.  
  28. proc ::ioNiNJA::sfv_check {sfvfile} {global pwd ioNJ path
  29. set sfvdata [split [string tolower  [readfile $sfvfile]] \n]
  30. set newsfv ""
  31. set m3u ""
  32.  
  33.  
  34. foreach line $sfvdata {
  35.     if {[string index $line 0] != ";"} {
  36.         if {[string length [lindex $line end]] == 8 && [llength $line] >= 2} {
  37.                  if {[lsearch -glob $newsfv "[lindex $line 0] *"] == "-1"} {
  38.               lappend newsfv $line
  39.                 if {$ioNJ(create_missing_files)} {
  40.                     if {![regexp -nocase {\.mu3$|\.nfo$} [string trim [lrange $line 0 end-1]]]} {
  41.                         catch {set missingfile [open $path/[lrange $line 0 end-1]${ioNJ(missingtag)} w]} error
  42.                         catch {close $missingfile}
  43.                     }
  44.                 }
  45.             }
  46.             }
  47.         }
  48. }
  49.  
  50. set mp3s [lsearch -regexp -all -inline $newsfv {[^;](.+?\.mp3) ([0-9a-z]){8}}]
  51.  
  52. #
  53. if {$ioNJ(create_m3u) && $mp3s != ""} {
  54.     foreach mp $mp3s {
  55.         append m3u "[lrange $mp 0 end-1]\n"
  56.     }
  57.     set m3uname "[file tail [file rootname $sfvfile]].m3u"
  58.     writefile "$path/$m3uname" $m3u
  59. }
  60.  
  61.  
  62. #write new sfv file without comments
  63. if {$ioNJ(sfv_cleanup)} {
  64.     writefile "$sfvfile" "[join $newsfv "\n"]"
  65. }
  66.  
  67. #Type of release
  68. if {$mp3s != ""} {
  69.     writechattr 12  "AUDIO"
  70. } elseif {[regexp -nocase {\.r[a0-9][r0-9]|\.0[0-9][0-9]} $newsfv]} {
  71.     writechattr 12  "RAR"
  72. } elseif {[regexp -nocase $ioNJ(samples) $newsfv]} {
  73.     writechattr 12  "VIDEO"
  74. } else {
  75.     writechattr 12 "OTHER"
  76. }
  77.  
  78. symlink_proc cd 1 ; symlink_proc sfv 0
  79.  
  80. writechattr 35 $newsfv
  81.  
  82. writechattr 13 [llength $newsfv]
  83. return
  84. }
  85.  
  86.  
  87.  
  88. proc ::ioNiNJA::clean_nfo {nfofile} {
  89.     set nfo [readfile $nfofile]
  90.     set tempnfo ""
  91.     regsub -all "\r\n\r\n" $nfo "\r\n" nfo
  92.     foreach line [split $nfo \n] {
  93.         lappend tempnfo "[string trimright $line]"
  94.     }
  95.    
  96.     set temp [writefile $nfofile [join $tempnfo \n]]
  97.     unset nfo
  98.     unset tempnfo
  99.         return
  100. }
  101.  
  102.  
  103.  
  104.  
  105. ########################
  106. # Symlink Proc
  107. ########################
  108.  
  109.  
  110. proc ::ioNiNJA::symlink_update {source} { global ioNJ pwd path
  111.  
  112.         set symtype 1
  113.        
  114.         foreach link [readchattr 240] {
  115.        
  116.             if {![file exists $link]} { continue }
  117.            
  118.             catch {vfs chattr "$link" 1} vfsdir
  119.                    
  120.             iputs -nobuffer "Checking: $link"
  121.                    
  122.             if {$vfsdir != ""} {
  123.                 set symtype 0
  124.                 } elseif {![catch {file link $link} templink]} {
  125.                 set symtype 1
  126.                 }
  127.                
  128.  
  129.             if {$symtype} {
  130.                   catch {file delete -force -- $link}
  131.                   catch {file mkdir "[file dirname $link]"}
  132.                   catch {file link -symbolic "$link" "$source"} error
  133.             } else {
  134.                 catch {file delete -force -- $link}
  135.                 catch {file mkdir "$link"}
  136.                 catch {vfs chattr "$link" 1 "$pwd"}
  137.                 catch {vfs flush "$link"}
  138.                 }
  139.        
  140.         }
  141.        
  142.     return
  143. }
  144.  
  145.  
  146. proc ::ioNiNJA::symlink_clean {} {global ioNJ
  147.  
  148.   foreach cleandir [split [string trim $ioNJ(cleanup_dirs)] \n] {
  149.     set dirs [resolve pwd $cleandir]
  150.     set nr 0
  151.    
  152.     while {[lindex $dirs $nr] != ""} {
  153.             if {[catch {file link [lindex $dirs $nr]} templink]} {
  154.            foreach dir [glob -nocomplain -type d -directory [lindex $dirs $nr] "*"] {
  155.             lappend dirs $dir
  156.            }
  157.             }
  158.             iputs -nobuffer "buffering: [file tail [lindex $dirs $nr]]"
  159.             incr nr
  160.             after 10
  161.     }
  162.  
  163.     foreach dir $dirs {
  164.         set delete 0
  165.         if {$dir == "" || ( ![file exists $dir] )} { continue }
  166.        
  167.         catch {vfs chattr "$dir" 1} vfsdir
  168.        
  169.         iputs -nobuffer "checking: [file tail $dir]"
  170.        
  171.         if {$vfsdir != ""} {
  172.             if {![file exists [resolve pwd $vfsdir]]} {
  173.                 set delete 1            }
  174.        
  175.            } elseif {![catch {file link $dir} templink]} {
  176.                 if {![file exists $templink]} {
  177.                     set delete 1
  178.                 }
  179.            }
  180.            
  181.            
  182.            if {$delete} {
  183.                 catch {file delete -force -- $dir} error
  184.                 set dir [file dirname $dir]
  185.                 while {[glob -nocomplain -directory $dir "*"] == ""} {
  186.                     catch {file delete -force -- $dir} error
  187.                     set dir [file dirname $dir]
  188.                 }
  189.            }
  190.       }
  191.  
  192.     }
  193.   unset -nocomplain dirs
  194. }
  195.  
  196.  
  197.  
  198. #######################
  199. ## Get Stats
  200. #######################
  201.  
  202.  
  203. proc ::ioNiNJA::get_stats {} {global pwd path uid gid
  204.  set wkup "" ; set mnup "" ; set allup "" ; set dayup ""
  205.  
  206. foreach uname [user list] {
  207.  set user1 [resolve uid $uname]
  208.     if {![userfile open $user1]} {
  209.         if {![catch {set uf [userfile bin2ascii]}]} {
  210.             regexp -nocase {wkup (.+?)\n} $uf -> userwkup
  211.             lappend wkup "$user1 [Calculate_Stats $userwkup]"
  212.  
  213.             regexp -nocase {monthup (.+?)\n} $uf -> usermnup
  214.             lappend mnup "$user1 [Calculate_Stats $usermnup]"
  215.  
  216.             regexp -nocase {allup (.+?)\n} $uf -> userallup
  217.             lappend allup "$user1  [Calculate_Stats $userallup]"
  218.  
  219.             regexp -nocase {dayup (.+?)\n} $uf -> userdayup
  220.             lappend dayup "$user1 [Calculate_Stats $userdayup]"
  221.         }
  222.      }
  223. }
  224.  
  225. if {![userfile open [resolve uid $uid]]} {
  226.         if {![catch {set uf [userfile bin2ascii]}]} {
  227.         }
  228. }
  229.  
  230. set wkup [lsort -decreasing -integer -index end "$wkup"]
  231. set mnup [lsort -decreasing -integer -index end "$mnup"]
  232. set allup [lsort -decreasing -integer -index end "$allup"]
  233. set dayup [lsort -decreasing -integer -index end "$dayup"]
  234. return [list $dayup $wkup $mnup $allup]
  235. }
  236.  
  237.  
  238. proc ::ioNiNJA::Calculate_Stats {tempstats} {
  239. set totalsize 0
  240. foreach {files size speed} $tempstats {
  241.       if {$size == 0} { continue }
  242.       set totalsize [format %.0f [expr $totalsize + ($size /1024.0)]]
  243. }
  244. return $totalsize
  245.  
  246. }
  247.  
  248.  
  249.  
  250. #######################
  251. ## DELETE DIR
  252. #######################
  253.  
  254.  
  255. proc ::ioNiNJA::delete_dir {delpwd delpath} {global ioNJ pwd path
  256. symlink_proc cd 0
  257. symlink_proc sfv 0
  258. symlink_proc nfo 0
  259.  
  260. vfs write $delpath 0 0 744
  261. vfs flush $delpath
  262. set error 0
  263. set counter 0
  264.     while {$error != "" && ( $counter != 50) } {
  265.         catch {set temp [client kill virtualpath "$delpwd/*"]} temp
  266.         catch {file delete -force -- "$delpath"} error
  267.         incr counter
  268.         after 200
  269.     }
  270. return $error
  271. }
  272.  
  273.  
  274. proc ::ioNiNJA::get_mp3_information {mp3file} {global ioNJ args pwd path uid gid
  275.  
  276.     if {![file exists $mp3file]} { return }
  277.    
  278.     set mp3 [readchattr 25]
  279.    
  280.     set dir [lindex [file split $pwd] end]
  281.    
  282.     if {[regexp -nocase  $ioNJ(notparent) $dir]} {
  283.         set subdir 1
  284.         set dir [lindex [file split $pwd] end-1]
  285.     }
  286.    
  287.     if {![info exists uid]} {
  288.         set uid 0
  289.         set gid 0
  290.     }
  291.  
  292.     set user [resolve uid $uid]
  293.     set ugroup [resolve gid $gid]
  294.     set fname [file tail $mp3file]
  295.     set lame "NA"
  296.     set lpreset "NA"
  297.     set vbroldnew "NA"
  298.     set fd [open $mp3file r]
  299.     fconfigure $fd  -encoding binary -translation binary -buffering full -buffersize 1000000
  300.     set idx 1
  301.     set offset 0
  302.     set mp3header [read $fd 10]
  303.     seek $fd -128 end
  304.     set id3v1 [read $fd]
  305.     seek $fd 0
  306.  
  307.     #GET THE iD3 TAG
  308.     binary scan $id3v1 A3 id
  309.     if {[string equal $id TAG]} {
  310.              set genre 149
  311.              binary scan $id3v1 A3A30A30A30A4A28ccc id title artist album  year comment zero track genre
  312.              if {$genre == "-1"} {
  313.                     set genre "Unknown"
  314.              } elseif {$genre < 0 } {
  315.                     set genre [expr $genre + 256]
  316.                 set genre [lindex $ioNJ(genres) $genre]
  317.              } else {
  318.                 set genre [lindex $ioNJ(genres) $genre]
  319.              }
  320.              if {$genre == ""} { set genre Unknown }
  321.     } else {
  322.         set title "Unknown" ; set artist "Unknown" ; set album "Unknown" ; set year "0000" ; set comment "Unknown" ; set zero 0 ; set track 0 ; set genre "Unknown"
  323.     }
  324.  
  325.  
  326.  
  327.     #Get THE iD3v2 TAG
  328.     binary scan $mp3header A3B8B8B8B32 tempid3 tempversion tempsubversion flags size
  329.     if {[string match -nocase "id3" $tempid3]} {
  330.         binary scan $mp3header A3B8B8B8B32 tempid3 tempversion tempsubversion flags size
  331.         set id3v2 [bin2dec $tempversion]
  332.         if {[string index $flags 4] != 0} {
  333.             set offset [expr [bin2dec [string range $size 1 7][string range $size 9 15][string range $size 17 23][string range $size 25 31]]+20]
  334.         } else {
  335.             set offset [expr [bin2dec [string range $size 1 7][string range $size 9 15][string range $size 17 23][string range $size 25 31]]+10]
  336.         }
  337.         seek $fd 10
  338.         set id3v2tag [read $fd $offset]
  339.         if {$id3v2 >= "1"} {
  340.              set num 0
  341.              if { $id3v2 >= "3" } {
  342.                 set bscan A4B32
  343.                 set offset2 10
  344.                 set offset3 11
  345.              } elseif {$id3v2 == "2"} {
  346.                 set bscan A3B24
  347.                 set offset2 6
  348.                 set offset3 7
  349.              }
  350.              while {$id3v2tag != ""} {
  351.                     binary scan $id3v2tag $bscan ID size   
  352.                     set tempcrap [expr [bin2dec [string range $size 1 7][string range $size 9 15][string range $size 17 23][string range $size 25 31]]+$offset2]
  353.                     if {$tempcrap == $offset2} { break }
  354.                     set data [string range $id3v2tag $offset3 [expr $tempcrap-1]]
  355.                     set data [string trim [regsub -all -- {[^[:graph:] ]|ÿ|þ} $data {}]]
  356.                     switch -- $ID {
  357.                         TRCK { if {$track == ""} { set track [lindex [split $data /] 0] } }
  358.                             COMM  { set comm [string range $data 4 end] }
  359.                             TIT2  { set title $data }
  360.                             TPE1  { set artist $data }
  361.                             TALB  { set album $data }
  362.                             MCDI  { set id3v2tag [string range $id3v2tag [expr 814 - $tempcrap] end] }
  363.                             TYER  { if {$year == "0000" && [string is integer -strict $data] || ([string length $year] == 4)} { set year $data } }
  364.                             TCON  {
  365.                                 if {$genre == "Unknown"} { if {[regexp -nocase {\(([0-9]+)\)} $data -> genrenr]} { set genre [lindex $ioNJ(genres) $genrenr] } elseif {$data != ""} { set genre "$data" } }
  366.                             }
  367.                             TT2  { set title $data }
  368.                         TOA  { set artist $data }
  369.                         TP1  { set artist $data }
  370.                         TRK  { if {$track == ""} { set track [lindex [split $data /] 0] } }
  371.                         CM1  { set comm [string range $data 4 end] }
  372.                         TAL  { set album $data }
  373.                             TYE  { if {$year == "0000" && [string is integer -strict $data] || ([string length $year] == 4)} { set year $data } }
  374.                             TCO  {
  375.                                if {$genre == "Unknown"} { if {[regexp -nocase {\(([0-9]+)\)} $data -> genrenr]} { set genre [lindex $ioNJ(genres) $genrenr] } elseif {$data != ""} { set genre "$data" } }
  376.                             }
  377.                     }
  378.                     set id3v2tag [string range $id3v2tag $tempcrap end]
  379.                     incr num
  380.    
  381.             }
  382.         }
  383.  
  384.     }  
  385.  
  386.     if {$year == "" || [string length $year] != 4} {
  387.         if {![regexp -nocase {([0-9]{4})} $dir -> year]} {
  388.             set year "0000"
  389.         }  
  390.     }
  391.  
  392.  
  393.     if {$title == ""} { set title "Unknown" }
  394.     if {$album == ""} { set album "Unknown" }
  395.     if {$artist == ""} { set artist "Unknown" }
  396.  
  397.     if {$ioNJ(strip_the)} { regsub -nocase {^the } $artist {} artist }
  398.    
  399.     regexp -nocase {(.+?) (feat|ft)} $artist -> artist crap
  400.    
  401.     set artist [string trim $artist]
  402.  
  403.     seek $fd $offset
  404.     while { ![eof $fd] } {
  405.       set head1  [read $fd 1]
  406.        scan $head1 %c byte1
  407.          if { ($byte1 & 0xFF) == 0xFF } {
  408.           set head2 [read $fd 1]
  409.            scan $head2 %c byte2
  410.             if { ($byte2 & 0xE0) == 0xE0 } {
  411.          set head3 [read $fd 2]
  412.               scan $head3 %c%c byte3 byte4
  413.                 if { ([expr {($byte2 >> 3) & 0x3}] != 0x1) && ([expr {($byte2 >> 1) & 0x3}] != 0x0) && ((($byte3 >> 2) & 0x3) != 0x3) && ((($byte3 >> 4) & 0xF)  != 0xf)} {
  414.             set mpeghead "$head1$head2$head3"
  415.             break
  416.                }
  417.             }
  418.         }
  419.     }
  420.     if {![info exists mpeghead]} { close $fd ; putlog -error "$mp3file does not contain a mpeghead" ; return }
  421.     binary scan $mpeghead B32 mp3head
  422.     set Framesync [string range $mp3head 0 10]
  423.     set MPEGAudioversion [string range $mp3head 11 12]
  424.     set Layerdescription [string range $mp3head 13 14]
  425.     set Protection [string index $mp3head 15]
  426.     set Bitrate [string range $mp3head 16 19]
  427.     set Samplingrate [string range $mp3head 20 21]
  428.     set Padding [string index $mp3head 22]
  429.     set Private  [string index $mp3head 23]
  430.     set Chanmode  [string range $mp3head 24 25]
  431.     set Modeextension [string range $mp3head 26 27]
  432.     set Copyright [string index $mp3head 28]
  433.     set Original [string index $mp3head 29]
  434.     set Emphasis [string range $mp3head 30 31]
  435.    
  436.     switch -exact -- $MPEGAudioversion {
  437.         11 {set mpeg "1" ; set srateidx 0 }
  438.         10 {set mpeg "2" ; set srateidx 1 }
  439.         00 {set mpeg "2.5" ; set srateidx 2 }
  440.         01 {set mpeg "0" ; set srateidx 4 }
  441.     }
  442.  
  443.     switch -exact -- $Layerdescription {
  444.         00 {set layer "0"}
  445.         01 {set layer "3"}
  446.         10 {set layer "2"}
  447.         11 {set layer "1"}
  448.     }
  449.  
  450.     switch -exact -- $Protection {
  451.         0 {set protection "Yes"}
  452.         1 {set protection "No"}
  453.     }
  454.  
  455.     switch -exact -- $mpeg.$layer {
  456.      1.1 { set bridx 0 }
  457.      1.2 { set bridx 1 }
  458.      1.3 { set bridx 2 }
  459.      2.1 { set bridx 3 }
  460.      2.2 { set bridx 4 }
  461.      2.3 { set bridx 4 }
  462.     }
  463.  
  464.  
  465.     set ioNJ(br.0000) {free free free free free }
  466.     set ioNJ(br.0001) {32 32 32 32 8}
  467.     set ioNJ(br.0010) {64 48 40 48 16}
  468.     set ioNJ(br.0011) {96 56 48 56 24}
  469.     set ioNJ(br.0100) {128 64 56 64 32}
  470.     set ioNJ(br.0101) {160 80 64 80 40}
  471.     set ioNJ(br.0110) {192 96 80 96 48}
  472.     set ioNJ(br.0111) {224 112 96 112 56}
  473.     set ioNJ(br.1000) {256 128 112 128 64}
  474.     set ioNJ(br.1001) {288 160 128 144 80}
  475.     set ioNJ(br.1010) {320 192 160 160 96}
  476.     set ioNJ(br.1011) {352 224 192 176 112}
  477.     set ioNJ(br.1100) {384 256 224 192 128}
  478.     set ioNJ(br.1101) {416 320 256 224 144}
  479.     set ioNJ(br.1110) {448 384 320 256 160}
  480.     set ioNJ(br.1111) {bad bad bad bad bad}
  481.    
  482.     if {![info exists bridx]} { return }
  483.  
  484.     set bitrate "[lindex $ioNJ(br.$Bitrate) $bridx]"
  485.  
  486.     switch -exact -- $Samplingrate {
  487.         00 {set srate {"44100" "22050" "11025"}}
  488.         01 {set srate {"48000" "24000" "12000"}}
  489.         10 {set srate {"32000" "16000" "8000"}}
  490.         11 {set srate {Unknown Unknown Unknown}}
  491.     }
  492.     set srate [lindex $srate $srateidx]
  493.  
  494.     switch -exact -- $Chanmode {
  495.         00 {set channelmode Stereo}
  496.         01 {set channelmode "Joint Stereo"}
  497.         10 {set channelmode "Dual channel"}
  498.         11 {set channelmode  Mono}
  499.     }
  500.  
  501.  
  502.     if {![info exists mpeg]} { putlog -error "$mp3file dmpeg not found in file" ; return }
  503.     if {$layer > 3} { putlog -error "$mp3file reports mpeglayer $layer" ; return}
  504.    
  505.  
  506.             set vbr   0
  507.         if {$mpeg >= 2} {
  508.             if {$channelmode == "Mono"} { set lamestart "13" } else { set lamestart "21" }
  509.         } elseif {$mpeg == 1} {
  510.             if {$channelmode == "Mono"} { set lamestart "21" } else { set lamestart "36" }
  511.         }
  512.  
  513.           seek $fd [expr $offset + $lamestart]
  514.    
  515.           if { [read $fd 4] == "Xing" } {
  516.             set vbr 1
  517.             set xingFrames 0
  518.             set xingBytes  0
  519.         if {[binary scan [read $fd 4] I xingHeadFlags] != 1} {
  520.             break  
  521.         }
  522.         if {[binary scan [read $fd 4] I xingFrames] != 1} {
  523.             break
  524.         }
  525.         if {[binary scan [read $fd 4] I xingBytes] != 1} {
  526.             break
  527.         }
  528.             if { ($xingFrames > 0) && ($xingBytes  > 0) && ($xingHeadFlags > 3) } {
  529.               set bitrate [expr {(($xingBytes / $xingFrames) * $srate) / ($mpeg == 1 ? 144000 : 72000)}]
  530.             }
  531.           }
  532.          
  533.     if {$vbr} {
  534.    
  535.         #find out if it's old or new vbr
  536.             seek $fd [expr $offset + 165]
  537.             set vbrver [read $fd 1]
  538.             set vbrver  [scan $vbrver %c]
  539.             switch -- $vbrver  {
  540.             2 {set vbroldnew "ABR"}     ; #abr
  541.                 3 {set vbroldnew "VBR-OLD"} ; #vbr old / vbr rh
  542.                 4 {set vbroldnew "VBR-NEW"} ; #VBR-MTRH
  543.                     5 {set vbroldnew "VBR-NEW"} ; #VBR-MT
  544.             }
  545.        
  546.        
  547.             seek $fd [expr $offset + 155]
  548.         set vbrquality [read $fd 1] ; # vbr quality setting
  549.         set vbrquality [scan $vbrquality %c]
  550.            
  551.         seek $fd [expr $offset + 156]
  552.         set lametemp [read $fd 10]
  553.         binary scan $lametemp A9B8 Lame subrev
  554.         set subver [bin2dec [string range $subrev 0 3]]
  555.         set revision [bin2dec [string range $subrev 4 7]]
  556.         set lame [string trim [string range $lametemp 0 8]]
  557.         set sublame [scan [string index $lametemp 9] %c]
  558.         seek $fd [expr $offset + 182]
  559.         set preset [read $fd 2]
  560.         binary scan $preset B16 temp
  561.         set lamepreset [bin2dec $temp]
  562.    
  563.         if {[string index $lame end] == "."} {
  564.                 set lame "$lame$revision"
  565.         }
  566.    
  567.     switch -- $lamepreset {
  568.         1000 {set lpreset "APR"}
  569.             1001 {set lpreset "APS"}
  570.             1002 {set lpreset "APE"}
  571.             1003 {set lpreset "API"}
  572.             1004 {set lpreset "FAPS"}
  573.             1005 {set lpreset "FAPE"}
  574.             1006 {set lpreset "APM"}
  575.             1007 {set lpreset "FAPM"}
  576.         320  {set lpreset "INSANE"}
  577.             410  {set lpreset "V9"}
  578.             420  {set lpreset "V8"}
  579.             430  {set lpreset "V7"}
  580.             440  {set lpreset "V6"}
  581.             450  {set lpreset "V5"}
  582.             460  {set lpreset "V4"}
  583.             470  {set lpreset "V3"}
  584.             480  {set lpreset "V2"}
  585.             490  {set lpreset "V1"}
  586.             500  {set lpreset "V0"}
  587.          }
  588.     }
  589.     if {$Bitrate != 0000} {
  590.         set duration [expr {int([file size $mp3file]*8 / double(1000*$bitrate))}]
  591.     } else {
  592.         set duration 0
  593.     }
  594.     close $fd
  595.    
  596.     if {$Original == 0} { set mp3original NO } else {  set mp3original Yes }
  597.     if {$Padding == 0} { set mp3padding NO } else {  set mp3padding Yes }
  598.     if {$vbr == 0} { set mp3vbr CBR } else { set mp3vbr VBR }
  599.    
  600.    
  601.    
  602.     set mp3info [list $artist $album $title $bitrate $mpeg $layer $channelmode $genre $year $srate $lame $lpreset $mp3original $mp3padding $duration $track $mp3vbr $vbroldnew]
  603.     regsub -all {[^[:graph:] ]} $mp3info {} mp3info
  604.     writechattr 25 $mp3info
  605.  
  606.        if {$mp3 == ""} {
  607.    
  608.         if {[regexp $ioNJ(mp3_path_check) $pwd] && $ioNJ(mp3_path_check) != "" } {
  609.  
  610.             #mp3 ban report or del
  611.             if {$ioNJ(audio_year_check) && ![regexp $ioNJ(allowed_years) $year]} {
  612.                 if {[string match $ioNJ(del_banned_release_path) $pwd] && $ioNJ(del_banned_release_path) != ""} {
  613.                     output "$ioNJ(zipscript_header)$ioNJ(zipscript_mp3_del_year)$ioNJ(zipscript_footer_skip)"
  614.                     delete_dir "$pwd" "$path"
  615.                     return
  616.                 }
  617.                 if {$ioNJ(audio_year_warn)} {
  618.                     put_log "BADYEAR: [list $pwd $dir $user $ugroup $fname $year]" 
  619.                 }  
  620.             }
  621.  
  622.             #check year and take action
  623.             if {$ioNJ(audio_genre_check) == 1 && ![regexp -nocase $ioNJ(allowed_genres) $genre] && $ioNJ(allowed_genres) != ""} {
  624.                 if {[regexp -nocase $ioNJ(del_banned_release_path) $pwd] && $ioNJ(del_banned_release_path) != ""} {
  625.                     output "$ioNJ(zipscript_header)$ioNJ(zipscript_mp3_alo_genre)$ioNJ(zipscript_footer_skip)"
  626.                     delete_dir "$pwd" "$path"
  627.                     return
  628.                 }
  629.                 if {$ioNJ(audio_genre_warn)} {
  630.                     put_log "BADGENRE: [list $pwd $dir $user $ugroup $fname $genre]"   
  631.                 }
  632.             } elseif {$ioNJ(audio_genre_check) == 2 && [regexp -nocase $ioNJ(banned_genres) $genre] && $ioNJ(banned_genres) != ""} {
  633.                 if {$ioNJ(del_banned_release_path) != "" && [regexp -nocase $ioNJ(del_banned_release_path) $pwd]} {
  634.                     output "$ioNJ(zipscript_header)$ioNJ(zipscript_mp3_ban_genre)$ioNJ(zipscript_footer_skip)"
  635.                     delete_dir "$pwd" "$path"
  636.                     return
  637.                 }
  638.                 if {$ioNJ(audio_genre_warn)} {
  639.                     put_log "BADGENRE: [list $pwd $dir $user $ugroup $fname $genre]"   
  640.                 }
  641.             }
  642.         }
  643.         }
  644.    
  645.     return
  646. }
  647.  
  648.  
  649.  
  650. #######################
  651. ## Mp3 Genres
  652. #######################
  653.  
  654.  
  655. set ioNJ(genres) {
  656. "Blues" "Classic Rock" "Country" "Dance"
  657. "Disco" "Funk" "Grunge" "Hip-Hop"
  658. "Jazz" "Metal" "New Age" "Oldies"
  659. "Other" "Pop" "R&B" "Rap"
  660. "Reggae" "Rock" "Techno" "Industrial"
  661. "Alternative" "Ska" "Death Metal" "Pranks"
  662. "Soundtrack" "Euro-Techno" "Ambient" "Trip-Hop"
  663. "Vocal" "Jazz+Funk" "Fusion" "Trance"
  664. "Classical" "Instrumental" "Acid" "House"
  665. "Game" "Sound Clip" "Gospel" "Noise"
  666. "Alt. Rock" "Bass" "Soul" "Punk"
  667. "Space" "Meditative" "Instrumental Pop" "Instrumental Rock"
  668. "Ethnic" "Gothic" "Darkwave" "Techno-Industrial"
  669. "Electronic" "Pop-Folk" "Eurodance" "Dream"
  670. "Southern Rock" "Comedy" "Cult" "Gangsta Rap"
  671. "Top 40" "Christian Rap" "Pop Funk" "Jungle"
  672. "Native American" "Cabaret" "New Wave" "Psychedelic"
  673. "Rave" "Showtunes" "Trailer" "Lo-Fi"
  674. "Tribal" "Acid Punk" "Acid Jazz" "Polka"
  675. "Retro" "Musical" "Rock & Roll" "Hard Rock"
  676. "Folk" "Folk Rock" "National Folk" "Swing"
  677. "Fast-Fusion" "Bebob" "Latin" "Revival"
  678. "Celtic" "Bluegrass" "Avantgarde" "Gothic Rock"
  679. "Progressive Rock" "Psychedelic Rock" "Symphonic Rock" "Slow Rock"
  680. "Big Band" "Chorus" "Easy Listening" "Acoustic"
  681. "Humour" "Speech" "Chanson" "Opera"
  682. "Chamber Music" "Sonata" "Symphony" "Booty Bass"
  683. "Primus" "Porn Groove" "Satire" "Slow Jam"
  684. "Club" "Tango" "Samba" "Folklore"
  685. "Ballad" "Power Ballad" "Rhythmic Soul" "Freestyle"
  686. "Duet" "Punk Rock" "Drum Solo" "A Cappella"
  687. "Euro-House" "Dance Hall" "Goa" "Drum & Bass"
  688. "Club-House" "Hardcore" "Terror" "Indie"
  689. "BritPop" "Negerpunk" "Polsk Punk" "Beat"
  690. "Christian Gangsta Rap" "Heavy Metal" "Black Metal" "Crossover"
  691. "Contemporary Christian" "Christian Rock" "Merengue" "Salsa"
  692. "Thrash Metal" "Anime" "JPop" "Synthpop"
  693. "Unknown"
  694. }
  695.  
  696. #######################
  697. ## Binary To Decimal
  698. #######################
  699.  
  700. proc ::ioNiNJA::bin2dec {binary} {
  701.     set decimal 0
  702.     for {set i 0} {$i < [string length $binary]} {incr i} {
  703.         set next [string index $binary end-$i]
  704.         set decimal [expr ($next << $i) | $decimal]
  705.     }
  706.     return $decimal
  707. }
  708.  
  709. #######################
  710. ### Get Total Files From zipfile and extract nfo
  711. #######################
  712. proc ::ioNiNJA::get_zip_info {zipfile} {global path pwd
  713.     if {![file exists $path/file_id.diz] || [file size "$path/file_id.diz"] == 0} {
  714.         catch {set inzip [exec ../scripts/ioNiNJA/MiSC/UNZIP32.exe -qql $zipfile]} inzip
  715.             foreach {Length Date Time Name} $inzip {
  716.                 if {[regexp -nocase {file_id\.diz$} $Name]} {
  717.                   catch {set temp [exec ../scripts/ioNiNJA/MiSC/UNZIP32.exe  -Cqqp $zipfile $Name > $path/$Name]} temp
  718.                   vfs chattr "$path" 10 $Name
  719.                 }
  720.         }
  721.         symlink_proc cd 1
  722.     }
  723.        
  724.     if {![file exists "$path/file_id.diz"]} {
  725.         return
  726.     } else {
  727.         set diz "$path/file_id.diz"
  728.     }
  729.  
  730.     if {[file size "$path/file_id.diz"] == 0} {
  731.         catch {file delete -force "$path/file_id.diz"}
  732.         return
  733.     }
  734.  
  735.     regsub -all -nocase {x|o|\*} [readfile $diz] 0 diz
  736.     regsub -all -nocase {[0-9]{1,4}/[0-9]{1,4}/[0-9]{1,4}} $diz "" diz
  737.     set dizinfo [regexp {[^/0-9]([0-9]{1,3})(?:/|/\n)([0-9]{1,3})(?:[^/0-9]|$)} $diz -> file_nr total_files]
  738.     if {[info exists total_files]} {
  739.         scan $total_files %d total_files
  740.         set total_files [format %.0f $total_files]
  741.         catch {vfs chattr "$path" 13 $total_files}
  742.         return
  743.     } else {
  744.         catch {file delete -force "$path/file_id.diz"}
  745.         return
  746.     }
  747.    
  748. }
  749.  
  750.  
  751.  
  752. #######################
  753. ### Get duration from timestamp
  754. #######################
  755.  
  756. proc ::ioNiNJA::duration { secs } {
  757.      if {![string is integer -strict $secs]} { return "0s" }
  758.      set timeatoms [ list ]
  759.      if { [ catch {
  760.         foreach div { 86400 3600 60 1 } \
  761.                 mod { 0 24 60 60 } \
  762.                name { d h m s } {
  763.            set n [ expr {$secs / $div} ]
  764.            if { $mod > 0 } { set n [ expr {$n % $mod} ] }
  765.               if { $n > 1 } {
  766.               lappend timeatoms "$n${name}"
  767.            } elseif { $n == 1 } {
  768.              lappend timeatoms "$n$name"
  769.            }
  770.         }
  771.      } err ] } {
  772.         return -code error "duration: $err"
  773.      }
  774.      return [ join $timeatoms ]
  775. }
  776.  
  777.  
  778. #######################
  779. ###Get userinfo
  780. #######################
  781. proc ::ioNiNJA::get_uinfo {user type} {
  782.     if {[userfile open $user] == 0} {
  783.         if {[set ufile [userfile bin2ascii]] != ""} {
  784.             foreach info [split $ufile \n] {
  785.                 if {[string match -nocase $type [lindex $info 0]]} {
  786.                     return [lrange $info 1 end]
  787.                 }
  788.             }
  789.         }
  790.     }
  791.   return ""
  792. }
  793.  
  794.  
  795. #######################
  796. ### String map crappy html codes
  797. #######################
  798.  
  799. proc ::ioNiNJA::htmlcodes {tempfile} {
  800.   set mapfile [string map {&#x26; & &nbsp; " " &#160; " " &#xA0; " " &iexcl; ¡ &#161; ¡ &#xA1; ¡ &cent; ¢ &#162; ¢ &#xA2; ¢ &pound; £ &#163; £ &#xA3; £ &curren; ¤ &#164; ¤ &#xA4; ¤ &yen; ¥ &#165; ¥ &#xA5; ¥ &brvbar; ¦ &#166; ¦ &#xA6; ¦ &sect; § &#167; § &#xA7; § &uml; ¨ &#168; ¨ &#xA8; ¨ &copy; © &#169; © &#xA9; © &ordf; ª &#170; ª &#xAA; ª &laquo; « &#171; « &#xAB; « &not; ¬ &#172; ¬ &#xAC; ¬ &shy; ­ &#173; ­ &#xAD; ­ &reg; ® &#174; ® &#xAE; ® &macr; ¯ &#175; ¯ &#xAF; ¯ &deg; ° &#176; ° &#xB0; ° &plusmn; ± &#177; ± &#xB1; ± &sup2; ² &#178; ² &#xB2; ² &sup3; ³ &#179; ³ &#xB3; ³ &acute; ´ &#180; ´ &#xB4; ´ &micro; µ &#181; µ &#xB5; µ &para; ¶ &#182; ¶ &#xB6; ¶ &middot; · &#183; · &#xB7; · &cedil; ¸ &#184; ¸ &#xB8; ¸ &sup1; ¹ &#185; ¹ &#xB9; ¹ &ordm; º &#186; º &#xBA; º &raquo; » &#187; » &#xBB; » &frac14; ¼ &#188; ¼ &#xBC; ¼ &frac12; ½ &#189; ½ &#xBD; ½ &frac34; ¾ &#190; ¾ &#xBE; ¾ &iquest; ¿ &#191; ¿ &#xBF; ¿ &Agrave; À &#192; À &#xC0; À &Aacute; Á &#193; Á &#xC1; Á &Acirc; Â &#194; Â &#xC2; Â &Atilde; Ã &#195; Ã &#xC3; Ã &Auml; Ä &#196; Ä &#xC4; Ä &Aring; Å &#197; Å &#xC5; Å &AElig; Æ &#198; Æ &#xC6; Æ &Ccedil; Ç &#199; Ç &#xC7; Ç &Egrave; È &#200; È &#xC8; È &Eacute; É &#201; É &#xC9; É &Ecirc; Ê &#202; Ê &#xCA; Ê &Euml; Ë &#203; Ë &#xCB; Ë &Igrave; Ì &#204; Ì &#xCC; Ì &Iacute; Í &#205; Í &#xCD; Í &Icirc; Î &#206; Î &#xCE; Î &Iuml; Ï &#207; Ï &#xCF; Ï &ETH; Ð &#208; Ð &#xD0; Ð &Ntilde; Ñ &#209; Ñ &#xD1; Ñ &Ograve; Ò &#210; Ò &#xD2; Ò &Oacute; Ó &#211; Ó &#xD3; Ó &Ocirc; Ô &#212; Ô &#xD4; Ô &Otilde; Õ &#213; Õ &#xD5; Õ &Ouml; Ö &#214; Ö &#xD6; Ö &times; × &#215; × &#xD7; × &Oslash; Ø &#216; Ø &#xD8; Ø &Ugrave; Ù &#217; Ù &#xD9; Ù &Uacute; Ú &#218; Ú &#xDA; Ú &Ucirc; Ú &#219; Û &#xDB; Û &Uuml; Ü &#220; Ü &#xDC; Ü &Yacute; Ý &#221; Ý &#xDD; Ý &THORN; Þ &#222; Þ &#xDE; Þ &szlig; ß &#223; ß &#xDF; ß &agrave; à &#224; à &#xE0; à &aacute; á &#225; á &#xE1; á &acirc; â &#226; â &#xE2; â &atilde; ã &#227; ã &#xE3; ã &auml; ä &#228; ä &#xE4; ä &aring; å &#229; å &#xE5; å &aelig; æ &#230; æ &#xE6; æ &ccedil; ç &#231; ç &#xE7; ç &egrave; è &#232; è &#xE8; è &eacute; é &#233; é &#xE9; é &ecirc; ê &#234; ê &#xEA; ê &euml; ë &#235; ë &#xEB; ë &igrave; ì &#236; ì &#xEC; ì &iacute; í &#237; í &#xED; í &icirc; î &#238; î &#xEE; î &iuml; ï &#239; ï &#xEF; ï &eth; ð &#240; ð &#xF0; ð &ntilde; ñ &#241; ñ &#xF1; ñ &ograve; ò &#242; ò &#xF2; ò &oacute; ó &#243; ó &#xF3; ó &ocirc; ô &#244; ô &#xF4; ô &otilde; õ &#245; õ &#xF5; õ &ouml; ö &#246; ö &#xF6; ö &divide; ÷ &#247; ÷ &#xF7; ÷ &oslash; ø &#248; ø &#xF8; ø &ugrave; ù &#249; ù &#xF9; ù &uacute; ú &#250; ú &#xFA; ú &ucirc; û  &#251; û &#xFB; û &uuml; ü &#252; ü &#xFC; ü &yacute; ý &#253; ý &#xFD; ý &thorn; þ &#254; þ &#xFE; þ &yuml; ÿ &#255; ÿ &#xFF; ÿ } $tempfile]
  801.   set mapfile [string map {&#x22; ' &#x27; ' &#160; " " &#39; ' &#34; ' &#38; & &#91; ( &#92; / &#93; ) &#123; ( &#125; ) &#161; ¡ &#162; ¢ &#163; £ &#164; ¤ &#165; ¥ &#166; ¦ &#167; § &#168; ¨ &#169; © &#170; ª &#171; « &#172; ¬ &#173; ­ &#174; ® } $mapfile]
  802.   set mapfile [string map {&#175; ¯ &#176; ° &#177; ± &#178; ² &#179; ³ &#180; ´ &#181; µ &#182; ¶ &#183; · &#184; ¸ &#185; ¹ &#186; º &#187; » &#188; ¼ &#189; ½ &#190; ¾ &#191; ¿ &#192; À &#193; Á &#194; Â } $mapfile]
  803.   set mapfile [string map {&#195; Ã &#196; Ä &#197; Å &#198; Æ &#199; Ç &#200; È &#201; É &#202; Ê &#203; Ë &#204; Ì &#205; Í &#206; Î &#207; Ï &#208; Ð &#209; Ñ &#210; Ò &#211; Ó &#212; Ô &#213; Õ &#214; Ö } $mapfile]
  804.   set mapfile [string map {&#215; × &#216; Ø &#217; Ù &#218; Ú &#219; Û &#220; Ü &#221; Ý &#222; Þ &#223; ß &#224; à &#225; á &#226; â &#227; ã &#228; ä &#229; å &#230; æ &#231; ç &#232; è &#233; é &#234; ê } $mapfile]
  805.   set mapfile [string map {&quot; ' &amp; "And" &#235; ë &#236; ì &#237; í &#238; î &#239; ï &#240; ð &#241; ñ &#242; ò &#243; ó &#244; ô &#245; õ &#246; ö &#247; ÷ &#248; ø &#249; ù &#250; ú &#251; û &#252; ü &#253; ý &#254; þ } $mapfile]
  806.  return $mapfile
  807. }
  808.  
  809.  
  810.  
  811. #######################
  812. # Sorting
  813. #######################
  814.  
  815. proc ::ioNiNJA::sorting {symtype linkto item pwd} {global ioNJ
  816.  
  817.     set linkto [file normalize $linkto]
  818.     set item [file normalize $item]
  819.    
  820.    
  821.     set item [string map [get_time [clock seconds]] $item]
  822.    
  823.     if {[file exists $item]} {
  824.         if {![catch {file link $item} templink]} {
  825.             set templink [file normalize $templink]
  826.             if {![file exists $templink] || ( [string match -nocase $templink $linkto] )} {
  827.                 catch {file delete -force -- $item} error
  828.             } elseif {[file tail $templink] == [file tail $linkto] && ( $templink != $linkto )} {
  829.                 set item "${item}.dupe"
  830.             }              
  831.         } else {
  832.             catch {file delete -force -- $item} error
  833.         }
  834.     }
  835.            
  836.     if {[file exists $item]} {
  837.         set i 0
  838.         while {[file exists "${item} (${i})"] && $i != 100} {
  839.             incr i 
  840.         }
  841.         set item "${item} (${i})"
  842.     }
  843.    
  844.    
  845.         if {!$symtype} {
  846.         catch {file delete -force -- $item}
  847.         catch {file mkdir "$item"}
  848.         catch {vfs chattr "$item" 1 "$pwd"}
  849.         catch {vfs flush "$item"}
  850.     } else {
  851.         catch {file delete -force -- $item}
  852.         catch {file mkdir "[file dirname $item]"}
  853.         catch {file link -symbolic "$item" "$linkto"} error
  854.     }
  855.    
  856.     set symlinks [readchattr 240]
  857.     lappend symlinks $item
  858.     writechattr 240 $symlinks
  859. return
  860. }
  861.  
  862.  
  863.  
  864.  
  865. #######################
  866. ## Get URL
  867. #######################
  868.  
  869.  
  870. proc ::ioNiNJA::get_url_long_timeout {url} {
  871.  
  872.  if {[regexp -nocase { } [string trim $url]]} { return "" }
  873.    
  874.  set tempcode ""
  875.      
  876.  catch {
  877.     set url_agent "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1"
  878.     set url_page  [::http::config -useragent $url_agent]
  879.     set token     [::http::geturl "$url" -timeout 600000]
  880.  
  881.  
  882.     set i 0
  883.     while {[set tempcode [::http::data $token]] == "" && $i != 5} {
  884.         http::cleanup $token
  885.         http::Finish $token
  886.         set token [::http::geturl "$url" -timeout 600000]
  887.         incr i
  888.     }
  889.  
  890.     http::cleanup $token
  891.  }
  892.  return $tempcode
  893. }
  894.  
  895.  
  896. proc ::ioNiNJA::get_url2 {url} {
  897.  
  898.  if {[regexp -nocase { } [string trim $url]]} { return "" }
  899.  
  900.  set tempcode ""
  901.  
  902.  catch {
  903.     set url_agent "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1"
  904.     set url_page  [::http::config -useragent $url_agent]
  905.     set token     [::http::geturl "$url" -timeout 60000]
  906.  
  907.     if {![info exists token]} {  set token [::http::geturl "$url" -timeout 60000] }
  908.  
  909.  
  910.     set i 0
  911.     while {[set tempcode [string trim [::http::data $token]]] == "" && $i != 5} {
  912.             http::cleanup $token
  913.         http::Finish $token
  914.         set token [::http::geturl "$url" -timeout 60000]
  915.         incr i
  916.      }
  917.  
  918.      http::cleanup $token
  919.  }
  920.  return $tempcode
  921. }
  922.  
  923.  
  924. proc ::ioNiNJA::get_url {url} {
  925.  
  926.  if {[regexp -nocase { } [string trim $url]]} { return "" }
  927.  
  928.  set tempcode ""
  929.  catch {
  930.     set url_agent "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1"
  931.     set url_page  [::http::config -useragent $url_agent]
  932.     set token     [::http::geturl "$url" -timeout 3000]
  933.  
  934.     if {![info exists token]} {  set token [::http::geturl "$url" -timeout 3000] }
  935.    
  936.     set i 0
  937.     while {[set tempcode [::http::data $token]] == "" && $i != 5} {
  938.         http::cleanup $token
  939.         http::Finish $token
  940.         set token [::http::geturl "$url" -timeout 3000]
  941.         incr i
  942.     }
  943.      
  944.     set tempcode [htmlcodes $tempcode]
  945.    
  946.     http::cleanup $token
  947.  }
  948.  return $tempcode
  949. }
  950.  
  951.  
  952. #######################
  953. ## Get GrpName From Rel
  954. #######################
  955.  
  956. proc ::ioNiNJA::get_grpname {release} {global ioNJ
  957.  if {[regexp {\-} $release]} {
  958.     set temps [split [string trim $ioNJ(force_groupnames)] \n]
  959.     if {$temps != ""} {
  960.         foreach temp $temps {
  961.             lassign $temp regex grp
  962.             if {[regexp -nocase $regex $release]} { return $grp }
  963.         }
  964.     }
  965.     if {[lindex [split $release -] end] != $release} { return [lindex [split $release -] end]}
  966.  }
  967.  
  968.  return "Unknown"
  969. }
  970.  
  971.  
  972.  
  973. #######################
  974. ## Make inc symlinks
  975. #######################
  976.  
  977. proc ::ioNiNJA::symlink_proc {type action} { global ioNJ pwd path
  978.         set dir [lindex [file split $path] end]
  979.         set parent [lindex [file split $path] end-1]
  980.         set rdir [file dirname $path]
  981.         set type2 ""
  982.         if {[regexp -nocase "$ioNJ(notparent)" "$dir"]} {
  983.             set rdir [file dirname $rdir]
  984.             set type2 cd
  985.         }
  986.        
  987.  
  988.        
  989.         switch -- $type {
  990.             sfv  {
  991.                 if {$type2 == "cd"} {
  992.                     set directory $ioNJ(incomplete_indicator_cd_sfv)
  993.                 }  else {
  994.                         set directory $ioNJ(incomplete_indicator_sfv)
  995.                 }
  996.             }
  997.            
  998.             nfo  {
  999.                 if {$type2 == "cd"} {
  1000.                     set dir $parent
  1001.                 }
  1002.                 set directory $ioNJ(incomplete_indicator_nfo)
  1003.             }
  1004.            
  1005.             sample  {
  1006.                 if {$type2 == "cd"} {
  1007.                     set dir $parent
  1008.                 }
  1009.                 set directory $ioNJ(incomplete_indicator_sample)
  1010.             }
  1011.            
  1012.            
  1013.                 cd   {
  1014.                     if {$type2 == "cd"} {
  1015.                     set directory $ioNJ(incomplete_indicator_cd)
  1016.                 }  else {
  1017.                         set directory $ioNJ(incomplete_indicator)
  1018.                 }
  1019.  
  1020.                 }
  1021.         }
  1022.        
  1023.     set dir [string map [list %di $dir %pa $parent] $directory]
  1024.  
  1025.     if {$action == 1} {
  1026.         catch {file mkdir "$rdir/$dir"}
  1027.         catch {vfs chattr "$rdir/$dir" 1 "$pwd"}
  1028.         catch {vfs flush $path }
  1029.         if {$ioNJ(sym_inc_dir) != "" && [file exists $ioNJ(sym_inc_dir)]} {
  1030.             if {![regexp -nocase $ioNJ(group_dirs) $pwd]} {
  1031.                 catch {file mkdir "$ioNJ(sym_inc_dir)/$dir"}
  1032.                 catch {vfs chattr "$ioNJ(sym_inc_dir)/$dir" 1 "$pwd"}
  1033.                 catch {vfs flush $ioNJ(sym_inc_dir)}
  1034.             }
  1035.         }
  1036.     } else {
  1037.         catch {file delete -force "$rdir/$dir"}
  1038.         catch {vfs flush $path}
  1039.         if {$ioNJ(sym_inc_dir) != "" && ![regexp -nocase $ioNJ(group_dirs) $pwd]} {
  1040.             catch {file delete -force "$ioNJ(sym_inc_dir)/$dir"}
  1041.             catch {vfs flush $ioNJ(sym_inc_dir)}
  1042.         }
  1043.     }
  1044.    
  1045.     return
  1046. }
  1047.  
  1048.  
  1049. #######################
  1050. ## Get Sammple Info
  1051. #######################
  1052.  
  1053. proc ::ioNiNJA::getsample {sample} { global path pwd ioNJ uid gid args
  1054. set samplerelease [lindex [file split $pwd] end-1]
  1055. set samplemessage "\n"
  1056. catch {exec ../scripts/ioNiNJA/misc/media.exe $sample} temp
  1057. if {$temp == ""} { return ""}
  1058. set audiostreams 0
  1059. set textstreams 0
  1060. set type 0 ; set g_movie_name "N/A" ; set w_writelib "N/A" ; set v_chroma "N/A" ; set v_resolution "N/A" ; set g_performer "N/A" ; set g_format  "N/A" ; set g_bitrate "N/A" ; set g_writeapp "N/A" ; set g_writelib "N/A" ; set a_codec "N/A" ; set a_codec_prof "N/A" ; set a_bitrate "N/A" ; set a_bitrate_mode "N/A" ; set a_chans "N/A" ; set a_srate "N/A" ; set a_WriteLib "N/A" ; set a_res "N/A" ; set a_chanpos "N/A" ; set v_codec_info "N/A" ; set v_codec_family "N/A" ; set v_codec_pack "N/A" ; set v_codec_bvop "N/A" ; set v_codec_qpel "N/A" ; set v_codec_gmc "N/A" ; set v_codec_matrix "N/A" ; set v_codec "N/A" ; set v_width "N/A" ; set v_height "N/A" ; set v_ar "N/A" ; set v_br "N/A" ; set v_fr "N/A" ; set v_standard "N/A" ; set v_interlace "N/A"
  1061.  
  1062. set samplemessage $ioNJ(sample_head)
  1063. foreach line [split $temp \n] {
  1064.     if {$line == ""} { continue }
  1065.     if {[string match "General #*" $line] || ( [regexp -nocase {(^General$)} $line] ) } {
  1066.         if {[lindex $line 1] == "#0" || ([regexp -nocase {(^General$)} $line]) } {
  1067.             set type g
  1068.         } else {
  1069.             set type 0
  1070.         }
  1071.     } elseif {[string match "Video #*" $line]  || ( [regexp -nocase {(^Video$)} $line] ) } {
  1072.         if {[lindex $line 1] == "#1" || ([regexp -nocase {(^Video$)} $line])} {
  1073.             append samplemessage $ioNJ(sample_video_head)
  1074.             set type v
  1075.         } else {
  1076.             set type 0
  1077.         }
  1078.     } elseif {[string match "Audio #*" $line] || ([regexp -nocase {(^Audio$)} $line]) } {
  1079.         incr audiostreams
  1080.         if {[lindex $line 1] == "#1" || ([regexp -nocase {(^Audio$)} $line]) } {
  1081.             append samplemessage "$ioNJ(sample_audio_head)"
  1082.             set type a
  1083.         } else {
  1084.             set type 0
  1085.         }
  1086.     }
  1087.  
  1088.     if {[string match -nocase "Text #*" $line]} { set type 0 ; incr textstreams }
  1089.  
  1090.     set line [split $line :]
  1091.     set first [string trim [lindex $line 0]]
  1092.     set second [string trim [join [lrange $line 1 end]]]
  1093.  
  1094.     if {$type == "g"} {
  1095.         switch -- $first {
  1096.           "Copyright"  { set g_movie_cr $second        ; append samplemessage [regsub -all {%value} $ioNJ(sample_copyright) $second]}
  1097.           "Movie name" { set g_movie_name $second        ; append samplemessage [regsub -all {%value} $ioNJ(sample_moviename) $second]}
  1098.           "Performer"  { set g_performer $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_performer) $second]}
  1099.           "Format" { set g_format $second                ; append samplemessage [regsub -all {%value} $ioNJ(sample_format) $second]}
  1100.           "Bit rate" { set g_bitrate $second             ; append samplemessage [regsub -all {%value} $ioNJ(sample_bitrate) $second]}
  1101.           "Writing application" { set g_writeapp $second ; append samplemessage [regsub -all {%value} $ioNJ(sample_writeapp) $second]}
  1102.           "Writing library" { set g_writelib $second     ; append samplemessage [regsub -all {%value} $ioNJ(sample_writelib) $second]}
  1103.         }
  1104.  
  1105.     }
  1106.     if {$type == "a"} {
  1107.         switch -- $first {
  1108.           "Format"            { set a_codec $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_format) $second] }
  1109.                  "Format/Info"       { set a_codec_prof $second    ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_codecprofile) $second] }
  1110.           "Bit rate"          { set a_bitrate $second       ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_bitrate) $second] }
  1111.           "Bit rate mode"     { set a_bitrate_mode $second  ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_brmode) $second] }
  1112.           "Channel(s)"        { set a_chans $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_channels) $second] }
  1113.           "Channel positions" { set a_chanpos $second       ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_chanpos) $second] }
  1114.           "Sampling rate"     { set a_srate $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_samprate) $second] }
  1115.           "Writing library"   { set a_WriteLib $second      ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_writelib) $second] }
  1116.           "Resolution"        { set a_res $second           ; append samplemessage [regsub -all {%value} $ioNJ(sample_audio_res) $second]}
  1117.         }
  1118.  
  1119.     }
  1120.  
  1121.     if {$type == "v"} {
  1122.         switch -- $first {
  1123.           "Format_info"                 { set v_codec_info $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_format) $second] }
  1124.               "Format/Info"                 { set v_codec_family $second       ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_formatinfo) $second] }
  1125.           "Codec settings/Packe"        { set v_codec_pack $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_pack) $second] }
  1126.                  "Codec settings/BVOP"         { set v_codec_bvop $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_bvop) $second] }
  1127.                  "Codec settings/QPel"         { set v_codec_qpel $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_qpel) $second] }
  1128.                  "Codec settings/GMC"          { set v_codec_gmc $second          ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_gmc) $second] }
  1129.                  "Codec settings/Matri"        { set v_codec_matrix $second       ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_matrix) $second] }
  1130.           "Codec"                       { set v_codec $second              ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_codec) $second] }
  1131.           "Width"                   { set v_width [lindex $second  0]  ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_width) $second] }
  1132.           "Height"                      { set v_height [lindex $second 0]  ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_height) $second] }
  1133.           "Display aspect ratio"        { set v_ar $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_aspect) $second] }
  1134.           "Bit rate"                    { set v_br $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_bitrate) $second] }
  1135.           "Frame rate"                  { set v_fr $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_framerate) $second] }
  1136.           "Format profile"              { set v_fp $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_formatprof) $second] }
  1137.           "Format settings, ReFrames"   { set v_rf $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_resframes) $second] }
  1138.           "Codec ID"                    { set v_codec $second                 ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_codecid) $second] }
  1139.           "Standard"                    { set v_standard $second           ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_standard) $second] }
  1140.           "Interlacement"               { set v_interlace $second          ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_interlace) $second] }
  1141.           "Resolution"                  { set v_resolution $second         ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_resolution) $second] }
  1142.           "Chroma"          { set v_chroma [regsub -all " " $second ":"]   ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_chroma) $second] }
  1143.           "Writing library"     { set w_writelib $second           ; append samplemessage [regsub -all {%value} $ioNJ(sample_video_writelib) $second] }
  1144.         }
  1145.  
  1146.  
  1147.     }
  1148.  
  1149. }
  1150.  
  1151. append samplemessage $ioNJ(sample_footer)
  1152.  
  1153. set samplemessage [string map "%ioNiNJA_VER $ioNJ(VER)" $samplemessage]
  1154.  
  1155. set exchange [regexp -all -inline {%fm([\-]?)([0-9]+)\{([^\{\}]+)\}} $samplemessage]
  1156. foreach {crap 1 2 replacing} $exchange {
  1157.     if {![string is integer -strict $2]} { continue }
  1158.        if {[string length $replacing] > $2} {
  1159.             set replace [string range $replacing 0 [expr $2 - 1]]
  1160.        } else {
  1161.             set replace $replacing
  1162.        }
  1163.      
  1164.     set samplemessage [string map [list "%fm$1$2\{$replacing\}" [format %${1}${2}s "$replace"]] $samplemessage]
  1165. }
  1166.  
  1167.  
  1168.  
  1169.  
  1170. if {![info exists g_format]} {
  1171. if {[info exists v_codec]} {
  1172.     set g_format $v_codec
  1173. } else {
  1174.     set g_format "default"
  1175. }
  1176.  
  1177. }
  1178. if {$a_chans == "2 channels" && $a_chanpos == "N/A" } { set a_chanpos "L R" }
  1179.  
  1180.  
  1181. if {![file exists [resolve pwd $pwd]/.ioFTPD.message] && [regexp -nocase {/sample/} $pwd]} {
  1182.     writefile $path/.ioFTPD.message "$samplemessage"
  1183.     catch {file attributes "$path/.ioFTPD.message" -hidden 1}
  1184. }
  1185.  
  1186.  
  1187.  
  1188. if {[regexp -nocase "/sample" $pwd]} {
  1189.     if {[string match -nocase "*AVI*" $g_format]} {
  1190.         put_log "SAMPLE_AVI: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $v_resolution $w_writelib $v_chroma $v_interlace $v_codec_matrix $v_codec_gmc $v_codec_pack $v_codec_qpel $v_codec_bvop $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_res $a_codec_prof $a_WriteLib $a_chanpos]"
  1191.     } elseif {[string match -nocase "*Windows Media*" $g_format]} {
  1192.         put_log "SAMPLE_WMV: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_br $v_height $v_width $v_ar $v_resolution $a_codec $a_bitrate $a_chans $a_srate]"
  1193.     } elseif {[string match -nocase "*MPEG-1*" $g_format]} {
  1194.         put_log "SAMPLE_MPEG: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $v_interlace $v_codec_matrix $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_res $a_WriteLib $a_chanpos]"
  1195.     } elseif {[string match -nocase "*MPEG-2*" $g_format]} {
  1196.         put_log "SAMPLE_MPEG2: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $v_interlace $v_standard $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_chanpos]"
  1197.     } elseif {[string match -nocase "*Matroska*" $g_format]} {
  1198.         put_log "SAMPLE_MATROSKA: [list $pwd [resolve uid $uid] [resolve gid $gid] $g_bitrate $v_codec $v_fr $v_height $v_width $v_ar $a_codec $a_chans $a_srate $a_chanpos]"
  1199.     } elseif {[string match -nocase "*RealVideo*" $g_format]} {
  1200.         put_log "SAMPLE_REAL: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $v_resolution $v_ar $a_codec $a_bitrate $a_chans $a_res]"
  1201.     } elseif {[string match -nocase "*QuickTime*" $g_format]} {
  1202.         put_log "SAMPLE_QT: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $a_codec $a_bitrate $a_chans $a_srate $a_res]"
  1203.     } else {
  1204.         put_log "SAMPLE_GENERAL: [list $pwd [resolve uid $uid] [resolve gid $gid] $v_codec $v_fr $v_br $v_height $v_width $v_ar $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_res]"
  1205.     }
  1206.         vfs chattr [file dirname $path] 20 "[list $v_codec $v_fr $v_br $v_height $v_width $v_ar $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_res]"
  1207.         output $samplemessage
  1208. } else {
  1209.     vfs chattr $path 20 "[list $v_codec $v_fr $v_br $v_height $v_width $v_ar $a_codec $a_bitrate $a_bitrate_mode $a_chans $a_srate $a_res]"
  1210. }
  1211.  
  1212. symlink_proc sample 0
  1213. return
  1214. }
  1215.  
  1216.  
  1217. proc ::ioNiNJA::get_files {dir pattern} {return [glob -nocomplain -type f -directory $dir $pattern]}
  1218. proc ::ioNiNJA::get_dirs  {dir pattern} {return [glob -nocomplain -type d -directory $dir $pattern]}
  1219.  
  1220. proc ::ioNiNJA::get_file_name {} {global path
  1221.  
  1222.     set fname ""
  1223.    
  1224.     set rarfname [lindex [get_files $path {*{.rar,.001}}] 0]
  1225.    
  1226.    
  1227.     if {$rarfname != ""} {
  1228.         if {[catch {set fname [exec -- ../scripts/ioNiNJA/MiSC/unrar.exe lb $rarfname]} error]} {
  1229.             set fname ""
  1230.         } else {
  1231.             set fname [file rootname $fname]
  1232.         }
  1233.     }
  1234.  
  1235.    
  1236.     if {$fname == ""} {
  1237.         set fname [file rootname [lindex [get_files $path {*{.mkv,.avi,.asf,.m2v,.mpg,.mpeg,.divx,.wmv,.mp4,.img,.iso,.bin,.rar,.001}}] 0]]
  1238.         if {$fname == ""} {
  1239.             set fname [file rootname [lindex [get_files $path {*{.nfo,.sfv}}] 0]]
  1240.             if {$fname == ""} {
  1241.                 set fname [lindex [file split $path] end]
  1242.             }
  1243.         }
  1244.     }
  1245.    
  1246.     return $fname
  1247. }
  1248.  
  1249. #######################
  1250. # get time vars
  1251. #######################
  1252.  
  1253. proc ::ioNiNJA::get_time {time} {
  1254.     set return [clock format $time -format "%%a %a %%A %A %%b %b %%B %B %%C %C %%d %d %%e %e %%g %g %%G %G %%h %h %%I %I %%j %j %%k %k %%l %l %%m %m %%M %M %%p %p %%u %u %%U %U %%V %V %%w %w %%W %W %%y %y %%Y %Y"]
  1255. }
  1256.  
  1257.  
  1258. #######################
  1259. # get time vars
  1260. #######################
  1261.  
  1262. proc ::ioNiNJA::get_sorted_time {dirs} {
  1263.     set return_dirs ""
  1264.    
  1265.     foreach dir $dirs {
  1266.         lappend return_dirs [list $dir [file mtime $dir]]
  1267.     }
  1268.    
  1269.     return [lsort -increasing -integer -index 1 "$return_dirs"]
  1270. }
  1271.  
  1272. #######################
  1273. ## Output to ftpd
  1274. #######################
  1275.  
  1276. proc ::ioNiNJA::output {message} {global ioNJ
  1277.     regsub -all %ioNiNJA_VER $message $ioNJ(VER) message
  1278.     foreach line [split [string trim $message] \n]  {
  1279.         iputs -nobuffer "$line"
  1280.     }
  1281. }
  1282.  
  1283. proc ::ioNiNJA::outputerror {message} {global ioNJ
  1284.     regsub -all %ioNiNJA_VER $message $ioNJ(VER) message
  1285.     foreach line [split [string trim $message] \n]  {
  1286.         iputs "$line"
  1287.     }
  1288. }
  1289.  
  1290.  
  1291.  
  1292. #######################
  1293. ## Format Size
  1294. #######################
  1295.  
  1296. proc ::ioNiNJA::format_size {amount} {
  1297.     foreach dec {0 0 1 2 2 2} unit {KB MB GB TB PB EB} {
  1298.         if {abs($amount) >= 1024} {
  1299.             set amount [expr $amount / 1024.0]
  1300.         } else {break}
  1301.     }
  1302.     return [format "%.*f%s" $dec $amount $unit]
  1303. }
  1304.  
  1305.  
  1306. #######################
  1307. ## Format Speed
  1308. #######################
  1309. proc ::ioNiNJA::format_speed {value} {
  1310.     if {$value > 1024 } {
  1311.         set value [format "%.1f" [expr {$value / 1024.0}]]
  1312.         set type "MB/s"
  1313.     } else {
  1314.         set value [format "%.1f" [expr $value * 1.0]]
  1315.         set type "KB/s"
  1316.     }
  1317. return "$value$type"
  1318. }
  1319.  
  1320. #######################
  1321. ## Read File
  1322. #######################
  1323.  
  1324. proc ::ioNiNJA::readfile {file} {
  1325.     if {![file exists $file]} {return ""}
  1326.     set openfile [open $file r]
  1327.     set fileread [read $openfile]
  1328.     close $openfile
  1329.     unset -nocomplain openfile
  1330.     return $fileread
  1331. }
  1332.  
  1333.  
  1334.  
  1335. #######################
  1336. ## Write File
  1337. #######################
  1338.  
  1339.  
  1340. proc ::ioNiNJA::writefile {file text} {
  1341.     set openfile [open $file w]
  1342.     puts $openfile $text
  1343.     close $openfile
  1344.     unset openfile
  1345.     return 0
  1346. }
  1347.  
  1348. #######################
  1349. ## Append to file
  1350. #######################
  1351.  
  1352. proc ::ioNiNJA::appendfile {file text} {
  1353.     set openfile [open $file a]
  1354.     puts $openfile "$text"
  1355.     close $openfile
  1356.     return 0
  1357. }
  1358.  
  1359.  
  1360. ##
  1361. # Check if something is binary
  1362. ##
  1363. proc ::ioNiNJA::bin_ary {data} {
  1364. return [string trim [expr {[string first \x00 $data]>=0}]]
  1365.  
  1366. }
  1367.  
  1368.  
  1369.  
  1370. proc ::ioNiNJA::save_pic {pic_data} { global ioNJ path pwd
  1371.  
  1372.     set images [list "$path/folder.jpg"]
  1373.    
  1374.    
  1375.     if {[regexp -nocase $ioNJ(notparent) [file tail $pwd]]} {
  1376.         lappend images "[file join [file dirname $path] folder.jpg]"
  1377.     }
  1378.    
  1379.  
  1380.     if {[string trim $pic_data] == ""} { return }
  1381.    
  1382.     if { ![bin_ary $pic_data] } { return }
  1383.    
  1384.     foreach image $images {
  1385.         catch {file attribute $image -hidden 0}
  1386.         set openfile [open $image w]
  1387.         fconfigure $openfile  -encoding binary -translation binary -buffering full -buffersize 1000000
  1388.         puts $openfile $pic_data
  1389.         close $openfile
  1390.         unset openfile
  1391.         if {$ioNJ(hide_folder_pic)} { catch {file attribute "$image" -hidden 1} }
  1392.         catch {vfs flush [file dirname $image]}
  1393.     }
  1394.     unset pic_data
  1395. }
  1396.  
  1397. proc ::ioNiNJA::save_pic_custom {pic_name pic_data} { global ioNJ path pwd
  1398.  
  1399.     set images [list "$pic_name"]
  1400.    
  1401.    
  1402.     if {[regexp -nocase $ioNJ(notparent) [file tail $pwd]]} {
  1403.         lappend images "[file join [file dirname $path] $pickname]"
  1404.     }
  1405.    
  1406.  
  1407.     if {[string trim $pic_data] == ""} { return }
  1408.    
  1409.     if { ![bin_ary $pic_data] } { return }
  1410.    
  1411.     foreach image $images {
  1412.         catch {file attribute $image -hidden 0}
  1413.         set openfile [open $image w]
  1414.         fconfigure $openfile  -encoding binary -translation binary -buffering full -buffersize 1000000
  1415.         puts $openfile $pic_data
  1416.         close $openfile
  1417.         unset openfile
  1418.         catch {vfs flush [file dirname $image]}
  1419.     }
  1420.     unset pic_data
  1421. }
  1422.  
  1423. proc ::ioNiNJA::save_pic_custom_path {pic_name pic_data} { global ioNJ path pwd
  1424.  
  1425.     set images [list "$pic_name"]
  1426.    
  1427.  
  1428.     if {[string trim $pic_data] == ""} { return }
  1429.    
  1430.     if { ![bin_ary $pic_data] } { return }
  1431.    
  1432.     foreach image $images {
  1433.         catch {file attribute $image -hidden 0}
  1434.         set openfile [open $image w]
  1435.         fconfigure $openfile  -encoding binary -translation binary -buffering full -buffersize 1000000
  1436.         puts $openfile $pic_data
  1437.         close $openfile
  1438.         unset openfile
  1439.         catch {vfs flush [file dirname $image]}
  1440.     }
  1441.     unset pic_data
  1442. }
  1443.  
  1444. #######################
  1445. ## Write Chattr
  1446. #######################
  1447.  
  1448. proc ::ioNiNJA::writechattr {raceinfo info} { global args pwd path
  1449.     set newcell 0
  1450.     set maxbytes 3499
  1451.     if {[string length $info] <= $maxbytes } {  catch {vfs chattr $path $raceinfo "$info"}  ; return }
  1452.     while {[set temp [string range $info $newcell [expr $newcell + $maxbytes]]] != ""} {
  1453.         set newcell [expr $newcell + $maxbytes + 1]
  1454.         catch {vfs chattr $path $raceinfo "$temp"}
  1455.         incr raceinfo
  1456.     }
  1457.   return
  1458. }
  1459.  
  1460.  
  1461. #######################
  1462. ## Read Chattr
  1463. #######################
  1464.  
  1465. proc ::ioNiNJA::readchattr {x} { global args pwd path
  1466.       set maxbytes 3499
  1467.       set new [vfs chattr $path $x]
  1468.       if {[string length $new] <= $maxbytes} { return $new }
  1469.       incr x
  1470.       while {[set info [vfs chattr $path $x]] != ""} {
  1471.              append new $info
  1472.              incr x
  1473.              if {[string length $info] <= $maxbytes} {
  1474.                 return $new
  1475.              }
  1476.              
  1477.        }
  1478.    
  1479. return $new
  1480. }
  1481.  
  1482. proc ::ioNiNJA::erasechattr {x} { global args pwd path
  1483.        while {[vfs chattr $path $x] != ""} {
  1484.             catch {vfs chattr $path $x ""} error
  1485.             incr x
  1486.        }
  1487. return
  1488. }
  1489.  
  1490.  
  1491. #######################
  1492. ## Read Chattr Parent
  1493. #######################
  1494.  
  1495. proc ::ioNiNJA::readparentchattr {x} { global args pwd path
  1496.     set p2 [file dirname $path]
  1497.     set maxbytes 1999
  1498.        set new [vfs chattr $p2 $x]
  1499.        if {[string length $new] <= $maxbytes} { return $new }
  1500.        incr x
  1501.        while {[set info [vfs chattr $p2 $x]] != ""} {
  1502.              append new $info
  1503.              incr x
  1504.              if {[string length $info] <= $maxbytes} {
  1505.                 return $new
  1506.              }
  1507.        }
  1508.    
  1509. return $new
  1510. }
  1511.  
  1512.  
  1513. #######################
  1514. ## putlog
  1515. #######################
  1516.  
  1517. proc ::ioNiNJA::put_log {text} {
  1518.     catch {set openfile [open ../logs/ioftpd.log a]}
  1519.     catch {puts $openfile "[clock format [clock seconds] -format "%m-%d-%Y %H:%M:%S"] $text"}
  1520.     catch {close $openfile}
  1521.     return 0
  1522. }
  1523.  
  1524.  
  1525. #######################
  1526. ## Add Genres
  1527. #######################
  1528.  
  1529. proc ::ioNiNJA::add_generes {} {global ioNJ
  1530.  
  1531.     foreach genre $ioNJ(genres) {
  1532.         catch {group delete $genre}
  1533.         regsub -all " " $genre "_" genre
  1534.         catch {group create $genre} temp
  1535.     }
  1536.    
  1537.     iputs "Groups added OK"
  1538.  
  1539. }
  1540.  
  1541.  
  1542. proc ::ioNiNJA::invite {} { global uid gid args
  1543.     set nick [lindex $args 1]
  1544.     set user [resolve uid $uid]
  1545.     set group [resolve gid $gid]
  1546.     set flags [get_uinfo $user flags]
  1547.    
  1548.     if {$nick == ""} { output "INVITE ERROR: No nick specified" ; return }
  1549.    
  1550.     put_log "INVITE: [list $nick $user $group $flags]"
  1551.    
  1552.     output " \"$nick\" was invited to join our chan(s)"
  1553. }
  1554.  
  1555.  
  1556. proc ::ioNiNJA::CWD {} { global path pwd uid gid args ioNJ
  1557.  
  1558.  
  1559.    
  1560.     if {[readchattr 4] == ""} {
  1561.         if {[readchattr 115] == ""} { return }
  1562.         writechattr 16 [readchattr 115]
  1563.         writechattr 115 ""
  1564.         writechattr 50 [readchattr 25]
  1565.         writechattr 25 ""
  1566.         writechattr 20 [readchattr 45]
  1567.         writechattr 45 ""
  1568.         writechattr 25 [readchattr 55]
  1569.         writechattr 55 ""
  1570.         writechattr 30 [readchattr 65]
  1571.         writechattr 65 ""
  1572.         writechattr 35 [readchattr 75]
  1573.         writechattr 75 ""
  1574.         writechattr 4 1
  1575.        
  1576.     }
  1577.  
  1578.     if {!$ioNJ(show_complete_message)} { return }
  1579.    
  1580.       if {[set complete [vfs chattr $path 9]] != 1} {
  1581.         if {[set imdb [readchattr 30]] != ""} {
  1582.             if {[lindex $imdb 0] == "IMDBTV"} {
  1583.                 set mess $ioNJ(message_tv_imdbinfo)
  1584.                 set replacevar "%imdb_title {[lindex $imdb 1]} %imdb_url {[lindex $imdb 2]} %imdb_year {[lindex $imdb 3]} %imdb_tv {[lindex $imdb 4]} %imdb_lifetime {[lindex $imdb 5]} %imdb_ratbar {[lindex $imdb 6]} %imdb_rating {[lindex $imdb 7]} %imdb_votes {[lindex $imdb 8]} %imdb_creator {[lindex $imdb 9]} %imdb_cast {[lindex $imdb 10]}  %imdb_runtime {[lindex $imdb 11]} %imdb_country {[lindex $imdb 12]} %imdb_language {[lindex $imdb 13]} %imdb_color {[lindex $imdb 14]} %imdb_genre {[lindex $imdb 15]} %imdb_tagline {[lindex $imdb 16]} %imdb_plot {[lindex $imdb 17]} %imdb_usercomment {[lindex $imdb 18]} %imdb_awards {[lindex $imdb 19]} %imdb_limited {[lindex $imdb 20]} %imdb_director {[lindex $imdb 21]} %ep_name {[lindex $imdb 22]} %ep_airdate {[lindex $imdb 23]}"
  1585.             } else {
  1586.                 set mess $ioNJ(message_imdbinfo)
  1587.                 set replacevar "%imdb_title {[lindex $imdb 0]} %imdb_url {[lindex $imdb 1]} %imdb_year {[lindex $imdb 2]} %imdb_tv {[lindex $imdb 3]} %imdb_lifetime {[lindex $imdb 4]} %imdb_ratbar {[lindex $imdb 5]} %imdb_rating {[lindex $imdb 6]} %imdb_votes {[lindex $imdb 7]} %imdb_director {[lindex $imdb 8]} %imdb_cast {[lindex $imdb 9]} %imdb_mpaa {[lindex $imdb 10]} %imdb_runtime {[lindex $imdb 11]} %imdb_country {[lindex $imdb 12]} %imdb_language {[lindex $imdb 13]} %imdb_color {[lindex $imdb 14]} %imdb_genre {[lindex $imdb 15]} %imdb_tagline {[lindex $imdb 16]} %imdb_plot {[lindex $imdb 17]} %imdb_usercomment {[lindex $imdb 18]} %imdb_awards {[lindex $imdb 19]} %imdb_opengross {[lindex $imdb 20]} %imdb_opencountry {[lindex $imdb 21]} %imdb_openday {[lindex $imdb 22]} %imdb_openyear {[lindex $imdb 23]} %imdb_openscreens {[lindex $imdb 24]} %imdb_screens {[lindex $imdb 25]} %imdb_budget {[lindex $imdb 26]} %imdb_top250 {[lindex $imdb 27]} %imdb_limited {[lindex $imdb 28]}"
  1588.             }
  1589.             set message "$ioNJ(message_header_plain)"
  1590.             append message  "$mess"
  1591.             append message  "$ioNJ(message_footer)"
  1592.                 ## Change variables in messages
  1593.                 set message [string map $replacevar $message]
  1594.                 #
  1595.                 set exchange [regexp -all -inline {%fm([\-]?)([0-9]+)\{([^\{\}]+)\}} $message]
  1596.                 foreach {crap 1 2 replacing} $exchange {
  1597.                     if {![string is integer -strict $2]} { continue }
  1598.                         if {[string length $replacing] > $2} {
  1599.                             set replace [string range $replacing 0 [expr $2 - 1]]
  1600.                         } else {
  1601.                             set replace $replacing
  1602.                         }
  1603.                        
  1604.                     set message [string map [list "%fm$1$2\{$replacing\}" [format %${1}${2}s "$replace"]] $message]
  1605.                 }
  1606.                
  1607.             output $message
  1608.         }
  1609.        
  1610.        
  1611.         return
  1612.      
  1613.      
  1614.       }
  1615.       set make_time     [vfs chattr $path 11]
  1616.       set release_type  [vfs chattr $path 12]
  1617.       set total_files   [vfs chattr $path 13]
  1618.       set mv_info       [vfs chattr $path 14]
  1619.       set racestats     [readchattr 50]
  1620.       set present_files [llength $racestats]
  1621.       set sample        [readchattr 20]
  1622.       set mp3           [readchattr 25]
  1623.       set imdb      [readchattr 30]
  1624.       set total_size    0
  1625.       set total_speed   0
  1626.       set time          [vfs chattr $path 5]
  1627.       set user          [resolve uid $uid]
  1628.       set ugroup        [resolve gid $gid]
  1629.       set tagline       [get_uinfo $user tagline]
  1630.       set dir           [lindex [file split $pwd] end]
  1631.       set groupusers    ""
  1632.       set replacevar    ""
  1633.       set racers        ""
  1634.       set groups        ""
  1635.       set groupusers    ""
  1636.       set totalracers   ""
  1637.       set totalgroups   ""
  1638.      
  1639.      
  1640.       if {$make_time == ""} { return }
  1641.      
  1642.       if {$time == ""} {
  1643.         set time [expr $make_time + 100]
  1644.         catch {vfs chattr $path 5 $time}
  1645.       }
  1646.      
  1647.         #sort users and groups.
  1648.         foreach {io_fname io_crc io_user io_group io_fsize io_speed} [string trim [join $racestats]] {
  1649.             if {[set race_idx [lsearch -glob $racers $io_user]] == "-1"} {
  1650.                 lappend racers $io_user
  1651.                 lappend groupusers [list $io_user $io_group]
  1652.                 lappend total_racers "$io_user $io_group [format %.0f [expr ($io_fsize /1024.0)]] $io_speed 1 [expr 100 / $present_files]"
  1653.             } else {
  1654.                 set temp [lindex $total_racers $race_idx]
  1655.                 set temp_files [expr [lindex $temp 4] + 1]
  1656.                 set temp_size  [format %.0f [expr [lindex $temp 2] * 1.0 + ($io_fsize /1024.0)]]
  1657.                 set temp_speed [format %.0f [expr ([lindex $temp 3] + $io_speed) / 2]]
  1658.                 set temp_percent [expr ($temp_files * 100) / $present_files]
  1659.                 set total_racers [lreplace $total_racers $race_idx $race_idx "$io_user $io_group $temp_size $temp_speed $temp_files $temp_percent"]
  1660.             }
  1661.            
  1662.             if {[set g_race_idx [lsearch -glob $groups $io_group]] == "-1"} {
  1663.                 lappend groups $io_group
  1664.                 lappend total_groups "$io_group [format %.0f [expr ($io_fsize /1024.0)]] $io_speed 1 [expr 100 / $present_files]"
  1665.             } else {
  1666.                 set temp [lindex $total_groups $g_race_idx]
  1667.                 set temp_files [expr [lindex $temp 3] + 1]
  1668.                 set temp_size  [format %.0f [expr [lindex $temp 1] * 1.0 + ($io_fsize /1024.0)]]
  1669.                 set temp_speed [format %.0f [expr ([lindex $temp 2] + $io_speed) / 2]]
  1670.                 set temp_percent [expr ($temp_files * 100) / $present_files]
  1671.                 set total_groups [lreplace $total_groups $g_race_idx $g_race_idx "$io_group $temp_size $temp_speed $temp_files $temp_percent"]
  1672.             }
  1673.        
  1674.             set total_size  [format %.0f [expr $total_size * 1.0 + ($io_fsize /1024.0)]]
  1675.             set total_speed [expr $total_speed + $io_speed]
  1676.         }
  1677.        
  1678.         set temp_new_race_stats [lsort -decreasing -integer -index 2 "$total_racers"]
  1679.  
  1680.         set rtop 0
  1681.         foreach race_stat $temp_new_race_stats {
  1682.             incr rtop
  1683.             lappend totalracers "$rtop [lindex $race_stat 0] [lindex $race_stat 1] [lindex $race_stat 2] [lindex $race_stat 3] [lindex $race_stat 4] [lindex $race_stat 5]"
  1684.          }
  1685.    
  1686.         set temp_new_race_stats [lsort -decreasing -integer -index end-3 "$total_groups"]
  1687.         set gtop 0
  1688.         foreach race_stat $temp_new_race_stats {
  1689.             incr gtop
  1690.             lappend totalgroups "$gtop [lindex $race_stat 0] [lindex $race_stat 1] [lindex $race_stat 2] [lindex $race_stat 3] [lindex $race_stat 4]"
  1691.          }
  1692.    
  1693.    
  1694.    
  1695.         # get dirname and change it if it's a subdir. Mostley for announce purpose but also for groupname
  1696.                
  1697.         if {[regexp -nocase  $ioNJ(notparent) $dir]} {
  1698.             set sample [readparentchattr 20]
  1699.             set imdb [readparentchattr 30]
  1700.             set parent [lindex [file split $pwd] end-1]
  1701.             set subdir ${dir}
  1702.             set dir "${parent}"
  1703.         }
  1704.        
  1705.         lassign [get_stats] racer_dayup racer_wkup racer_mnup racer_allup
  1706.         set temp_racestats ""
  1707.         foreach race_stat $totalracers {
  1708.                 set dayup [expr [lsearch -glob $racer_dayup "[lindex $race_stat 1] *"] + 1]
  1709.             set wkup  [expr [lsearch -glob $racer_wkup "[lindex $race_stat 1] *"] + 1]
  1710.             set mnup  [expr [lsearch -glob $racer_mnup "[lindex $race_stat 1] *"] + 1]
  1711.             set allup [expr [lsearch -glob $racer_allup "[lindex $race_stat 1] *"] + 1]
  1712.             lappend temp_racestats "$race_stat $dayup $wkup $mnup $allup"
  1713.         }
  1714.         set totalracers $temp_racestats
  1715.         set racestats [lsort -increasing -integer -index end "$racestats"]
  1716.         lassign [lindex $racestats end] crap crap u_fastest_name u_fastest_gname crap u_fastest_speed
  1717.         lassign [lindex $racestats 0] crap crap u_slowest_name u_slowest_gname crap u_slowest_speed
  1718.         append replacevar " %u_slowest_name {$u_slowest_name} %u_slowest_gname {$u_slowest_gname} %u_slowest_speed {[format_speed $u_slowest_speed]} %u_fastest_name {$u_fastest_name} %u_fastest_gname {$u_fastest_gname} %u_fastest_speed {[format_speed  $u_fastest_speed]}"
  1719.            
  1720.        
  1721.         # MP3INFO
  1722.           if {$mp3 != ""} {
  1723.             append replacevar "  %audio_artist {[lindex $mp3 0]} %audio_album {[lindex $mp3 1]} %audio_title {[lindex $mp3 2]} %audio_bitrate {[lindex $mp3 3]} %audio_mpeglayer {MPEG [lindex $mp3 4] Layer [lindex $mp3 5]} %audio_chanmode {[lindex $mp3 6]} %audio_genre {[lindex $mp3 7]} %audio_year {[lindex $mp3 8]} %audio_samplerate {[lindex $mp3 9]} %audio_lame_version {[lindex $mp3 10]} %audio_lame_preset {[lindex $mp3 11]} %audio_original {[lindex $mp3 12]} %audio_padding {[lindex $mp3 13]} %audio_duration {[lindex $mp3 14]} %audio_track_nr {[lindex $mp3 15]} %audio_vbr_old_or_new {[lindex $mp3 17]} %audio_vbr {[lindex $mp3 16]}"
  1724.           }
  1725.    
  1726.         # IMDB INFO
  1727.         if {$imdb != ""} {
  1728.                 append replacevar " %imdb_title {[lindex $imdb 0]} %imdb_url {[lindex $imdb 1]} %imdb_year {[lindex $imdb 2]} %imdb_tv {[lindex $imdb 3]} %imdb_liftime {[lindex $imdb 4]} %imdb_ratbar {[lindex $imdb 5]} %imdb_rating {[lindex $imdb 6]} %imdb_votes {[lindex $imdb 7]} %imdb_director {[lindex $imdb 8]} %imdb_cast {[lindex $imdb 9]} %imdb_mpaa {[lindex $imdb 10]} %imdb_runtime {[lindex $imdb 11]} %imdb_country {[lindex $imdb 12]} %imdb_language {[lindex $imdb 13]} %imdb_color {[lindex $imdb 14]} %imdb_genre {[lindex $imdb 15]} %imdb_tagline {[lindex $imdb 16]} %imdb_plot {[lindex $imdb 17]} %imdb_usercomment {[lindex $imdb 18]} %imdb_awards {[lindex $imdb 19]} %imdb_opengross {[lindex $imdb 20]} %imdb_opencountry {[lindex $imdb 21]} %imdb_openday {[lindex $imdb 22]} %imdb_openyear {[lindex $imdb 23]} %imdb_openscreens {[lindex $imdb 24]} %imdb_screens {[lindex $imdb 25]} %imdb_budget {[lindex $imdb 26]} %imdb_top250 {[lindex $imdb 27]} %imdb_limited {[lindex $imdb 28]}"
  1729.         }
  1730.        
  1731.         # MV_INFO
  1732.           if {$mv_info != ""} {
  1733.             append replacevar " %mv_genre {[lindex $mv_info 0]} %mv_artist {[lindex $mv_info 1]} %mv_year {[lindex $mv_info 2]} %mv_title {[lindex $mv_info 3]}"
  1734.           }
  1735.    
  1736.         #SAMPLE INFO
  1737.           if {$sample != ""} {     
  1738.             append replacevar " %video_codec {[lindex $sample 0]} %video_framerate {[lindex $sample 1]} %video_bitrate {[lindex $sample 2]} %video_height {[lindex $sample 3]} %video_width {[lindex $sample 4]} %video_aspect_ratio {[lindex $sample 5]} %video_audio_codec {[lindex $sample 6]} %video_audio_bitrate_mode {[lindex $sample 8]} %video_audio_bitrate {[lindex $sample 7]}  %video_audio_chans {[lindex $sample 9]} %video_audio_samplerate {[lindex $sample 10]} %video_audio_resolution {[lindex $sample 11]}"
  1739.             set release_type "VIDEO"
  1740.          }
  1741.    
  1742.         #Set the progressbar
  1743.         if {$present_files != 0 && $total_files != 0} {
  1744.             set progsigns [format %.0f [expr ($present_files * [string length $ioNJ(charbar_filled)])/$total_files]]
  1745.             if {$progsigns == 0} {
  1746.                 set pbar $ioNJ(charbar_missing)
  1747.             } else {
  1748.                 set pbar [string range $ioNJ(charbar_filled) 0 [expr $progsigns - 1]]
  1749.                 set pbar "$pbar[string range $ioNJ(charbar_missing) $progsigns end]"
  1750.             }
  1751.    
  1752.         } else {
  1753.             set pbar $ioNJ(charbar_missing)
  1754.         }
  1755.    
  1756.    
  1757.     set durtimestamp [expr $time - $make_time]
  1758.     if {$durtimestamp == 0} { set durtimestamp 1 }
  1759.     set duration $durtimestamp
  1760.     set missingfiles [expr $total_files - $present_files]
  1761.     set percentdone [format %.1f [expr ((100.0 /$total_files) * $present_files)]]
  1762.     set percentleft [format %.1f [expr 100 - $percentdone]]
  1763.     set avgspeed [format %.0f [expr $total_size / $durtimestamp]]
  1764.     if {$avgspeed == 0} { set avgspeed 1 }
  1765.     set a_avgspeed [format %.0f [expr $total_size / $durtimestamp]]
  1766.     set r_avgspeed [expr $total_speed / $present_files]
  1767.     lassign [lindex $totalracers 0] crap u_winner_name  u_winner_gname u_winner_mbytes u_winner_avgspeed u_winner_files u_winner_percent
  1768.     lassign [lindex $totalgroups 0] crap g_winner_name g_winner_mbytes g_winner_avgspeed g_winner_files g_winner_percent
  1769.     set winner_idx [lsearch -glob $groupusers "$u_winner_name *"]
  1770.     set lead_groupusers [lreplace $groupusers $winner_idx $winner_idx]
  1771.     set user_idx   [lsearch -glob $groupusers "$user *"]
  1772.     set groupusers [lreplace $groupusers $user_idx $user_idx]
  1773.     set a_groupusers $groupusers
  1774.     if {$groupusers == ""} { set groupusers "NoOne NoGroup"}
  1775.     if {$total_files != $present_files } { set eta [format %.0f [expr (($total_size / $present_files) * $missingfiles) / $avgspeed]] } else { set eta 0 }
  1776.     set total_size [format %.0f $total_size]
  1777.     set esize [format %.0f [expr ($total_size / $present_files * [format %.1f $total_files])]]
  1778.     set tempesize [format %.0f [expr $esize / 1024.0]]
  1779.        
  1780.    
  1781.     append replacevar " %ioNiNJA_VER $ioNJ(VER) %sitename {$ioNJ(ssn)} %racers {$racers} %complete_eta \"[duration $eta]\" %percentdone {$percentdone} %rtop {$rtop} %gtop {$gtop} %release {$dir} %total_files {$total_files} %files_uploaded {$present_files} %missing_files {$missingfiles} %estimated_size [format_size $esize] %total_size \"[format_size $total_size]\" %average_speed \"[format_speed $a_avgspeed]\" %race_duration \"[duration $duration]\" %r_avg_speed \"[format_speed $r_avgspeed]\" %progress_bar {$pbar} %time {[clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]}"
  1782.    
  1783.     set message "$ioNJ(message_header)"
  1784.     if {$ioNJ(show_user_info)} {
  1785.         append message $ioNJ(message_user_header)
  1786.         foreach {rtop raceuser racegroup racesize racespeed racefiles racepercent dayup wkup mnup allup} [join $totalracers] {
  1787.             append message [string map [list %race_user_dayup $dayup %race_user_wkup $wkup %race_user_mnup $mnup %race_user_allup $allup %race_user_position $rtop %race_user_name $raceuser %race_user_group $racegroup %race_user_files $racefiles %race_user_size [format_size $racesize] %race_user_percent $racepercent %race_user_speed [format_speed $racespeed]] $ioNJ(message_user_body)]
  1788.         }
  1789.         append message "$ioNJ(message_user_footer)"
  1790.     }
  1791.    
  1792.     if {$ioNJ(show_group_info)} {
  1793.         append message "$ioNJ(message_group_header)"
  1794.         foreach {gtop rgroup gracesize gracespeed gracefiles gracepercent} [join $totalgroups] {
  1795.             append message [string map [list %race_group_position $gtop %race_group_name $rgroup %race_group_files $gracefiles %race_group_size [format_size $gracesize] %race_group_percent $gracepercent %race_group_speed [format_speed $gracespeed]] $ioNJ(message_group_body)]
  1796.         }
  1797.         append message  "$ioNJ(message_group_footer)"
  1798.     }
  1799.     if {$mp3 != ""} {
  1800.         append message "$ioNJ(message_mp3)"
  1801.     }
  1802.     if {$sample != ""} {
  1803.         append message  "$ioNJ(message_sample)"
  1804.     }
  1805.     if {$mv_info != ""} {
  1806.         append message  "$ioNJ(message_mv)"
  1807.     }
  1808.     if {$imdb != ""} {
  1809.         append message  "$ioNJ(message_imdbinfo)"
  1810.     }
  1811.    
  1812.     append message  "$ioNJ(message_footer)"
  1813.     if {[vfs chattr $path 3] == 1 && $ioNJ(custom_group_dirs_complete_message) != ""} {
  1814.         if {[file exists $ioNJ(custom_group_dirs_complete_message)]} {
  1815.             set message  [readfile $ioNJ(custom_group_dirs_complete_message)]
  1816.         }
  1817.     }
  1818.    
  1819.    
  1820.     ## Change variables in messages
  1821.     set message [string map $replacevar $message]
  1822.     #
  1823.     set exchange [regexp -all -inline {%fm([\-]?)([0-9]+)\{([^\{\}]+)\}} $message]
  1824.     foreach {crap 1 2 replacing} $exchange {
  1825.         if {![string is integer -strict $2]} { continue }
  1826.             if {[string length $replacing] > $2} {
  1827.                 set replace [string range $replacing 0 [expr $2 - 1]]
  1828.             } else {
  1829.                 set replace $replacing
  1830.             }
  1831.            
  1832.         set message [string map [list "%fm$1$2\{$replacing\}" [format %${1}${2}s "$replace"]] $message]
  1833.     #r4nd0m Changes
  1834.     set propercwd "250-"
  1835.     append propercwd $message  
  1836.     }
  1837.    
  1838.     #r4nd0m Changes - Output variable used to be $message
  1839.     output $propercwd
  1840.    
  1841.    
  1842.    
  1843. return
  1844. }
  1845.  
  1846.  
  1847. #######################
  1848. ## Resort
  1849. #######################
  1850. proc ::ioNiNJA::resort {} {global pwd path args ioNJ
  1851.  
  1852.     if {[regexp -nocase {mp3|imdb|tv|mv|xxx} [lindex $args 1]]} {
  1853.         set type [string toupper [lindex $args 1]]
  1854.         set paths [join [get_mountpoints]]
  1855.         set new_dirs [list $path $pwd]
  1856.         set basedirs [join [join [get_mountpoints]] |]
  1857.         set nr 0
  1858.         while {[lindex $paths $nr] != ""} {
  1859.             set temp [glob -nocomplain -type d -directory [lindex $paths $nr] "*"]
  1860.             foreach dir $temp {
  1861.                 lappend paths $dir
  1862.                 iputs -nobuffer "Reading: $dir"
  1863.                 lappend new_dirs $dir  [file join [regsub -nocase $basedirs $dir $pwd]]
  1864.             }
  1865.             incr nr
  1866.         }
  1867.         unset paths
  1868.  
  1869.         foreach {temp_dir temp_pwd} $new_dirs {
  1870.             output "RESORT $type: [file tail $temp_dir]"
  1871.             set pwd  $temp_pwd
  1872.             set path $temp_dir
  1873.             if {$type == "MP3"} {
  1874.                 set temp_mp3 [lindex [glob -nocomplain -type f -directory $temp_dir "*.mp3"] 0]
  1875.                 if {$temp_mp3 != ""} {
  1876.                     catch {vfs chattr $path 25 ""}
  1877.                     get_mp3_information "$temp_mp3"
  1878.                     ::ioNiNJA::MP3::Main
  1879.                 }
  1880.             } elseif {$type == "IMDB"} {
  1881.                 catch {vfs chattr $path 30 ""}
  1882.                 iMDB::imdb_readnfo
  1883.             } elseif {$type == "TV"} {
  1884.                 ioTV::MKD
  1885.             } elseif {$type == "XXX"} {
  1886.                 xxxInfo::get_xxx_info
  1887.             } elseif {$type == "MV"} {
  1888.                 MvInfo::get_mv_info
  1889.             }
  1890.         }
  1891.        
  1892.     } else {
  1893.         output $ioNJ(resort_help)
  1894.     }
  1895.    
  1896. }
  1897.  
  1898.  
  1899. ####
  1900. ## DELETE OLD BARS
  1901. ####
  1902. proc ::ioNiNJA::del_old_bars {} {global ioNJ pwd path
  1903.     set oldfiles [glob -nocomplain -directory "$path" "[string map { \[ \\[ \] \\]} $ioNJ(del_progressmeter)]"]
  1904.     foreach progeta $oldfiles { catch {file delete -force "$progeta"} }
  1905.     set oldfiles [glob -nocomplain -directory "$path" "[string map { \[ \\[ \] \\]} $ioNJ(del_completebar)]"]
  1906.     foreach progeta $oldfiles {catch {file delete -force "$progeta"} }
  1907.     return
  1908. }
  1909.  
  1910.  
  1911.  
  1912. ###
  1913. # Get Mountpoints from vfs file
  1914. ###
  1915. proc ::ioNiNJA::get_mountpoints {} {global pwd
  1916.  
  1917.     set wp ""
  1918.     foreach {vp rp} [mountpoints] {
  1919.         if {[regexp -nocase "^[string range $pwd 0 end-1]" $vp]} {
  1920.             lappend wp $rp
  1921.         }
  1922.        
  1923.     }
  1924.    
  1925.     if {$wp != ""} { return $wp }
  1926.    
  1927.     return [resolve pwd $pwd]
  1928. }
  1929.  
  1930.  
  1931.  
  1932. #######################
  1933. ## Rescan
  1934. #######################
  1935.  
  1936. proc ::ioNiNJA::rescan {} {global pwd path args ioNJ speed
  1937.  
  1938.  
  1939.     regsub -all {\\} $path {/} path
  1940.    
  1941.     if {[regexp -nocase "all" [lindex $args 1]]} {
  1942.         set type [string tolower [lindex $args 1]]
  1943.         set paths [join [get_mountpoints]]
  1944.         set new_dirs ""
  1945.         set basedirs [join [join [get_mountpoints]] |]
  1946.         set nr 0
  1947.         while {[lindex $paths $nr] != ""} {
  1948.             set temp [glob -nocomplain -type d -directory [lindex $paths $nr] "*"]
  1949.             foreach dir $temp {
  1950.                 lappend paths $dir
  1951.                 iputs -nobuffer "Reading: $dir"
  1952.                 lappend new_dirs $dir  [file join [regsub -nocase $basedirs $dir $pwd]]
  1953.             }
  1954.             incr nr
  1955.         }
  1956.         unset paths
  1957.        
  1958.     } elseif {[regexp -nocase "this" [lindex $args 1]]} {
  1959.         set new_dirs ""
  1960.         lappend new_dirs $path $pwd
  1961.     } else {
  1962.         output $ioNJ(rescan_help)
  1963.         return
  1964.     }
  1965.    
  1966.    
  1967.     foreach {path pwd} $new_dirs {
  1968.             iputs -nobuffer "RESCAN: [file tail $pwd]"
  1969.             writechattr 5 ""
  1970.             writechattr 9 ""
  1971.             writechattr 10 ""
  1972.             writechattr 11 [clock seconds]
  1973.             writechattr 13 0
  1974.             writechattr 14 ""
  1975.             erasechattr 25
  1976.             erasechattr 57
  1977.             erasechattr 30
  1978.             erasechattr 35
  1979.             erasechattr 50
  1980.             del_old_bars           
  1981.             foreach file [glob -nocomplain -type f -directory $path "*${ioNJ(missingtag)}"] { catch {file delete -force -- "$file"} }
  1982.             set temp [glob -nocomplain -type f -directory $path "*"]
  1983.             if {[set nfo_f [lsearch -glob $temp *.nfo]] != "-1"} {
  1984.                 set temp_nfo [lindex $temp $nfo_f]
  1985.                 set temp [lreplace $temp $nfo_f $nfo_f]
  1986.                 set temp [linsert $temp 0 $temp_nfo]
  1987.             }
  1988.             if {[set sfv_f [lsearch -glob $temp *.sfv]] != "-1"} {
  1989.                 set temp_sfv [lindex $temp $sfv_f]
  1990.                 set temp [lreplace $temp $sfv_f $sfv_f]
  1991.                 set temp [linsert $temp 0 $temp_sfv]
  1992.            
  1993.             }
  1994.             set passed_f 0
  1995.             set failed_f 0
  1996.             set passed_size 0
  1997.             set failed_size 0
  1998.             foreach file $temp {
  1999.                 set speed 2000
  2000.                 if {![file exists $file]} { continue }
  2001.                 set fsize [file size $file]
  2002.                 lassign [vfs read $file] uid gid crap
  2003.                 set vf  [file join [regsub -nocase $path $file $pwd]]
  2004.                 set crc [format %08X [crc32 $file]]
  2005.                 set args [list 1 $file $crc $vf]
  2006.                 ZipScript::ZipScript 1 $file $crc $vf
  2007.                 if {![file exists $file]} {
  2008.                     set passed_size [expr $fsize + $passed_size]
  2009.                     incr passed_f
  2010.                     iputs -nobuffer "FAiLED: [file tail $file]"
  2011.                 } else {
  2012.                     set failed_size [expr $fsize + $failed_size]
  2013.                     incr failed_f
  2014.                     iputs -nobuffer "PASSED: [file tail $file]"
  2015.                 }
  2016.  
  2017.             }
  2018.            
  2019.         put_log [list RESCAN: $pwd $passed_f $passed_size $failed_f $failed_size]
  2020.     }
  2021.    
  2022. }
  2023.  
  2024. proc ::ioNiNJA::njver {} {global ioNJ
  2025.     output "Running ioNiNJA $ioNJ(VERLONG)"
  2026. }
Add Comment
Please, Sign In to add comment