synack / rssnzb

Download NZBs from an RSS feed

This URL has Read+Write access

rssnzb / ssnzb.py
100755 48 lines (38 sloc) 1.434 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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()