• R/O
  • HTTP
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A CLI tool for downloading from pixiv.net


Commit MetaInfo

修订版46c78720d8de7460f4737b6e0443e6b565e8c3ed (tree)
时间2023-09-29 19:04:43
作者mio <stigma@disr...>
Commitermio

Log Message

Further improvements to the progress bar

Still can't say I'm completely happy with this (trailing newlines and
single-paged illustrations not changing the final message to 'Finished')
but it's an improvement.

I did spend a while trying to get a graphic progress bar, but couldn't
integrate the UI in a way that I liked (the current implementation looks
better IMO).

See: https://codeberg.org/supercell/pixiv_down/issues/2

更改概述

差异

--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,16 +21,17 @@ anything, has changed.
2121 * All the help messages have been re-written to be more helpful and
2222 provide examples.
2323 * Images can be resumed if interrupted.
24+* Progress bars used to display download progress.
2425
2526 ### Artist Command
2627
2728 In the first version of pixiv_down, the `artist` command would only download
2829 illustrations, requiring the use of `--type manga` if you wanted to download
29-their manga as well. The new version of pixiv_down changes this so it will
30-download *both* illustrations and manga by default.
30+their manga as well. The new version of pixiv_down will download *both*
31+illustrations and manga by default.
3132
32-* Allow multiple artist IDs to consecutively download more than one artist
33- in one hit.
33+* Permits multiple artist IDs at once to consecutively download more than one
34+ artist in a single run.
3435 * Download both illustrations and manga by default.
3536 * Specify only one by using the `--type` option.
3637
@@ -53,4 +54,11 @@ your publicaly followed accounts.
5354 * Removed `-l, --limit` option. It's highly probably this will return with a
5455 different meaning.
5556
57+### Bug Fixes
58+
59+* Using incorrect filename when downloading an Ugoira that uses Japanese in
60+ the title.
61+* Incorrect behaviour when attempting to resume a previous manga download
62+ that wasn't finished.
63+
5664 [Unreleased]: https://codeberg.org/supercell/pixiv_down/compare/v0.1...HEAD
--- a/dub.sdl
+++ b/dub.sdl
@@ -18,7 +18,7 @@ dependency "magickd:graphicsmagick_c" \
1818
1919 dependency "pixivd" \
2020 repository="git+https://pf.osdn.net/gitroot/n/ne/nemophila/pixivd.git" \
21- version="c9a28e4f8521840f3919c5a38817906e6be1fdef"
21+ version="ec0f80a31846bc9a58dd1a31e583cbfebcfbc050"
2222
2323 ########################################################
2424 # If you are using the "fetch_dependencies.sh" script, #
@@ -35,10 +35,6 @@ dependency "pixivd" \
3535 # version="*"
3636
3737
38-
39-
40-
41-
4238 # Q16 default as that's what I use. Feel free to change
4339 # this to suit yourself, just don't commit it.
4440 configuration "Q16" {
--- a/dub.selections.json
+++ b/dub.selections.json
@@ -2,6 +2,6 @@
22 "fileVersion": 1,
33 "versions": {
44 "magickd": {"version":"dd4985919d78d0cf37ab4b2ab99bb2ecec6aec15","repository":"git+https://repo.or.cz/magickd.git"},
5- "pixivd": {"version":"c9a28e4f8521840f3919c5a38817906e6be1fdef","repository":"git+https://pf.osdn.net/gitroot/n/ne/nemophila/pixivd.git"}
5+ "pixivd": {"version":"ec0f80a31846bc9a58dd1a31e583cbfebcfbc050","repository":"git+https://pf.osdn.net/gitroot/n/ne/nemophila/pixivd.git"}
66 }
77 }
--- a/insert_gitversion.sh
+++ b/insert_gitversion.sh
@@ -15,7 +15,7 @@ then
1515 printf 'enum gitDate = "%s";\n' "$gdate" >> source/git_version.d
1616 printf 'enum gitHash = "%s";\n' "$ghash" >> source/git_version.d
1717
18- printf "[insert_gitversion] Success!\n"
18+ printf "[prebuild_command] Successfully inserted git version.\n"
1919 fi
2020
2121
--- a/source/app.d
+++ b/source/app.d
@@ -48,64 +48,97 @@ import pixivd.client;
4848
4949 class ProgressMonitor
5050 {
51- import std.format : format;
52- import util : getTerminalColumns;
51+ private size_t currentPage = 1;
52+ private const size_t totalPages;
5353
54- size_t currentImage = 1;
54+ this(size_t totalPages)
55+ {
56+ this.totalPages = totalPages;
57+ }
5558
5659 void alreadyComplete(PageAlreadyDownloadedEvent ev)
5760 {
5861 import std.conv : ConvException, to;
62+ import std.format : format;
5963
60- size_t promptLength = 0;
61-
62- try {
63- const numberOfDigits = to!string(ev.totalPages).length;
64- const modifier = format("%%%dd", numberOfDigits);
65- const promptWM = format("\r Already downloaded page %s.",
66- modifier);
67- writefln(promptWM, currentImage);
68- } catch (ConvException ce) {
64+ string value;
65+ if (convertToString(ev.totalPages, value)) {
66+ const numerOfDigits = value.length;
67+ const modifier = format("%%%dd", numerOfDigits);
68+ // ^ Determines the padding (e.g. %2d)
69+ const prompt = format("\r Previously downloaded page %s/%d.",
70+ modifier, ev.totalPages);
71+ writefln(prompt, ev.currentPage);
72+ } else {
6973 debug(app)
7074 {
71- stderr.writefln("ERORR converting size_t to string");
72- stderr.writefln(" --> %s", ce.msg);
75+ log.errorf("Converting size_t to string: %d", ev.totalPages);
7376 }
74- writefln("\r Already downloaded page %d.", currentImage);
77+ writefln("\r Previously downloaded page %d/%d.",
78+ ev.currentPage, ev.totalPages);
7579 }
76- currentImage += 1;
80+ currentPage += 1;
7781 }
7882
7983 void update(DownloadProgressEvent ev)
8084 {
81- import std.math.traits : isNaN, isInfinity;
85+ import std.format : format;
86+ import std.math : isNaN, isInfinity;
87+
88+ string value;
89+ string prompt;
90+ if (convertToString(totalPages, value)) {
91+ const modifier = format("%%%dd", value.length);
92+ prompt = format("\r Downloading page %s/%d...", modifier,
93+ totalPages);
94+ prompt = format(prompt, currentPage);
95+ } else {
96+ prompt = format("\r Downloading page %d/%d...");
97+ }
98+
99+ write(prompt);
82100
83101 if (ev.current == 0.0 || ev.total == 0.0) {
84- write("\r 00.00%");
102+ write(" ( 0.00%).");
85103 } else {
86- double percentage = (cast(double)ev.current / ev.total) * 100;
104+ const percentage = (cast(double)ev.current / ev.total) * 100.0;
87105 if (isNaN(percentage) || isInfinity(percentage)) {
88- percentage = 0.0;
106+ write(" ( 0.00%).");
107+ } else {
108+ writef(" (%6.2f%%).", percentage);
89109 }
90- writef("\r Downloading page %d... %6.2f%%", currentImage,
91- percentage);
92110 }
93111 }
94112
95113 void complete(DownloadCompleteEvent ev)
96114 {
115+ import std.format : format;
116+ import std.range : repeat;
117+ import util : getTerminalColumns;
118+
119+ string value;
120+
97121 if (ev.forPage) {
98- string prompt = "\r Downloaded page %d.".format(currentImage);
99- size_t remLength = getTerminalColumns() - prompt.length;
122+ if (convertToString(totalPages, value)) {
123+ const modifier = format("%%%dd", value.length);
124+ const prompt = format("\r Finished downloading page %s/%d.",
125+ modifier, totalPages);
126+ const remLength = getTerminalColumns() - prompt.length;
127+
128+ writef(prompt, currentPage);
129+ writefln("%s", ' '.repeat(remLength));
130+ } else {
131+ const prompt = format("\r Finished downloading page %d/%d.",
132+ currentPage, totalPages);
133+ const remLength = getTerminalColumns() - prompt.length;
100134
101- write(prompt);
102- for (int i = 0; i < remLength; i++) {
103- write(' ');
135+ write(prompt);
136+ writefln("%s", ' '.repeat(remLength));
104137 }
105-
106- currentImage += 1;
138+ currentPage += 1;
139+ } else {
140+ write("\n");
107141 }
108- write('\n');
109142 }
110143 }
111144
@@ -130,6 +163,28 @@ version(appimage) {
130163 }
131164 enum PixivDownVersionString = gitDate ~ " (" ~ gitHash ~ ")";
132165
166+///
167+/// Converts *value* to a string *converted*.
168+///
169+/// Params:
170+/// value = the value to convert
171+/// converted = the output that will hold the converted string.
172+///
173+/// Returns: `true` if the conversion was successful, or `false`
174+/// if a ConvException was thrown.
175+///
176+private bool convertToString(size_t value, out string converted)
177+{
178+ import std.conv : ConvException, to;
179+
180+ try {
181+ converted = to!string(value);
182+ return true;
183+ } catch (ConvException ce) {
184+ return false;
185+ }
186+}
187+
133188 /**
134189 * Prompt for the PHPSESSID cookie.
135190 *
@@ -263,7 +318,7 @@ void downloadIllust(ref Illustration illust, ref Config conf,
263318 illust.title);
264319 log.tracef("Downloading post type %s", illust.type);
265320
266- scope monitor = new ProgressMonitor();
321+ scope monitor = new ProgressMonitor(illust.pages);
267322 conf.client.connect(&monitor.alreadyComplete);
268323 conf.client.connect(&monitor.update);
269324 conf.client.connect(&monitor.complete);
@@ -273,6 +328,7 @@ void downloadIllust(ref Illustration illust, ref Config conf,
273328 } catch (FileException fe) {
274329 log.warningf("FileException: %s (overwrite = %s)", fe.msg,
275330 overwrite ? "true" : "false");
331+ stderr.write("\r");
276332 stderr.writefln("[%s] %s - %s has already been downloaded", illust.type,
277333 illust.userName, illust.title);
278334 }
--- a/source/util.d
+++ b/source/util.d
@@ -1,10 +1,31 @@
1+/*
2+ * pixiv_down - CLI-based downloading tool for https://www.pixiv.net.
3+ * Copyright (C) 2023 Mio
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, version 3 of the License.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
16+ */
117 module util;
218
3-import std.conv;
4-import std.process;
5-
19+///
20+/// Returns the number of columns in the terminal.
21+///
22+/// Bugs: Only works on Posix.
23+///
624 ushort getTerminalColumns()
725 {
26+ import std.process : environment;
27+ import std.conv : parse;
28+
829 string columnsEnv = environment.get("COLUMNS");
930 if (null is columnsEnv) {
1031 return posixGetTerminalColumns();
@@ -12,13 +33,15 @@ ushort getTerminalColumns()
1233 return parse!ushort(columnsEnv);
1334 }
1435
36+private:
37+
1538 version (Posix)
1639 {
17- import core.sys.posix.sys.ioctl;
18- import core.sys.posix.unistd;
19-
2040 ushort posixGetTerminalColumns()
2141 {
42+ import core.sys.posix.sys.ioctl : winsize, TIOCGWINSZ, ioctl;
43+ import core.sys.posix.unistd : STDOUT_FILENO;
44+
2245 winsize w;
2346 ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
2447 return w.ws_col;