4 Revize f42279665e ... 9216ef6849

Autor SHA1 Zpráva Datum
  mio 9216ef6849 daily: Prohibit BEGIN without END or END > BEGIN před 1 měsícem
  mio 4dde47aa56 Update documentation for daily command před 1 měsícem
  mio 72bd556e27 Add support for automatic daily end date. před 1 měsícem
  mio b78a891d6a Configure guix.scm to use meson build system před 1 měsícem
5 změnil soubory, kde provedl 129 přidání a 30 odebrání
  1. 19 0
      ChangeLog
  2. 6 1
      README.md
  3. 23 3
      docs/pixiv_down-daily.1
  4. 3 8
      guix.scm
  5. 78 18
      source/cmds/daily.d

+ 19 - 0
ChangeLog

@@ -1,3 +1,22 @@
+2024-10-15  mio  <stigma@disroot.org>
+
+	daily: Prohibit BEGIN without END or END > BEGIN
+
+	Update documentation for daily command
+
+2024-10-15  mio  <stigma@disroot.org>
+
+	Add support for automatic daily end date.
+	Dates are stored in $XDG_STATE_HOME/pixiv_down/last_daily_run on a
+	single line using the format YYYY-MM-DD.  No time is recorded, since
+	the daily command will use midnight as the end time (00:00)
+
+	Resolves: https://codeberg.org/supercell/pixiv_down/issues/32
+
+2024-10-15  mio  <stigma@disroot.org>
+
+	Configure guix.scm to use meson build system
+
 2024-10-13  mio  <stigma@disroot.org>
 
 	Update PHPSESSID link

+ 6 - 1
README.md

@@ -92,7 +92,7 @@ Commands:
       out the actions that would take place, without actually
       performing the actions.
 
-  daily <-e|--end END> [-b|--begin BEGIN] [-s|--sfw-only]
+  daily [-e|--end END] [-b|--begin BEGIN] [-s|--sfw-only]
 
       Download the latest content from all the accounts you follow.
       The END option specifies the date to stop downloading at. The
@@ -101,6 +101,11 @@ Commands:
       the date pixiv_down begins downloading from. Both BEGIN and
       END expect a date in the format YYYY-MM-DD.
 
+      An END date will be determined automatically if you have
+      previously called 'daily'.  It will use the BEGIN of the
+      previous run, regardless of if a manual date was provided
+      or not.
+
       The --sfw-only option restricts the content that is downloaded
       to that which is not marked as R-18.
 

+ 23 - 3
docs/pixiv_down-daily.1

@@ -1,4 +1,4 @@
-.Dd September 24, 2024
+.Dd October 15, 2024
 .Dt PIXIV_DOWN-DAILY 1
 .Os
 .Sh NAME
@@ -8,16 +8,23 @@
 .Sh SYNOPSIS
 .Nm
 .Cm daily
-.Fl e Ar end
 .Op Fl f
 .Op Fl s
 .Op Fl b Ar begin
+.Op Fl e Ar end
 .Sh DESCRIPTION
 .Nm
 .Cm daily
 will download all recently uploaded content from the artists that
 you follow, up to (and including)
 .Ar end .
+If no end date has been provided,
+.Nm
+will attempt to use the
+.Ar begin
+date from the previous run as
+.Ar end
+date for this run.
 .Pp
 .Nm
 .Cm daily
@@ -57,7 +64,7 @@ Only download content that is
 as determined by pixiv and the artist.  Omitting this flag will
 cause both SFW and NSFW content to be downloaded.
 .Sh EXAMPLES
-Assuming that the current date and time is 2024-04-01T10:00:00,
+Assuming that the current date and time is 2024-04-02T10:00:00,
 you can download only the content uploaded in the last day by
 running:
 
@@ -70,6 +77,19 @@ Or more generically:
 Both of the above commands will download content from
 2024-04-02T10:00:00 to 2024-04-01T00:00:00.
 .Pp
