Ejemplo n.º 1
0
def get_nfo(dataset=None):
    if auth():
        guid = request.query.guid or None
        if guid:
            release = db.releases.find_one({'id': guid})
            if release:
                data = fs.get(release['nfo']).read()
                response.set_header('Content-type', 'application/x-nfo')
                response.set_header('Content-Disposition', 'attachment; filename="{0}"'
                .format(release['search_name'].replace(' ', '_') + '.nfo')
                )
                return gzip.decompress(data)
            else:
                return api_error(300)
        else:
            return api_error(200)
    else:
        return api_error(100)
Ejemplo n.º 2
0
def get_nzb_dict(nzb_id):
    """Returns a JSON-like Python dict of NZB contents, including extra information
    such as a list of any nfos/rars that the NZB references."""
    data = xmltodict.parse(gzip.decompress(fs.get(nzb_id).read()))

    nfos = []
    rars = []
    pars = []
    rar_count = 0
    par_count = 0
    zip_count = 0

    if 'file' not in data['nzb']:
        return None

    if not isinstance(data['nzb']['file'], list):
        data['nzb']['file'] = [data['nzb']['file'], ]

    for part in data['nzb']['file']:
        if re.search(rar_part_regex, part['@subject'], re.I):
            rar_count += 1
        if re.search(nfo_regex, part['@subject'], re.I) and not re.search(metadata_regex, part['@subject'], re.I):
            nfos.append(part)
        if re.search(rar_regex, part['@subject'], re.I) and not re.search(metadata_regex, part['@subject'], re.I):
            rars.append(part)
        if re.search(par2_regex, part['@subject'], re.I):
            par_count += 1
            if not re.search(par_vol_regex, part['@subject'], re.I):
                pars.append(part)
        if re.search(zip_regex, part['@subject'], re.I) and not re.search(metadata_regex, part['@subject'], re.I):
            zip_count += 1

    data['nfos'] = nfos
    data['rars'] = rars
    data['pars'] = pars
    data['rar_count'] = rar_count
    data['par_count'] = par_count
    data['zip_count'] = zip_count

    return data
Ejemplo n.º 3
0
Archivo: nfos.py Proyecto: shpd/pynab
def get(nfo_id):
    """Retrieves and un-gzips an NFO from GridFS."""
    if nfo_id:
        return gzip.decompress(fs.get(nfo_id).read())
    else:
        return None