2
from flexget.plugin import register_plugin, priority, DependencyError
4
log = logging.getLogger('nzb_size')
6
# a bit hacky, add nzb as a known mimetype
8
mimetypes.add_type('application/x-nzb', '.nzb')
14
Provides entry size information when dealing with nzb files
18
def on_feed_modify(self, feed):
20
The downloaded file is accessible in modify phase
23
from pynzb import nzb_parser
25
# TODO: remove builtin status so this won't get repeated on every feed execution
26
# TODO: this will get loaded even without any need for nzb
27
raise DependencyError(issued_by='nzb_size', missing='lib pynzb')
29
for entry in feed.accepted:
30
if entry.get('mime-type', None) in [u'text/nzb', u'application/x-nzb'] or \
31
entry.get('filename', '').endswith('.nzb'):
33
if 'file' not in entry:
34
log.warning('%s does not have a to get size from' % entry['title'])
37
filename = entry['file']
38
log.debug('reading %s' % filename)
39
xmldata = file(filename).read()
42
nzbfiles = nzb_parser.parse(xmldata)
44
log.debug('%s is not a valid nzb' % entry['title'])
48
for nzbfile in nzbfiles:
49
for segment in nzbfile.segments:
52
size_mb = size / 1024 / 1024
53
log.debug('%s content size: %s MB' % (entry['title'], size_mb))
54
entry['content_size'] = size_mb
56
log.trace('%s does not seem to be nzb' % entry['title'])
59
register_plugin(NzbSize, 'nzb_size', builtin=True)