Show newest NZBs in Conky

This script will prepare a text file containing the latest posts in nzbserver.com for reading in Conky.

nzb2conky

Here’s the Conky script I use for displaying the information:

# General
background no
alignment bottom_right
no_buffers yes
out_to_stderr no
update_interval 60
double_buffer yes

# Font
font ubuntu:size=8
xftfont ubuntu:size=8
use_xft yes
draw_outline no
draw_shades no
override_utf8_locale yes

TEXT
${hr}
${execp sed '1!d' nzbs.txt}
${execp sed '2!d' nzbs.txt}
${execp sed '3!d' nzbs.txt}
${execp sed '4!d' nzbs.txt}
${execp sed '5!d' nzbs.txt}
${execp sed '6!d' nzbs.txt}
${execp sed '7!d' nzbs.txt}
${execp sed '8!d' nzbs.txt}
${execp sed '9!d' nzbs.txt}
${execp sed '10!d' nzbs.txt}
${color lightgrey}${alignr}Updated: ${exec stat -c %y nzbs.txt | cut -d . -f 1}

Note that I have Conky update every 60 seconds. The source information doesn’t change that quickly.

Because of the length of the titles it is probably a good idea to put this in a Conky of its own.

This version marks scifi films in green.

If you have any suggestions for improvement please do leave them in the comments. I wrote this script mainly for trying my hand at screenscraping in Linux.

This script uses recode to recode html (e.g. replace “& a m p ;” with “&”). I had to install recode first by doing

aptitude install recode

Schedule with

crontab -e

.

Here’s the script. It probably needs some more error handling.

#!/bin/bash

# Directory to work from
cd /home/vorkbaard/conky/

# Number of results
results=10

# This is my custom filter. Read nzbserver.com's documentation
# to create your own. This shows all hd movies except in the genres:
# music;musical;sports;war.

nzburl="http://www.nzbserver.com/?page=index&search[tree]=cat0_z0_a9,cat0_z0_d12,cat0_z0_d13,cat0_z0_d14,cat0_z0_d18,cat0_z0_d21i%2C&sortby=stamp&sortdir=DESC"

echo Download info from nzbserver.com
wget -O raw.txt $nzburl
# Wait for download to complete
wait

echo Cut out the interesting lines
cat raw.txt | head -198 | tail -$results > code.txt

echo Retrieve title from code
cat code.txt | cut -d \> -f 8 | cut -d \< -f 1 > titles.txt

echo Retrieve genre from code
# NOTE: THE FOLLOWING MUST BE ON ONE LINE (cat ... genres.txt)
cat code.txt | cut -d { -f 2 | cut -d } -f 1 | sed 's/.*.Genre":"//' | sed 's/","Type":"Movie"//' > genres.txt

echo Combine genres with titles
paste --delimiters=\| titles.txt genres.txt > nzbstemp.txt

echo Clean up the text a bit
# Add spaces around pipe between title and genre
sed -i 's/|/ | /g' nzbstemp.txt
# Replace html by ascii code
recode html nzbstemp.txt

# I want all Science fiction films to show up green in Conky
# Delete fmtnzb file if it exist
if [ -e fmtnzb.txt ]; then
  rm fmtnzb.txt
fi

while read film; do
 if [ "${film/Science\ Fiction}" = "$film" ] ; then
   # regular film
   echo $film | sed 's/^/\${alignr}/' >> fmtnzb.txt
 else
   # Science fiction film
   film="$film\${color}"
   echo $film | sed 's/^/\${color green}\${alignr}/' >> fmtnzb.txt
 fi
done < nzbstemp.txt

# Copy new nzbs to Conky
mv fmtnzb.txt nzbs.txt

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top