[QUESTION] Setting Category When Uploading ?

Get help, report and discuss bugs.
phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

[QUESTION] Setting Category When Uploading ?

Post by phil-t » 29 Jan 2009, 00:47

I know the answer is probably simple, but..

How does nzbGet handle 'categories' ? (From a developers point of view)

i.e. if I have a .nzb file and a category for that .nzb, is it just a case of creating a sub-dir in the NzbDir with the Category name? or is there another mechanism?

(I'm just finishing off an update to the Web Interface, adding Newzbin support, and now I have the .nzb and category, I'm just looking at how best to 'deliver' it to NZBGet)


If the mod works out OK, is this something you may take a look at for possible future integration into the Web interface? I don''t know if you are looking for any code contribution, It's for personal consumption at the moment, I don't want to tread on any toes!

Thanks..

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [QUESTION] Setting Category When Uploading ?

Post by hugbug » 29 Jan 2009, 08:34

Your contribution is welcome.

There are two ways to set category from web-app:
1. Create sub-dir and put the file there;
2. Use remote call "edit-queue" to change the category.

In second case you need to wait until the file is picked up by nzbget and appears in queue before you can call "edit-queue"-command. The sequence were:
1. Put nzb-file into nzbdir-directory;
2. Call remote command "Scan", wich causes nzbget to pickup files (to not wait until NzbDirInterval expires);
3. Read queue to find the latest item. Check if it has the same nzb-filename, which were just uploaded;
4. Call remote command "edit-queue" for the last ID to set the category.

As you see the second method is much more difficult.

phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

Re: [QUESTION] Setting Category When Uploading ?

Post by phil-t » 30 Jan 2009, 01:46

I don't suppose you could help me a little bit by posting the PHP I need to issue a SCAN remote command?

This is the last thing to complete before I start some serious testing..

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [QUESTION] Setting Category When Uploading ?

Post by hugbug » 30 Jan 2009, 08:17

Please try this:

Code: Select all

GetRequest('scan', '');
The function is declared in "functions.php".

Note, that the scan-command is executed asynchronously. The server doesn't wait until all files are parsed and added to queue, but responses immediately.

phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

Re: [QUESTION] Setting Category When Uploading ?

Post by phil-t » 30 Jan 2009, 09:07

Thanks for that..

I saw the Request functions in the functions.php, and looked at the existing usage of those in the Web Interface, but wasn't 100% sure how it worked! That's saved me looking at the source code!

phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

Re: [QUESTION] Setting Category When Uploading ?

Post by phil-t » 05 Feb 2009, 20:18

Hi,

I'm having problems getting this to work!

If, once the file is saved, and the permissions set for the nzb I've saved to the NzbDir, if I call

Code: Select all

GetRequest('scan','');
(this is just before the GetNzbFromNewzbin() function returns)

Nothing actually happens, the nzb is not queued.


If I manually request a scan via the status.php, this works, and the nzb queues and starts downloading

e.g. http://NAS_IP/nzbgetweb/status.php?action=scan

Looking at the source code of status.php, this just calls GetRequest($action,"") which would seem identical to the function call I've tried making.


I'm sure I'm overlooking something obvious, but any help would be appreciated.

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [QUESTION] Setting Category When Uploading ?

Post by hugbug » 05 Feb 2009, 20:40

I think it's because nzbget checks file timestamps and process only nzbs, which are older than defined by option NZBDirFileAge. I forgot about that particularity when I wrote one of the previous posts with algroithm.

A workaround should be to set the filetime to a past day, e.g. yesterday or just 01.01.2000.

If it will work could you please patch the standard nzb-upload function as well? ;)

phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

Re: [QUESTION] Setting Category When Uploading ?

Post by phil-t » 06 Feb 2009, 18:13

Nearly there, but not quite!

The NZBGet server uses

Code: Select all

			else if ((buffer.st_mode & S_IFDIR) == 0 &&
				// file found, checking modification-time
				time(NULL) - buffer.st_mtime > g_pOptions->GetNzbDirFileAge() &&
				time(NULL) - buffer.st_ctime > g_pOptions->GetNzbDirFileAge())
			{
				// the file is at least g_pOptions->GetNzbDirFileAge() seconds old, we can process it
				ProcessIncomingFile(szDirectory, filename, fullfilename, szCategory);
			}
This checks the M (Last Modified) and C (Last INODE Change) Timestamps to ensure they are old enough.

Unforunately, the PHP touch() function can only set A (Last Access) and M (Last Modified) timestamps!

I can't find any information on setting the C Time in PHP, so was wondering the implications of changing the Server code to just check A/M timestamps? I guess you check the C Timestamp for a reason?

Which leads me on to the next question..

How did you compile your "cs05q3armel" target ?

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [QUESTION] Setting Category When Uploading ?

Post by hugbug » 06 Feb 2009, 18:51

It becomes more difficult as expected.

Actually, st_ctime is the most important timestamp. It shows the real timestamp of modification, while st_mtime can be manipulated by application.

When user copies file from a local computer or folder to the incoming folder, if file manager works in sequence "create destination file -> copy file attributes, including mtime -> copy file content", then nzbget could treat the file as old enough, if it would check only st_mtime, while the copying may be still in progress. st_ctime is updated by system and helps in this case.
phil-t wrote:How did you compile your "cs05q3armel" target ?
Here is a guide - Building the ipkg package.

phil-t
Posts: 31
Joined: 27 Jan 2009, 08:24

Re: [QUESTION] Setting Category When Uploading ?

Post by phil-t » 06 Feb 2009, 19:24

A good point about the files.. Although I'm wondering where the A time (Last Accessed) would come into it??

I'd have to look further at the code, but I think if someone calls a remote 'scan' command, it would be fair to say in that instance to forgo the time checks? But if it's triggered from the NzbDirInterval time interval, it does the checks?



In the mean time, I can use the following workaround

1. Set the NzbFileAge to a low value (e.g. 1)
2. In the PHP function, I can sleep for NzbFileAge + 1 second, then issue a scan..

This does work, and as long as NzbFileAge is 1 or 2 seconds, it's not too bad a delay to the user.

It may be worth persuing a cleaner solution, as energy saving is one of the reasons people buy these embedded devices, and it's a hot topic on all the forums when the HDD's won't spin down etc..

I may be thinking off the top of my head, but some possible ideas?
1. Change the remote 'scan' command behaviour as described above (i.e. if called remotely, ignore timestamp checks, assuming that the 'client' is in control of file creation etc before calling the scan command.
2. A remote 'queue nzb' command so we could send the filename (and sub-category) to the server, so it can then go and queue it
3. Look at the A-Timestamp to see if that may offer enough protection but be flexible enough for this type of scheme to work?

And thanks for the ipkg info, I'll go an read that!

Post Reply

Who is online

Users browsing this forum: No registered users and 44 guests