Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/gawk -f
- # info.awk
- # parser for output from `deluge-console info`
- # directory structure:
- # ./info.awk
- # ./webserver/htdocs/status.awk
- # ./torrents/*.torrent (configured for torrent storage in deluge)
- # ./storage/*.* (configured for download in deluge)
- # ./webserver/htdocs/storage -> ../../storage (link)
- # ./webserver/htdocs/torrents -> ../../torrents (link)
- BEGIN {
- numtorr = 0
- Name = "Name"
- ID = "ID"
- State = "State"
- Progress = "Progress"
- host = "\\\\host-name"
- dir = "torrents/"
- files = "storage/"
- }
- /^ $/ { numtorr++ }
- /Name:/ { torr[numtorr, Name] = $2 }
- /ID:/ { torr[numtorr, ID] = $2 }
- /State:/ { torr[numtorr, State] = $2 }
- /Progress:/ { torr[numtorr, Progress] = $2 }
- function output_header() {
- print "Content-Type: text/html"
- print ""
- print "<html>"
- print "<head>"
- print "<title>Deluge Torrent List for " host "</title>"
- print "<link rel=\"stylesheet\" href=\"style.awk\" />"
- print "</head>"
- print "<body>"
- print "<p>Files List</p>"
- print "<hr />"
- print "<table>"
- print "<tr>"
- print "<th>Download Title (link to file)</th>" \
- "<th>Transfer Status (Progress%)</th>"
- print "</tr>"
- }
- function rowclass() {
- if( _rowclass == "odd" ) _rowclass = "even"
- else _rowclass = "odd"
- return _rowclass
- }
- function output_torr( _t ) {
- print "<tr class=\"" rowclass() "\">"
- print "<td class=\"title\">"
- _st = torr[_t, State]
- if ( torr[_t, Progress] == "" )
- print "<a href=\"" files torr[_t, Name] "\">" torr[_t, Name] "</a>"
- else
- print torr[_t, Name]
- print "</td>"
- print "<td class=\"progress\">"
- print "<a href=\"" dir torr[_t, ID] ".torrent\">" \
- torr[_t, State] "</a>" \
- " (" torr[_t, Progress] ")"
- print "</td>"
- print "</tr>"
- }
- function output_tail() {
- print "</table>"
- print "</body>"
- print "</html>"
- }
- function sort_torr() {
- for( t = 1; t <= numtorr; t++ ) {
- stor[ t ] = torr[t,Name]
- _names[torr[t,Name]] = t
- }
- asort( stor )
- for( t = 1; t <= numtorr; t++ ) {
- stor[t] = _names[stor[t]]
- }
- }
- END {
- output_header()
- sort_torr()
- for ( t = 1; t <= numtorr; t++ ) {
- output_torr( stor[t] )
- }
- output_tail()
- }
Add Comment
Please, Sign In to add comment