D wrapper around (some) of the pixiv web API
Revision | c9a28e4f8521840f3919c5a38817906e6be1fdef (tree) |
---|---|
Time | 2023-09-26 18:56:48 |
Author | supercell <stigma@disr...> |
Commiter | supercell |
Include current progress in PageAlreadyDownloaded
@@ -44,6 +44,10 @@ struct DownloadCompleteEvent | ||
44 | 44 | /// |
45 | 45 | struct PageAlreadyDownloadedEvent |
46 | 46 | { |
47 | + /// The current page number (1-based numbering) | |
48 | + size_t currentPage; | |
49 | + /// The total number of pages (1-based numbering) | |
50 | + size_t totalPages; | |
47 | 51 | } |
48 | 52 | |
49 | 53 | /** |
@@ -814,7 +818,12 @@ private: | ||
814 | 818 | throw new PixivJSONException("JSON response contains no 'body'."); |
815 | 819 | } |
816 | 820 | |
817 | - foreach (jsonobj; json["body"].array) | |
821 | + const jsonBody = json["body"].array; | |
822 | + // +1 so this matches PageAlreadyDownloaded containing the | |
823 | + // 1-based numbering of the current page. | |
824 | + const totalNumberOfPages = jsonBody.length + 1; | |
825 | + | |
826 | + foreach (pageNumber, jsonobj; jsonBody) | |
818 | 827 | { |
819 | 828 | import std.path : baseName, stripExtension; |
820 | 829 |
@@ -824,7 +833,7 @@ private: | ||
824 | 833 | string mode = "w+"; |
825 | 834 | |
826 | 835 | if (true == exists(baseFileName) && false == overwrite) { |
827 | - emit(PageAlreadyDownloadedEvent()); | |
836 | + emit(PageAlreadyDownloadedEvent(pageNumber + 1, totalNumberOfPages)); | |
828 | 837 | continue; |
829 | 838 | } |
830 | 839 |