#!/usr/bin/env python
# Copyright (c) 2008, Jeremy Grosser
# Open source under New BSD License. See LICENSE file for details
# Where the patterns and downloaded files are stored
RSSNZB_DIR = '/etc/rssnzb'
# Where to put downloaded NZB files
DOWNLOAD_DIR = '/mnt/media/upload'
from urllib import urlretrieve
from xmlrpclib import ServerProxy
from time import sleep
import feedparser
import re
dl = open('%s/downloaded' % RSSNZB_DIR, 'r')
downloaded = []
for line in dl.readlines():
downloaded.append(line[:-1])
dl.close()
def download_nzbs(url, hella):
feed = feedparser.parse(url)
for entry in feed['entries']:
if entry['report_progress'] == 'Report is complete' and not entry['report_id'] in downloaded:
print 'Downloading %s' % (entry.title)
hella.enqueuenewzbin(int(entry['report_id']))
file('%s/downloaded' % RSSNZB_DIR, 'a').write('%s\n' % entry['report_id'])
sleep(1)
#nzb = file('%s/%s.nzb' % (DOWNLOAD_DIR, entry.title), 'w')
#query = {
# 'reportid': str(entry['report_id']),
#}
#nzb.write(directnzb(query)[1])
#nzb.close()
def main():
hella = ServerProxy('http://hellanzb:massive@localhost:8760/')
for url in file('%s/savedsearches' % RSSNZB_DIR).readlines():
url = url.rstrip('\r\n')
download_nzbs(url, hella)
if __name__ == '__main__':
main()