Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
fixes #115: use parent category name during nzb creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmeneghello committed Jan 8, 2015
1 parent 9fcd4d3 commit 29e3592
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pynab/nzbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def get_nzb_details(nzb):
}


def create(name, category, binary):
def create(name, parent_category_name, binary):
"""Create the NZB, store it in GridFS and return the ID
to be linked to the release."""

xml = io.StringIO()
xml.write('<?xml version="1.0" encoding="UTF-8"?>\n'
'<!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.1//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.1.dtd">\n'
'<nzb>\n'
'<head><meta type="category">{}</meta><meta type="name">{}</meta></head>\n'.format(category.name, escape(name))
'<head><meta type="category">{}</meta><meta type="name">{}</meta></head>\n'.format(parent_category_name, escape(name))
)

for part in binary.parts:
Expand Down
8 changes: 6 additions & 2 deletions pynab/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ def process():
for blacklist in blacklists:
db.expunge(blacklist)

# cache categories
parent_categories = {}
for category in db.query(Category).all():
parent_categories[category.id] = category.parent.name if category.parent else category.name

# for interest's sakes, memory usage:
# 38,000 releases uses 8.9mb of memory here
# no real need to batch it, since this will mostly be run with
Expand Down Expand Up @@ -295,13 +300,12 @@ def process():

# give the release a category
release.category_id = pynab.categories.determine_category(binary.name, binary.group_name)
category = db.query(Category).filter(Category.id == release.category_id).one()

# create the nzb, store it and link it here
# no need to do anything special for big releases here
# if it's set to lazyload, it'll kill rows as they're used
# if it's a small release, it'll go straight from memory
nzb = pynab.nzbs.create(release.search_name, category, binary)
nzb = pynab.nzbs.create(release.search_name, parent_categories[release.category_id], binary)

if nzb:
added_count += 1
Expand Down

0 comments on commit 29e3592

Please sign in to comment.