Guest User

Untitled

a guest
Jun 21st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #!/usr/bin/gawk -f
  2.  
  3. # info.awk
  4. # parser for output from `deluge-console info`
  5. # directory structure:
  6. # ./info.awk
  7. # ./webserver/htdocs/status.awk
  8. # ./torrents/*.torrent (configured for torrent storage in deluge)
  9. # ./storage/*.* (configured for download in deluge)
  10. # ./webserver/htdocs/storage -> ../../storage (link)
  11. # ./webserver/htdocs/torrents -> ../../torrents (link)
  12.  
  13. BEGIN {
  14. numtorr = 0
  15. Name = "Name"
  16. ID = "ID"
  17. State = "State"
  18. Progress = "Progress"
  19. host = "\\\\host-name"
  20. dir = "torrents/"
  21. files = "storage/"
  22. }
  23. /^ $/ { numtorr++ }
  24.  
  25. /Name:/ { torr[numtorr, Name] = $2 }
  26. /ID:/ { torr[numtorr, ID] = $2 }
  27. /State:/ { torr[numtorr, State] = $2 }
  28. /Progress:/ { torr[numtorr, Progress] = $2 }
  29.  
  30. function output_header() {
  31. print "Content-Type: text/html"
  32. print ""
  33.  
  34. print "<html>"
  35. print "<head>"
  36. print "<title>Deluge Torrent List for " host "</title>"
  37. print "<link rel=\"stylesheet\" href=\"style.awk\" />"
  38. print "</head>"
  39. print "<body>"
  40.  
  41. print "<p>Files List</p>"
  42. print "<hr />"
  43.  
  44. print "<table>"
  45. print "<tr>"
  46. print "<th>Download Title (link to file)</th>" \
  47. "<th>Transfer Status (Progress%)</th>"
  48. print "</tr>"
  49. }
  50.  
  51. function rowclass() {
  52. if( _rowclass == "odd" ) _rowclass = "even"
  53. else _rowclass = "odd"
  54. return _rowclass
  55. }
  56.  
  57. function output_torr( _t ) {
  58. print "<tr class=\"" rowclass() "\">"
  59. print "<td class=\"title\">"
  60.  
  61. _st = torr[_t, State]
  62. if ( torr[_t, Progress] == "" )
  63. print "<a href=\"" files torr[_t, Name] "\">" torr[_t, Name] "</a>"
  64. else
  65. print torr[_t, Name]
  66.  
  67. print "</td>"
  68. print "<td class=\"progress\">"
  69.  
  70. print "<a href=\"" dir torr[_t, ID] ".torrent\">" \
  71. torr[_t, State] "</a>" \
  72. " (" torr[_t, Progress] ")"
  73. print "</td>"
  74. print "</tr>"
  75. }
  76.  
  77. function output_tail() {
  78. print "</table>"
  79. print "</body>"
  80. print "</html>"
  81. }
  82.  
  83. function sort_torr() {
  84. for( t = 1; t <= numtorr; t++ ) {
  85. stor[ t ] = torr[t,Name]
  86. _names[torr[t,Name]] = t
  87. }
  88. asort( stor )
  89. for( t = 1; t <= numtorr; t++ ) {
  90. stor[t] = _names[stor[t]]
  91. }
  92. }
  93.  
  94. END {
  95. output_header()
  96.  
  97. sort_torr()
  98.  
  99. for ( t = 1; t <= numtorr; t++ ) {
  100. output_torr( stor[t] )
  101. }
  102. output_tail()
  103. }
Add Comment
Please, Sign In to add comment