+If you have previously run
+.Cm daily ,
+then the
+.Va end
+date will be determined automatically, meaning you can just call
+
+.Dl $ pixiv_down daily
+
+and that will download the artworks between 2024-04-02T10:00:00
+and 2024-04-01:T00:00:00.  This works even if no
+.Va begin
+date was provided in the previous run.
+.Pp
 You can also specify a
 .Va begin
 date, which will cause downloading to stop at midnight (00:00:00)

+ 3 - 8
guix.scm

@@ -34,12 +34,10 @@
 	     (guix gexp)
 	     (guix licenses)
 	     (guix git-download)
-	     (guix build-system gnu)
-	     (gnu packages autotools)
+	     (guix build-system meson)
 	     (gnu packages certs)
 	     (gnu packages curl)
-	     (gnu packages dlang)
-	     (gnu packages gcc)
+	     (gnu packages gcc)          ;; gdc
 	     (gnu packages imagemagick)
 	     (gnu packages pkg-config))
 
@@ -51,14 +49,11 @@
  (source (local-file %source-dir
 		     #:recursive? #t
 		     #:select? (git-predicate %source-dir)))
- (build-system gnu-build-system)
+ (build-system meson-build-system)
  (arguments
   (list #:tests? #f))
  (native-inputs
   (list
-   autoconf
-   automake
-   gcc ;; needed for linking the executable
    gdc
    pkg-config))
  (inputs

+ 78 - 18
source/cmds/daily.d

@@ -16,15 +16,16 @@
  */
 module cmds.daily;
 
-import std.datetime.systime;
-
 import configuration;
 import pixiv;
 import pixiv_downloader;
+import std.datetime.systime;
 import std.experimental.logger;
 import term;
 import util;
 
+import std.typecons: nullable, Nullable;
+
 public int dailyHandle(string[] args, in Config config)
 {
    import core.time : TimeException;
@@ -43,12 +44,11 @@ public int dailyHandle(string[] args, in Config config)
    try {
       getopt(args,
          "begin|b", &rawBeginDate,
-         GetOptOption.required,
          "end|e", &rawEndDate,
          "force|f", &force,
          "sfw-only|s", &restrict);
    } catch (GetOptException e) {
-      stderr.writefln("pixiv_donw daily: %s", e.msg);
+      stderr.writefln("pixiv_down daily: %s", e.msg);
       stderr.writefln("Run 'pixiv_down help daily' for more information");
       return 1;
    }
@@ -69,12 +69,28 @@ public int dailyHandle(string[] args, in Config config)
       }
    }
 
-   try {
-      endDate = SysTime.fromISOExtString(rawEndDate ~ "T00:00:00+00:00");
-   } catch (TimeException te) {
-      stderr.writefln("pixiv_down daily: Failed to parse the end DATE: %s", rawEndDate);
-      stderr.writeln("Make sure it's in the format YYYY-MM-DD, for example: 2023-06-20");
+   /* Automatically determine the end date, based off of the last run
+    * of this command, but allow people to specify a custom end date. */
+   if (string.init != rawEndDate) {
+      try {
+         endDate = SysTime.fromISOExtString(rawEndDate ~ "T00:00:00+00:00");
+      } catch (TimeException te) {
+         stderr.writefln("pixiv_down daily: Failed to parse the end DATE: %s", rawEndDate);
+         stderr.writeln("Make sure it's in the format YYYY-MM-DD, for example: 2023-06-20");
+         return 1;
+      }
+   } else if (string.init != rawBeginDate) {
+      stderr.writeln("pixiv_down daily: Cannot determine END date when BEGIN date has been provided.");
+      stderr.writeln("                  Please manually provide and END date with the -e option.");
       return 1;
+   } else {
+      auto lastRunTime = fetchLastStartTime();
+      if (lastRunTime.isNull()) {
+         stderr.writeln("pixiv_down daily: No end date could be determined, please provide date.");
+         stderr.writeln("                  For example `pixiv_down daily -e 2023-06-20`");
+         return 1;
+      }
+      endDate = lastRunTime.get();
    }
 
    /*
@@ -86,10 +102,17 @@ public int dailyHandle(string[] args, in Config config)
       beginDate.minute = 59;
       beginDate.second = 59;
    }
-   stderr.writeln("Begin = ", beginDate);
-   stderr.writeln("End   = ", endDate);
+
+   if (endDate.stdTime > beginDate.stdTime) {
+      stderr.writeln("pixiv_down daily: Cannot download. Provided END date is after BEGIN date.");
+      stderr.writeln("                  pixiv_down downloads from newer date to older date.");
+      return 1;
+   }
+   stderr.writeln("Begin = ", (cast(Date)beginDate).toISOExtString());
+   stderr.writeln("End   = ", (cast(Date)endDate).toISOExtString());
 
    downloadDaily(DailyOptions(beginDate, endDate, restrict, force), config);
+   saveLastStartTime(beginDate);
 
    return 0;
 }
@@ -100,13 +123,16 @@ void displayDailyHelp()
 
    stderr.writefln(
       "pixiv_down daily - Download new content from followed artists.\n" ~
-      "\nUsage:\tpixiv_down daily --end DATE [options]\n" ~
+      "\nUsage:\tpixiv_down daily [options]\n" ~
       "\nThis command will, by default, download all the recently uploaded\n" ~
       "from the people you follow up to (and including) the end date.\n" ~
-      "This will also download both the \"safe\" works and \"r18\" works.\n" ~
-      "Use the RESTRICT option to change this.\n" ~
-      "\nThe only required option is the END date. Both the BEGIN and END\n" ~
-      "dates are in the format of YYYY-MM-DD, for example: 2023-06-20.\n" ~
+      "This will also download both the \"safe\" and \"r18\" works.  Use\n" ~
+      "the --sfw-only flag to change this.\n" ~
+      "\nBoth the BEGIN and END dates must follow the format YYYY-MM-DD,\n" ~
+      "for example: 2023-06-20.  The END date is only required for the\n" ~
+      "first run of the daily command.  Afterwards, the end date will be\n" ~
+      "determined automatically based on the last run's BEGIN date,\n" ~
+      "regardless of whether a BEGIN date was provided or not.\n" ~
       "\nOptions:\n" ~
       "   -b, --begin    BEGIN    \tThe date the begin downloading from.\n" ~
       "   -e, --end      END      \tThe date to finish downloading at.\n" ~
@@ -121,8 +147,8 @@ void displayDailyHelp()
       "\nI wouldn't recommend downloading all content from a specific day\n" ~
       "which is over a month or two ago, since this command isn't really\n" ~
       "designed for that. It'll require a lot of requests to the pixiv\n" ~
-      "server and will take a long while.  You'd be better using either the\n" ~
-      "'artist' or 'following' command.");
+      "server and will take a long while.  You'd be better using either\n" ~
+      "the 'artist' or 'following' command.");
 }
 
 
@@ -232,3 +258,37 @@ void downloadLatestNovels(in DailyOptions options, in Config config)
       }
    } while (!pastEndDate);
 }
+
+Nullable!SysTime fetchLastStartTime() nothrow
+{
+   import mlib.directories: getProjectDirectories;
+   import std.datetime.date: Date;
+   import std.path: buildPath;
+   import std.stdio: File;
+
+   Nullable!SysTime sysTime;
+   auto dirs = getProjectDirectories(null, "YumeNeru Software", "pixiv_down");
+
+   try {
+      auto file = File(buildPath(dirs.stateDir, "last_daily_run"), "r");
+      auto date = Date.fromISOExtString(file.readln());
+      sysTime = SysTime(date);
+   } catch (Exception) {
+      return sysTime;
+   }
+
+   return sysTime;
+}
+
+void saveLastStartTime(const ref SysTime startDate)
+{
+   import mlib.directories: getProjectDirectories;
+   import std.datetime.date: Date;
+   import std.path: buildPath;
+   import std.stdio: File;
+
+   auto dirs = getProjectDirectories(null, "YumeNeru Software", "pixiv_down");
+
+   auto file = File(buildPath(dirs.stateDir, "last_daily_run"), "w+");
+   file.writeln((cast(Date)startDate).toISOExtString());
+}