Exemplo n.º 1
0
 def QueueAction(self, action):
     try:
         self.logger.debug(action + " ALL")
         nzbget = jsonrpc.ServerProxy('%s' % self.nzbget_url())
         if 'resume' in action:
             status = nzbget.resume()
         elif 'pause' in action:
             status = nzbget.pause()
         return status
     except Exception as e:
         self.logger.error("Failed to %s" % (action, e))
Exemplo n.º 2
0
 def ChangeCategory(self, nzbid=None, cat=None, nzbname=None):
     self.logger.debug('Change %s nzbname id %s to category %s' %
                       (nzbname, nzbid, cat))
     r = False
     try:
         nzbget = jsonrpc.ServerProxy('%s' % self.nzbget_url())
         if nzbid and cat:
             r = nzbget.editqueue("GroupSetCategory", 0, cat, [int(nzbid)])
     except Exception as e:
         self.logger.error('Failed to set %s on %s' % (cat, nzbname, e))
     return r
Exemplo n.º 3
0
def queue_add_nzbget():
    status = False
    if len(nzb):
        try:
            nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % nzbget_url())
            nzb = request.form['url']
            nzb = urllib.urlopen(nzb).read()
            status = nzbget.append('test', '', False, base64.encode(nzb))
        except Exception as e:
            nzbget_exception(e)

    return jsonify({'success': status})
Exemplo n.º 4
0
def queue_action_nzbget(action):
    status = False
    logger.log('NZBGet :: Queue action: %s' % action, 'INFO')
    try:
        nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % nzbget_url())
        if 'resume' in action:
            status = nzbget.resume()
        elif 'pause' in action:
            status = nzbget.pause()

    except Exception as e:
        nzbget_exception(e)

    return jsonify({'success': status})
Exemplo n.º 5
0
 def AddNzbFromUrl(self, nzb_url= '', nzb_category='', nzb_name='') : 
     if not nzb_url:
         return
     self.logger.info("Added %s category %s url %s" %(nzb_name, nzb_category, nzb_url))
     try:
         nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % self.nzbget_url())
         nzb = urlopen(nzb_url).read()
         # If name is missig the link is added manually
         if not nzb_name:
             nzb_name = 'Temp Name'
         nzbget.append(nzb_name, nzb_category, False, base64.standard_b64encode(nzb))
         return {'status':True}
     except Exception as e:
         self.logger.error("Failed to add %s to queue %s" % (nzb_name, e))
Exemplo n.º 6
0
    def GetCategorys(self):
        self.logger.debug('Fetching categories')
        categorys = []
        # Add default category
        categorys.append('')
        try:
            nzbget = jsonrpc.ServerProxy('%s' % self.nzbget_url())
            config = nzbget.config()
            r = re.compile(ur'(Category\d+.name)', re.IGNORECASE)
            for category in config:
                if re.match(r, category['Name']):
                    categorys.append(category['Value'])
        except Exception as e:
            self.logger.error('Failed to fetch categorys %s' % e)

        return categorys
Exemplo n.º 7
0
def xhr_nzbget():
    downloads = status = nzbget = None
    logger.log('NZBGet :: Getting download list', 'INFO')
    try:
        nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % nzbget_url())
        status = nzbget.status()
        downloads = nzbget.listgroups()
    except Exception as e:
        nzbget_exception(e)

    logger.log('NZBGet :: Getting download list (DONE)', 'INFO')
    return render_template(
        'nzbget-queue.html',
        nzbget=status,
        downloads=downloads,
    )
Exemplo n.º 8
0
 def IndividualAction(self, id='', name='', action=''):
     try:
         self.logger.debug("%s %s %s" % (action, name, id))
         nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % self.nzbget_url())
         if 'resume' in action:
             action = 'GroupResume'
         elif 'pause' in action:
             print 'pause is pause'
             action = 'GroupPause'
         elif 'delete' in action:
             action = 'GroupDelete'
         elif 'hidehistory' in action:
             action = 'HistoryDelete'
         status = nzbget.editqueue(action, 0, '', [int(id)])
         return status
     except Exception as e:
         self.logger.error("Failed to %s %s %s %s" % (action, name, id, e))
Exemplo n.º 9
0
def individual_action_nzbget(id, action):
    status = False
    logger.log('NZBGet :: Item %s action: %s' % (id, action), 'INFO')
    if 'resume' in action:
        action = 'GroupResume'
    elif 'pause' in action:
        action = 'GroupPause'
    elif 'delete' in action:
        action = 'GroupDelete'

    try:
        nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % nzbget_url())
        status = nzbget.editqueue(action, 0, '', id)

    except Exception as e:
        nzbget_exception(e)

    return jsonify({'success': status, 'id': id, 'action': action})
Exemplo n.º 10
0
def queue_add_nzbget():
    status = False
    try:
        nzb = request.form['url']
        name = request.form['name']
        category = request.form['category']
        nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % nzbget_url())
        nzb = urllib.urlopen(nzb).read()
        status = nzbget.append(
            name,  #filename
            base64.b64encode(nzb),  #nzb
            category,  # category
            0,  #priority (0 = default)
            False,  # add to top
            False,  # add paused
            name,  # dupe key
            100000,  # dupe score
            'Force')  # dupe mode
    except Exception as e:
        nzbget_exception(e)

    return jsonify({'success': status})
Exemplo n.º 11
0
    def AddNzbFromUrl(self, nzb_url='', nzb_category='', nzb_name='', f=''):
        self.logger.info("Added %s category %s url %s" %
                         (nzb_name, nzb_category, nzb_url))
        r = False
        try:
            nzbget = jsonrpc.ServerProxy('%s' % self.nzbget_url())
            if f:
                # f = nzbfile
                r = nzbget.append(nzb_name, nzb_category, False, f)
            else:
                sess = requests.Session()
                nzb = sess.get(nzb_url, timeout=30)

                if not nzb_name:
                    try:
                        # Try to get the filename from the download
                        # TODO check if x-dnzb-name is on all indexers
                        nzb_name = nzb.headers.get('x-dnzb-name')
                    except Exception as e:
                        self.logger.error('%s' % e)
                        self.logger.debug(
                            'Trying to parse the nzbname from content-disposition'
                        )
                        nzb_name = nzb.headers.get(
                            'content-disposition').split(
                                'filename=')[1].replace('.nzb',
                                                        '').replace('"', '')

                nzb = nzb.content
                r = nzbget.append(nzb_name, nzb_category, False,
                                  base64.standard_b64encode(nzb))

        except Exception as e:
            self.logger.error("Failed to add %s %s to queue %s" %
                              (nzb_name, nzb_url, e))
        return r
Exemplo n.º 12
0
 def GetConfig(self):
     nzbget = jsonrpc.ServerProxy('%s/jsonrpc' % self.nzbget_url())
     return nzbget.config()