This is a "plugin" for the Video Disk Recorder (VDR).

Written by:                  Thorsten Scheck

Project's homepage:          http://www.copypointburscheid.de/linux/autosort.htm

Latest version available at: http://www.copypointburscheid.de/linux/autosort.htm

See the file COPYING for license information.

Description: This plugin performs a presortion of new channels.

----------------------------------------------------------------

If you try this Plugin the first time
              !!! Backup your channels.conf !!!

If you upgrade from an older version 
              !!! Backup your channels.conf !!!

If you make heavy changes to autosort.conf
   !!! Backup your channels.conf AND your autosort.conf !!!
 
----------------------------------------------------------------

Refer README.config for configuration options.

Install as usual
Delete your "New"- and/or "Unsorted"-Section 
or 
move the channels you want to resort behind the AutoSort mark created on an earlier run
Start vdr with "-P autosort"

----------------------------------------------------------------

What it does:

AutoSort adds the group delimiters you gave in autosort.conf and
sorts all channels after the AutoSort mark into these groups.
    

What it is for:

It's intended use is that you pick up the channels for your daily
use out of a smaller, presorted list instead of searching some
hundreds, mostly useless for you, entrys by hand.
It may be possible that it can do the complete channel arrangement for you.


What's on the Roadmap:

Some more config options.
Some regex perhaps.
May be some other channel modifying tasks.
Threading (not in 0.0.x series).

----------------------------------------------------------------

How it does it's job in detail

So, let's start at the very beginnig:
AutoSort need's a config file called "autosort.conf" to know what you want it to do.
For testing or to have a starting point you can take the one in the archive and 
copy it to /video/plugins/ or the directory you set with "-c".

You have to start VDR with the additional argument "-P autosort"
I also recommend, that you add "-l 3" (L - explained in vdr.1) to your command line.

On startup, AutoSort reads it's config file and checks your channels.conf:
If there is no group "Auto Sort" it will be created.
If there if there is any other group missing, it will be created.
If there is a group to much, it will be deleted.
Finally AutoSort checks the order of the groups and will move them if nessasary.

It takes some time (up to 5 minutes) to complete all this, but you'll be
informed about whats going on via OSD-Messages (depending on the level you set)
and in your sys.log or messages file. And this has to be repeated on every startup
because noone knows if your channels.conf has been changed outside VDR or not.

What happens next is easy to explain: nothing.
VDR has enougth to do: switch channels for you, make some recordings etc.
If this all is ready and nothing else is to do for a few minutes, VDR calls the 
housekeeping tasks and therewith starts AutoSort and others.

Now AutoSort takes the first group and follows the rules you gave.
First it checks if the channels in this group still fits to the group-rules and if
not moves them back to "unsorted".
Then it checks the channels in all other groups with lower priority and moves them 
into this group if they fit.
At last the group will be sorted and AutoSort stops until the next housekeeping call.

AutoSort has to give back control to VDR as soon as possible and so it does.
It will be very rare that a group is perfectly sorted after the first run. 
It's written to run 24/7 in background, every 10 minutes a bit, without disturbing
the user or other VDR tasks. It may happen that it takes a week to complete this
job with some hundred groups on some thousend channels and as long as some channels 
change twice a day you will probabaly never reach your goal.

Finally let's remember that AutoSort will never work before it's start-mark 
(the group called "Auto Sort") so if you set "Update Channels" in VDR's DVB-Menu
to anything less than "Add Channels" and don't move your old "unsorted" or "new channels"
section behind the delimiter "Auto Sort", this plugin wont be worth a penny to you.

----------------------------------------------------------------

Main Menu

