Index: programs/mythfilldatabase/filldata.cpp
===================================================================
--- programs/mythfilldatabase/filldata.cpp	(revision 14764)
+++ programs/mythfilldatabase/filldata.cpp	(working copy)
@@ -684,7 +684,7 @@
 
             // We'll keep grabbing until it returns nothing
             // Max days currently supported is 21
-            int grabdays = 21;
+            int grabdays = REFRESH_MAX;
 
             if (maxDays > 0) // passed with --max-days
                 grabdays = maxDays;
@@ -694,7 +694,7 @@
             grabdays = (only_update_channels) ? 1 : grabdays;
 
             if (grabdays == 1)
-                refresh_today = true;
+                refresh_request[0] = true;
 
             if (is_grabber_datadirect(xmltv_grabber) && only_update_channels)
             {
@@ -725,31 +725,18 @@
 
                 bool download_needed = false;
 
-                if (refresh_all)
+                if (refresh_request[i])
                 {
-                    VERBOSE(VB_GENERAL,
-                            "Data Refresh needed because of --refresh-all");
-                    download_needed = true;
-                }
-                else if ((i == 0 && refresh_today) || (i == 1 && refresh_tomorrow) ||
-                         (i == 2 && refresh_second))
-                {
-                    // Always refresh if the user specified today/tomorrow/second.
-                    if (refresh_today)
+		  if( i == 1 )
                     {
-                        VERBOSE(VB_GENERAL,
-                            "Data Refresh needed because user specified --refresh-today");
+		      VERBOSE(VB_GENERAL,
+			      "Data Refresh always needed for tomorrow");
                     }
-                    else if (refresh_second)
-                    {
-                        VERBOSE(VB_GENERAL,
-                            "Data Refresh needed because user specified --refresh-second");
-                    }
-                    else
-                    {
-                        VERBOSE(VB_GENERAL,
-                            "Data Refresh always needed for tomorrow");
-                    }
+		  else
+		    {
+		      VERBOSE(VB_GENERAL,
+			      "Data Refresh needed because of user request");
+		    }
                     download_needed = true;
                 }
                 else
Index: programs/mythfilldatabase/main.cpp
===================================================================
--- programs/mythfilldatabase/main.cpp	(revision 14764)
+++ programs/mythfilldatabase/main.cpp	(working copy)
@@ -207,7 +207,7 @@
 
             fill_data.maxDays = QString(a.argv()[++argpos]).toInt();
 
-            if (fill_data.maxDays < 1 || fill_data.maxDays > 21)
+            if (fill_data.maxDays < 1 || fill_data.maxDays > REFRESH_MAX)
             {
                 printf("ignoring invalid parameter for --max-days\n");
                 fill_data.maxDays = 0;
@@ -215,20 +215,40 @@
         }
         else if (!strcmp(a.argv()[argpos], "--refresh-today"))
         {
-            fill_data.refresh_today = true;
+            fill_data.refresh_request[0] = true;
         }
         else if (!strcmp(a.argv()[argpos], "--dont-refresh-tomorrow"))
         {
-            fill_data.refresh_tomorrow = false;
+            fill_data.refresh_request[1] = false;
         }
         else if (!strcmp(a.argv()[argpos], "--refresh-second"))
         {
-            fill_data.refresh_second = true;
+            fill_data.refresh_request[2] = true;
         }
         else if (!strcmp(a.argv()[argpos], "--refresh-all"))
         {
-            fill_data.refresh_all = true;
+	  for( int i = 0; i < REFRESH_MAX; i++ )
+            fill_data.refresh_request[i] = true;
         }
+	else if (!strcmp(a.argv()[argpos], "--refresh-day"))
+        {
+            if (((argpos + 1) >= a.argc()))
+            {
+                printf("missing parameter for --refresh-day option\n");
+                return FILLDB_EXIT_INVALID_CMDLINE;
+            }
+
+            int day = QString(a.argv()[++argpos]).toInt();
+
+            if (day < 0 || day > REFRESH_MAX)
+            {
+                printf("ignoring invalid parameter for --refresh-day\n");
+            }
+	    else
+	    {
+	      fill_data.refresh_request[day] = true;
+	    }
+        }
         else if (!strcmp(a.argv()[argpos], "--dont-refresh-tba"))
         {
             fill_data.refresh_tba = false;
@@ -258,9 +278,8 @@
         else if (!strcmp(a.argv()[argpos], "--dd-grab-all"))
         {
             fill_data.dd_grab_all = true;
-            fill_data.refresh_today = false;
-            fill_data.refresh_tomorrow = false;
-            fill_data.refresh_second = false;
+	    for( int i = 0; i < REFRESH_MAX; i++ )
+	      fill_data.refresh_request[i] = false;
         }
 #endif
         else if (!strcmp(a.argv()[argpos], "--quiet"))
@@ -416,8 +435,9 @@
             cout << "--refresh-today\n";
             cout << "--refresh-second\n";
             cout << "--refresh-all\n";
+	    cout << "--refresh-day <number>";
             cout << "   (Only valid for selected grabbers: e.g. DataDirect)\n";
-            cout << "   Force a refresh today or two days (or every day) from now,\n";
+            cout << "   Force a refresh today, two days, every day, or a specific day from now,\n";
             cout << "   to catch the latest changes\n";
             cout << "--dont-refresh-tomorrow\n";
             cout << "   Tomorrow will always be refreshed unless this argument is used\n";
Index: programs/mythfilldatabase/filldata.h
===================================================================
--- programs/mythfilldatabase/filldata.h	(revision 14764)
+++ programs/mythfilldatabase/filldata.h	(working copy)
@@ -14,6 +14,8 @@
 #include "xmltvparser.h"
 #include "icondata.h"
 
+#define REFRESH_MAX 21
+
 struct Source
 {
     int id;
@@ -37,12 +39,13 @@
         lastdduserid(QString::null),    graboptions(""),
         raw_lineup(0),                  maxDays(0),
         interrupted(false),             endofdata(false),
-        refresh_today(false),           refresh_tomorrow(true),
-        refresh_second(false),          refresh_all(false),
         refresh_tba(true),              dd_grab_all(false),
         dddataretrieved(false),
         need_post_grab_proc(true),      only_update_channels(false),
-        channel_update_run(false) {}
+        channel_update_run(false) {
+	    for( int i = 0; i < REFRESH_MAX; i++ ) refresh_request[i] = false;
+	    refresh_request[1] = true;
+	}
 
     void DataDirectStationUpdate(Source source, bool update_icons = true);
     bool DataDirectUpdateChannels(Source source);
@@ -71,10 +74,7 @@
 
     bool    interrupted;
     bool    endofdata;
-    bool    refresh_today;
-    bool    refresh_tomorrow;
-    bool    refresh_second;
-    bool    refresh_all;
+    bool    refresh_request[REFRESH_MAX];
     bool    refresh_tba;
     bool    dd_grab_all;
     bool    dddataretrieved;
Index: contrib/smartfill
===================================================================
--- contrib/smartfill	(revision 0)
+++ contrib/smartfill	(revision 0)
@@ -0,0 +1,27 @@
+#! /bin/sh
+
+MFD=/var/log/MFD.out
+
+# Have a rolling refresh one week from now, since one channel has a bunch
+# of shows running one week late
+arg="--refresh-day 7"
+
+# Several shows are maybe re-broadcast on the weekend, so we want to force
+# the weekend to refresh while we still have a chance to record them today
+day=`date +%u`		#  %u     day of week (1..7); 1 is Monday
+saturday=`expr 6 - $day`
+sunday=`expr 7 - $day`
+if [ $day -le 4 ]; then
+    arg="$arg --refresh-day $saturday --refresh-day $sunday"
+fi
+    
+# With the random start times sometimes when we run just past midnight it
+# can mean that the data for today isn't refreshed with the default behaviour
+hour=`date +%H`
+if [ $hour -le 6 ]; then
+    arg="$arg --refresh-today"
+fi
+
+optimize_mythdb.pl
+mythfilldatabase --remove-new-channels $arg | tee $MFD
+

Property changes on: contrib/smartfill
___________________________________________________________________
Name: svn:executable
   + *

