def _HandleLink( jobs, link, title, flag, orgcat, cat, pp, script, download, star, order, priority=NORMAL_PRIORITY, rule=0 ): """ Process one link """ if script == "": script = None if pp == "": pp = None jobs[link] = {} jobs[link]["order"] = order jobs[link]["orgcat"] = orgcat if special_rss_site(link): nzbname = None else: nzbname = sanitize_foldername(title) m = RE_NEWZBIN.search(link) if m and m.group(1).lower() == "newz" and m.group(2) and m.group(3): if download: jobs[link]["status"] = "D" jobs[link]["title"] = title logging.info("Adding %s (%s) to queue", m.group(3), title) sabnzbd.add_msgid(m.group(3), pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]["status"] = flag + "*" else: jobs[link]["status"] = flag jobs[link]["title"] = title jobs[link]["url"] = m.group(3) jobs[link]["cat"] = cat jobs[link]["pp"] = pp jobs[link]["script"] = script jobs[link]["prio"] = str(priority) else: if download: jobs[link]["status"] = "D" jobs[link]["title"] = title logging.info("Adding %s (%s) to queue", link, title) sabnzbd.add_url(link, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]["status"] = flag + "*" else: jobs[link]["status"] = flag jobs[link]["title"] = title jobs[link]["url"] = link jobs[link]["cat"] = cat jobs[link]["pp"] = pp jobs[link]["script"] = script jobs[link]["prio"] = str(priority) jobs[link]["time"] = time.time() jobs[link]["rule"] = rule
def _HandleLink(jobs, link, title, flag, orgcat, cat, pp, script, download, star, order, priority=NORMAL_PRIORITY, rule=0): """ Process one link """ if script == '': script = None if pp == '': pp = None jobs[link] = {} jobs[link]['order'] = order jobs[link]['orgcat'] = orgcat if special_rss_site(link): nzbname = None else: nzbname = sanitize_foldername(title) m = RE_NEWZBIN.search(link) if m and m.group(1).lower() == 'newz' and m.group(2) and m.group(3): if download: jobs[link]['status'] = 'D' jobs[link]['title'] = title logging.info("Adding %s (%s) to queue", m.group(3), title) sabnzbd.add_msgid(m.group(3), pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]['status'] = flag + '*' else: jobs[link]['status'] = flag jobs[link]['title'] = title jobs[link]['url'] = m.group(3) jobs[link]['cat'] = cat jobs[link]['pp'] = pp jobs[link]['script'] = script jobs[link]['prio'] = str(priority) else: if download: jobs[link]['status'] = 'D' jobs[link]['title'] = title logging.info("Adding %s (%s) to queue", link, title) sabnzbd.add_url(link, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]['status'] = flag + '*' else: jobs[link]['status'] = flag jobs[link]['title'] = title jobs[link]['url'] = link jobs[link]['cat'] = cat jobs[link]['pp'] = pp jobs[link]['script'] = script jobs[link]['prio'] = str(priority) jobs[link]['time'] = time.time() jobs[link]['rule'] = rule
def _HandleLink(jobs, link, title, flag, orgcat, cat, pp, script, download, star, order, priority=NORMAL_PRIORITY, rule=0): """ Process one link """ if script == '': script = None if pp == '': pp = None jobs[link] = {} jobs[link]['order'] = order jobs[link]['orgcat'] = orgcat if special_rss_site(link): nzbname = None else: nzbname = title m = RE_NEWZBIN.search(link) if m and m.group(1).lower() == 'newz' and m.group(2) and m.group(3): if download: jobs[link]['status'] = 'D' jobs[link]['title'] = title logging.info("Adding %s (%s) to queue", m.group(3), title) sabnzbd.add_msgid(m.group(3), pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]['status'] = flag + '*' else: jobs[link]['status'] = flag jobs[link]['title'] = title jobs[link]['url'] = m.group(3) jobs[link]['cat'] = cat jobs[link]['pp'] = pp jobs[link]['script'] = script jobs[link]['prio'] = str(priority) else: if download: jobs[link]['status'] = 'D' jobs[link]['title'] = title logging.info("Adding %s (%s) to queue", link, title) sabnzbd.add_url(link, pp=pp, script=script, cat=cat, priority=priority, nzbname=nzbname) else: if star: jobs[link]['status'] = flag + '*' else: jobs[link]['status'] = flag jobs[link]['title'] = title jobs[link]['url'] = link jobs[link]['cat'] = cat jobs[link]['pp'] = pp jobs[link]['script'] = script jobs[link]['prio'] = str(priority) jobs[link]['time'] = time.time() jobs[link]['rule'] = rule
def run(self, delete=None, force=False): if not (cfg.newzbin_bookmarks() or force): return if not (cfg.newzbin_username() and cfg.newzbin_password()): return headers = { 'User-Agent': 'SABnzbd+/%s' % sabnzbd.__version__, } # Connect to Newzbin try: if _HAVE_SSL: conn = httplib.HTTPSConnection(cfg.newzbin_url()) else: conn = httplib.HTTPConnection(cfg.newzbin_url()) if delete: logging.debug('Trying to delete Newzbin bookmark %s', delete) postdata = { 'username': cfg.newzbin_username(), 'password': cfg.newzbin_password(), 'action': 'delete', \ 'reportids' : delete } else: logging.info('Fetching Newzbin bookmarks') postdata = { 'username': cfg.newzbin_username(), 'password': cfg.newzbin_password(), 'action': 'fetch'} postdata = urllib.urlencode(postdata) headers['Content-type'] = 'application/x-www-form-urlencoded' fetchurl = '/api/bookmarks/' conn.request('POST', fetchurl, postdata, headers) response = conn.getresponse() except: _warn_user('Problem accessing Newzbin server.') logging.info("Traceback: ", exc_info = True) return data = response.read() # Get the status rcode = str(response.status) # Official return codes: # 200 = OK, NZB content follows # 204 = No content # 400 = Bad Request, please supply all parameters # (this generally means reportid or fileid is missing; missing user/pass gets you a 401) # 401 = Unauthorised, check username/password? # 402 = Payment Required, not Premium # 403 = Forbidden (incorrect auth) # 500 = Internal Server Error, please report to Administrator # 503 = Service Unavailable, site is currently down if rcode not in ('500', '503'): _access_ok() if rcode == '204': logging.debug("No bookmarks set") elif rcode in ('401', '403'): logging.warning(Ta('Unauthorised, check your newzbin username/password')) elif rcode in ('402'): logging.warning(Ta('You have no credit on your Newzbin account')) elif rcode in ('500', '503'): _warn_user('Newzbin has a server problem (%s).' % rcode) elif rcode == '200': if delete: if data.startswith('1'): logging.info('Deleted newzbin bookmark %s', delete) if delete in self.bookmarks: self.bookmarks.remove(delete) else: if delete in self.bookmarks: logging.warning(Ta('Could not delete newzbin bookmark %s'), delete) else: for line in data.split('\n'): try: msgid, size, text = line.split('\t', 2) except: msgid = size = text = None if msgid and (msgid not in self.bookmarks): self.bookmarks.append(msgid) logging.info("Found new bookmarked msgid %s (%s)", msgid, text) sabnzbd.add_msgid(int(msgid), None, None, priority=None) else: logging.error(Ta('Newzbin gives undocumented error code (%s)'), rcode) self._save() self.__busy = False
def run(self, delete=None): headers = { 'User-Agent': 'SABnzbd+/%s' % sabnzbd.__version__, } # Connect to Newzbin try: if _HAVE_SSL: conn = httplib.HTTPSConnection('www.newzbin.com') else: conn = httplib.HTTPConnection('www.newzbin.com') if delete: logging.debug('Trying to delete Newzbin bookmark %s', delete) postdata = { 'username': cfg.newzbin_username(), 'password': cfg.newzbin_password(), 'action': 'delete', \ 'reportids' : delete } else: logging.info('Fetching Newzbin bookmarks') postdata = { 'username': cfg.newzbin_username(), 'password': cfg.newzbin_password(), 'action': 'fetch'} postdata = urllib.urlencode(postdata) headers['Content-type'] = 'application/x-www-form-urlencoded' fetchurl = '/api/bookmarks/' conn.request('POST', fetchurl, postdata, headers) response = conn.getresponse() except: _warn_user('Problem accessing Newzbin server.') logging.info("Traceback: ", exc_info = True) return data = response.read() # Get the status rcode = str(response.status) # Official return codes: # 200 = OK, NZB content follows # 204 = No content # 400 = Bad Request, please supply all parameters # (this generally means reportid or fileid is missing; missing user/pass gets you a 401) # 401 = Unauthorised, check username/password? # 402 = Payment Required, not Premium # 403 = Forbidden (incorrect auth) # 500 = Internal Server Error, please report to Administrator # 503 = Service Unavailable, site is currently down if rcode not in ('500', '503'): _access_ok() if rcode == '204': logging.debug("No bookmarks set") elif rcode in ('401', '403'): logging.warning(Ta('Unauthorised, check your newzbin username/password')) elif rcode in ('402'): logging.warning(Ta('You have no credit on your Newzbin account')) elif rcode in ('500', '503'): _warn_user('Newzbin has a server problem (%s).' % rcode) elif rcode == '200': if delete: if data.startswith('1'): logging.info('Deleted newzbin bookmark %s', delete) if delete in self.bookmarks: self.bookmarks.remove(delete) else: if delete in self.bookmarks: logging.warning(Ta('Could not delete newzbin bookmark %s'), delete) else: for line in data.split('\n'): try: msgid, size, text = line.split('\t', 2) except: msgid = size = text = None if msgid and (msgid not in self.bookmarks): self.bookmarks.append(msgid) logging.info("Found new bookmarked msgid %s (%s)", msgid, text) sabnzbd.add_msgid(int(msgid), None, None, priority=None) else: logging.error(Ta('Newzbin gives undocumented error code (%s)'), rcode) self._save() self.__busy = False