"Autosort Config Test"
    This option is hidden by default.
    
    If selected, AutoSort reloads it's config and does a complete run.
    The advantages
	You don't need to restart VDR to test a new config.
	A run is completed after 20min instead of 5h housekeeping. 
    The disadvantages
	VDR won't return to it's main loop during run, and therewith won't
	  start or end a recording, switch channels or do other tasks.
	  (Recordings started before the complete-run don't get damaged,
	  they just won't end before AutoSort is ready.)
	           !!! So use this with care !!!
		   
    Watchdog will be refreshed to 60s during channels check.		   
    You can stop the test with the 'back'-button on your remote control.
    

Setup Menu

"Hide MainMenu entry"
    Cause the complete run is just for checking your config you can hide it here.
    Default is 'Yes' (Hide entry)
    A VDR-Restart is needed if you change this.
    
"Run on housekeeping"
    The most important innovation for technical stuff ever made: the off-switch.
    Default is 'Yes' (Run)
    
"Max channels to move"
    The maximum number of channels to move on a housekeeping run.
    Less moves means earlier return to vdr-main-loop.
    More moves means earlier finish of sorting.
    Default is 20 (Just leave it here)
    
"Message level"
    Level of OSD-Messages
    0 - No Messages
    1 - Startup messages and housekeeping is ready with last group
    2 - Group related messages (check, add, delete, move)
    3 - Channel moves
    Default is 2, for a config test you should switch to 3
  
"Use FixedPos for 'Auto Sort'"
    Assign a fixed channel number to group 'Auto Sort' or not.
    Default is "No"  
    You need to reload the configuration if you change this.

"Fixed Position for 'Auto Sort'"
    The channel number to assign to group 'Auto Sort'.
    Default is 0
    You need to reload the configuration if you change this.
  
"Sort unsorted channels"
    Does an alphabetically sortion in 'Unsorted' group.
    Default is "Yes"
    You need to reload the configuration if you change this.
    
"Use FixedPos for 'Unsorted'"
    Assign a fixed channel number to group 'Unsorted' or not.
    Default is "No"  
    You need to reload the configuration if you change this.

"Fixed Position for 'Unsorted'"
    The channel number to assign to group 'Unsorted'.
    Default is 0
    You need to reload the configuration if you change this.

"Keep new channels seperated"
    You may have missed this: the 'New Channels' group.
    It's just in case you want to review new channels before they disapear in the deeps of AutoSort
    Default is "No"
    You need to reload the configuration if you change this.
    
"Sort new channels"
    Does an alphabetically sortion in 'New Channels' group.
    Keep in mind that they are normaly sorted by age, what also could be usefull.
    Default is "No"
    You need to reload the configuration if you change this.
    
"Use FixedPos for 'New Channels'"
    Assign a fixed channel number to group 'New Channels' or not.
    Default is "No"  
    You need to reload the configuration if you change this.

"Fixed Position for 'New Channels'"
    The channel number to assign to group 'New Channels'.
    Default is 0
    You need to reload the configuration if you change this.

"Use 'version' sort"
    Switches to another sorting algorithm witch ignores spaces
    and special characters and sorts numbers correctly (1,2,10,20 instead of 1,10,2,20)
    Default is "Yes"
    It will take some time before you see the results after switching this.
    
"Set TimeStamps"
    Whether to set TimeStamps or not.
    If set to "YES" AutoSort will overwrite the short names of the channels with "ASTS-xxxxxxxxxx"
    where xxxx is the unix-time (seconds since 1970). You can catch those channels who aren't updated
    after some time with the 'TimeStamp' option.
    Default is "Yes"
        
"Days between TimeStamps"
    How many days to wait before setting TimeStamps again.
    Default is 7 days

----------------------------------------------------------------

Patches

deleteca.diff
    Normaly VDR doesn't overwrite special Ca Values.
    If you want to use SetCaFF or SetCa0 you should apply this patch.
    AutoSort will tell you in syslog for witch channel it will need it.

----------------------------------------------------------------

Known Bug's

EPG-Search plugin may fail it's first run on statup.
    Try starting EPG-Search after AutoSort. (solved in 0.1.x)
Some config options aren't implemented yet.
    Open-/ClosedCa will follow later.
The multiple options HasCaValue, NotCaValue, HasName, NotName, HasProvider, AudioLang are limited to 10.
    There is no error checking for that!
On Config-Test-Run main menu stays in background and looks ugly.
    Hope i can fix that soon.
In 0.0.x series you need to run vdr with Watchdog.
    refreshing Watchdog gets unnessesary with 0.1.x
