def NZBDownloadMethod(bookid=None, nzbprov=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() if (lazylibrarian.NZB_DOWNLOADER_SABNZBD and lazylibrarian.SAB_HOST) and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: download = sabnzbd.SABnzbd(nzbtitle, nzburl) elif (lazylibrarian.NZB_DOWNLOADER_NZBGET and lazylibrarian.NZBGET_HOST) and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: headers = {'User-Agent': USER_AGENT} data = request.request_content(url=nzburl, headers=headers) nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl download = nzbget.sendNZB(nzb) elif lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: try: req = urllib2.Request(nzburl) if lazylibrarian.PROXY_HOST: req.set_proxy(lazylibrarian.PROXY_HOST, lazylibrarian.PROXY_TYPE) req.add_header('User-Agent', USER_AGENT) nzbfile = urllib2.urlopen(req, timeout=90).read() except (urllib2.URLError, socket.timeout) as e: logger.warn('Error fetching nzb from url: %s, %s' % (nzburl, e)) nzbfile = False if nzbfile: nzbname = str(nzbtitle) + '.nzb' nzbpath = os.path.join(lazylibrarian.NZB_BLACKHOLEDIR, nzbname) try: with open(nzbpath, 'w') as f: f.write(nzbfile) logger.debug('NZB file saved to: ' + nzbpath) download = True # try: # os.chmod(nzbpath, 0777) # except Exception, e: # logger.error("Could not chmod path: " + str(nzbpath)) except Exception as e: logger.error('%s not writable, NZB not saved. Error: %s' % (nzbpath, e)) download = False else: logger.warn('No NZB download method is enabled, check config.') return False if download: logger.debug('Nzbfile has been downloaded from ' + str(nzburl)) myDB.action('UPDATE books SET status = "Snatched" WHERE BookID="%s"' % bookid) myDB.action('UPDATE wanted SET status = "Snatched" WHERE NZBurl="%s"' % nzburl) return True else: logger.error(u'Failed to download nzb @ <a href="%s">%s</a>' % (nzburl, nzbprov)) myDB.action('UPDATE wanted SET status = "Failed" WHERE NZBurl="%s"' % nzburl) return False
def DownloadMethod(bookid=None, nzbprov=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() if lazylibrarian.SAB_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: download = sabnzbd.SABnzbd(nzbtitle, nzburl) elif lazylibrarian.NZBGET_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: headers = {'User-Agent': USER_AGENT} data = request.request_content(url=nzburl, headers=headers) nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl download = nzbget.sendNZB(nzb) elif lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: try: req = urllib2.Request(nzburl) if lazylibrarian.PROXY_HOST: req.set_proxy(lazylibrarian.PROXY_HOST, lazylibrarian.PROXY_TYPE) req.add_header('User-Agent', USER_AGENT) nzbfile = urllib2.urlopen(req, timeout=90).read() except urllib2.URLError, e: logger.warn('Error fetching nzb from url: ' + nzburl + ' %s' % e) nzbfile = False if (nzbfile): nzbname = str(nzbtitle) + '.nzb' nzbpath = os.path.join(lazylibrarian.NZB_BLACKHOLEDIR, nzbname) try: f = open(nzbpath, 'w') f.write(nzbfile) f.close() logger.info('NZB file saved to: ' + nzbpath) download = True try: os.chmod(nzbpath, 0777) except Exception, e: logger.info("Could not chmod path: " + str(file2)) except Exception, e: logger.error('%s not writable, NZB not saved. Error: %s' % (nzbpath, e)) download = False
def NZBDownloadMethod(bookid=None, nzbtitle=None, nzburl=None, library='eBook'): myDB = database.DBConnection() Source = '' downloadID = '' if lazylibrarian.CONFIG['NZB_DOWNLOADER_SABNZBD'] and lazylibrarian.CONFIG[ 'SAB_HOST']: Source = "SABNZBD" downloadID = sabnzbd.SABnzbd(nzbtitle, nzburl, False) # returns nzb_ids or False if lazylibrarian.CONFIG['NZB_DOWNLOADER_NZBGET'] and lazylibrarian.CONFIG[ 'NZBGET_HOST']: Source = "NZBGET" data, success = fetchURL(nzburl) if not success: logger.debug('Failed to read nzb data for nzbget: %s' % data) downloadID = '' else: nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl downloadID = nzbget.sendNZB(nzb) if lazylibrarian.CONFIG['NZB_DOWNLOADER_SYNOLOGY'] and lazylibrarian.CONFIG['USE_SYNOLOGY'] and \ lazylibrarian.CONFIG['SYNOLOGY_HOST']: Source = "SYNOLOGY_NZB" downloadID = synology.addTorrent(nzburl) # returns nzb_ids or False if lazylibrarian.CONFIG['NZB_DOWNLOADER_BLACKHOLE']: Source = "BLACKHOLE" nzbfile, success = fetchURL(nzburl) if not success: logger.warn('Error fetching nzb from url [%s]: %s' % (nzburl, nzbfile)) nzbfile = '' if nzbfile: nzbname = str(nzbtitle) + '.nzb' nzbpath = os.path.join(lazylibrarian.CONFIG['NZB_BLACKHOLEDIR'], nzbname) try: with open(nzbpath, 'wb') as f: if isinstance(nzbfile, unicode): nzbfile = nzbfile.encode('iso-8859-1') f.write(nzbfile) logger.debug('NZB file saved to: ' + nzbpath) setperm(nzbpath) downloadID = nzbname except Exception as e: logger.error('%s not writable, NZB not saved. %s: %s' % (nzbpath, type(e).__name__, str(e))) downloadID = '' if not Source: logger.warn('No NZB download method is enabled, check config.') return False if downloadID: logger.debug('Nzbfile has been downloaded from ' + str(nzburl)) if library == 'eBook': myDB.action('UPDATE books SET status="Snatched" WHERE BookID=?', (bookid, )) elif library == 'AudioBook': myDB.action( 'UPDATE books SET audiostatus = "Snatched" WHERE BookID=?', (bookid, )) myDB.action( 'UPDATE wanted SET status="Snatched", Source=?, DownloadID=? WHERE NZBurl=?', (Source, downloadID, nzburl)) return True else: logger.error('Failed to download nzb @ <a href="%s">%s</a>' % (nzburl, Source)) myDB.action('UPDATE wanted SET status="Failed" WHERE NZBurl=?', (nzburl, )) return False
def NZBDownloadMethod(bookid=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() Source = '' downloadID = '' if lazylibrarian.CONFIG['NZB_DOWNLOADER_SABNZBD'] and lazylibrarian.CONFIG[ 'SAB_HOST']: Source = "SABNZBD" downloadID = sabnzbd.SABnzbd(nzbtitle, nzburl, False) # returns nzb_ids or False if lazylibrarian.CONFIG['NZB_DOWNLOADER_NZBGET'] and lazylibrarian.CONFIG[ 'NZBGET_HOST']: Source = "NZBGET" # headers = {'User-Agent': USER_AGENT} # data = request.request_content(url=nzburl, headers=headers) data, success = fetchURL(nzburl) if not success: logger.debug('Failed to read nzb data for nzbget: %s' % data) downloadID = '' else: nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl downloadID = nzbget.sendNZB(nzb) if lazylibrarian.CONFIG['NZB_DOWNLOADER_SYNOLOGY'] and lazylibrarian.CONFIG[ 'USE_SYNOLOGY'] and lazylibrarian.CONFIG['SYNOLOGY_HOST']: Source = "SYNOLOGY_NZB" downloadID = synology.addTorrent(nzburl) # returns nzb_ids or False if lazylibrarian.CONFIG['NZB_DOWNLOADER_BLACKHOLE']: Source = "BLACKHOLE" nzbfile, success = fetchURL(nzburl) if not success: logger.warn('Error fetching nzb from url [%s]: %s' % (nzburl, nzbfile)) nzbfile = '' if nzbfile: nzbname = str(nzbtitle) + '.nzb' nzbpath = os.path.join(lazylibrarian.CONFIG['NZB_BLACKHOLEDIR'], nzbname) try: with open(nzbpath, 'w') as f: f.write(nzbfile) logger.debug('NZB file saved to: ' + nzbpath) setperm(nzbpath) downloadID = nzbname except Exception as e: logger.error('%s not writable, NZB not saved. Error: %s' % (nzbpath, str(e))) downloadID = '' if not Source: logger.warn('No NZB download method is enabled, check config.') return False if downloadID: logger.debug('Nzbfile has been downloaded from ' + str(nzburl)) myDB.action('UPDATE books SET status = "Snatched" WHERE BookID="%s"' % bookid) myDB.action( 'UPDATE wanted SET status = "Snatched", Source = "%s", DownloadID = "%s" WHERE NZBurl="%s"' % (Source, downloadID, nzburl)) return True else: logger.error(u'Failed to download nzb @ <a href="%s">%s</a>' % (nzburl, Source)) myDB.action('UPDATE wanted SET status = "Failed" WHERE NZBurl="%s"' % nzburl) return False