Advertisement
McLovin

torrent-status.sh

Sep 10th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. #trim torrent name to this many characters
  4. trim=30
  5.  
  6. #more settings further down marked with ========================
  7.  
  8.  
  9. #get listing of all torrent info from transmission
  10. # NOTE: you need to install transmission-cli AND UNINSTALL transmission-daemon
  11. alltorrents=$(transmission-remote -l | sed -n -e '$b' -e '2,$p')
  12.  
  13.  
  14. n=$(echo "$alltorrents" | wc -l)
  15.  
  16.  
  17. #parse output to get data
  18. #DO NOT EDIT THIS BIT
  19. for i in `seq $n`
  20. do
  21. torrent[$i]=$(echo "$alltorrents" | sed -n ''$i'p' | sed 's/ */\//g')
  22.  
  23. progress[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $3}' | sed 's/%//')
  24. percent[$i]=$(echo 'scale=2; '${progress[$i]}'/100' | bc)
  25. have[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $4}')
  26. eta[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $5}')
  27. up[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $6}')
  28. down[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $7}')
  29. ratio[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $8}')
  30. status[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $9}')
  31. name[$i]=$(echo ${torrent[$i]} | awk -F/ '{print $10}' )
  32. #trim and add ellipsis if too long
  33. if [ `echo ${name[$i]} | wc -m` -gt $trim ]
  34. then
  35.  
  36. name[$i]=$(echo ${name[$i]} | cut -c -$trim)...
  37. fi
  38. done
  39.  
  40. #convert status to symbols
  41.  
  42.  
  43. #output data to conky, using standard conky formating
  44.  
  45. #some more settings=====================================================
  46. #=======================================================================
  47.  
  48. #limit output to a certain number of torrents, all is a=$n first four is a=4 etc
  49. a=$n
  50.  
  51. #progress bar length from right edge of conky
  52. barlength=80
  53.  
  54. #change colours of listing depending on status and/or add icons
  55. # icons are webding fonts eg pause symbol, down arrow etc
  56. #CHANGE COLORS TO DESIRED OR COMMENT OUT IF NO COLORS WANTED
  57. #movedown=$(echo '14*'$n | bc)
  58. #echo '${voffset -'$movedown'}'
  59.  
  60. for i in `seq $a`
  61. do
  62. case ${status[$i]} in
  63. "Idle")
  64. icon[$i]='${font Webdings};${font}'
  65. color[$i]="B7B7B7"
  66. ;;
  67. "Stopped")
  68. icon[$i]='${font Webdings}<${font}'
  69. color[$i]="B7B7B7"
  70. ;;
  71. "Up & Down")
  72. icon[$i]='${font Webdings}6${font}'
  73. #color[$i]=
  74. ;;
  75. "Downloading")
  76. icon[$i]='${font Webdings}6${font}'
  77. #color[$i]=
  78. ;;
  79. "Seeding")
  80. icon[$i]='${font Webdings}5${font}'
  81. color[$i]='FFFFFF'
  82. ;;
  83. *)
  84. ;;
  85. esac
  86.  
  87. #test to check we actually got some data back
  88. if [ -z "$alltorrents" ]
  89. then echo "Can't connect to transmission"
  90. #if not, print error message if you like, and exit
  91. #echo "Can't connect to transmission"
  92. exit
  93. fi
  94. #===================================================================
  95.  
  96. #EDIT THE FOLLOWING BIT TO CONTROL DATA SEEN IN CONKY
  97. #enclose conky commands with ' '
  98. #enclose variables from this script with " " or nothing
  99. #in form ${name[$i]} where $i refers to the torrent number
  100. #possible variables are:
  101. # progress number 1-100 how much downloaded eg "45"
  102. # percent same but 0-1 eg "0.45"
  103. # have amount downloaded as string eg "4.1 GB"
  104. # eta estimated time of arrival as string eg "4 hrs"
  105. # up transfer rate up in KB/s eg "21.1"
  106. # down transfer rate down in KB/s eg "21.1"
  107. # ratio transfer ratio for torrent eg "0.88"
  108. # status eg "Downloading"
  109. # icon a small icon indicating status (see above
  110. # section)
  111. # color color depending on status (see above section)
  112. # eg "FF88AA" NB: must use exactly the format:
  113. # '${color '${color[$i]}'}' to apply the color to
  114. # a stretch of text, and remember to end it with
  115. # '${color}'
  116. # to draw the progress bar, use the exact command (incl single
  117. # quotes) '${execbar echo '${percent[%i]'}' and control the
  118. # length with '${alignr '$barlength'}' where barlength defined above
  119.  
  120.  
  121.  
  122. echo '$color7}'${icon[$i]}'${font Santana:style=bold:size=10}'"${name[$i]}" is Currently: '${color9}'${status[$i]}'${font Santana:size=0}''${color}'
  123. echo '${voffset -2}''${font}${hr 1}'
  124. echo Progress: '${font Santana:style=bold:size=10}''${color9}'${progress[$i]}%: '${font}${execbar echo '${progress[$i]}'}' '${color}'
  125. echo Downloaded:'${font Santana:style=bold:size=10}''${color9}' ${have[$i]} '${color}' '${font}''${goto 195}' Time Left:'${color9}' '${font Santana:style=bold:size=10}'"${eta[$i]}" '${color}''${font}''${goto 1}'
  126. echo U-L Speed: '${font Santana:style=bold:size=10}''${color #FF6754}'"${up[$i]}"Kb/s '${font}' '${color}' '${goto 200}'D-L Speed: '${font Santana:style=bold:size=10}''${color #3E8847}'"${down[$i]}"Kb/s'${font}' '${color}''${goto 1}'
  127. echo Share Ratio: '${font Santana:style=bold:size=10}''${color9}'${ratio[$i]}'${color}'
  128. echo '${voffset -8}''${color9}''${hr 1}'
  129. #===================================================================
  130. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement