• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

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

D wrapper around (some) of the pixiv web API


Commit MetaInfo

Révisionb1bd23854879047a369ecef3075b1981f9a767c7 (tree)
l'heure2023-01-28 14:59:11
Auteursupercell <stigma@disr...>
Commitersupercell

Message de Log

Update examples to use new API.

Change Summary

Modification

--- a/examples/download_daily_images.d
+++ b/examples/download_daily_images.d
@@ -19,34 +19,37 @@ import core.time : seconds;
1919 import std.random : uniform;
2020
2121 import pixivd;
22+import pixivd.types;
2223
2324 int main(string[] args)
2425 {
2526 write("Please enter your PHPSESSID: ");
2627 string sessionId = readln().strip();
2728
28- auto client = Client(sessionId);
29+ auto client = new Client(sessionId);
2930
3031 /* fetch the first page of daily illustrations */
31- long[] ids = client.fetchIllustrationsFollowing();
32+ Thumbnail[] thumbnails = client.fetchIllustrationsFollowing();
3233
33- foreach (index, id; ids) {
34- /* you could fetch the illustration before writing this. */
35- writefln("Downloading illustration id %d...", id);
36- scope illust = client.fetchIllustration(to!string(id));
34+ foreach (index, Thumbnail thumb; thumbnails) {
35+ writefln("Downloading illustration id %d...", thumb.id);
36+ /* fetch the actual content piece */
37+ scope Illustration illust = client.fetchIllustration(thumb.id);
3738 string artistDir = buildPath(getcwd(),
38- illust.user.id ~ "_" ~ illust.user.name);
39+ illust.userId ~ "_" ~ illust.userName);
3940
4041 if (false == exists(artistDir))
4142 mkdir(artistDir);
4243
43- illust.download(artistDir);
44+ client.downloadIllust(illust, artistDir);
4445
45- if (index + 1 < ids.length) {
46+ if (index + 1 < thumbnails.length) {
47+ /* So we don't spam the server too much. */
4648 int sleepDuration = uniform(3, 8);
4749 writefln("Sleeping for %d seconds...", sleepDuration);
4850 Thread.sleep(sleepDuration.seconds);
4951 }
5052 }
53+
5154 return 0;
5255 }
--- a/examples/download_pixiv_image.d
+++ b/examples/download_pixiv_image.d
@@ -21,6 +21,7 @@ import core.time : seconds;
2121 import std.random : uniform;
2222
2323 import pixivd;
24+import pixivd.types;
2425
2526 int main(string[] args)
2627 {
@@ -33,20 +34,12 @@ int main(string[] args)
3334 write("enter your PHPSESSID: ");
3435 scope sessionID = readln().strip();
3536
36- writeln(sessionID);
37-
38- Client client = Client(sessionID);
39-
40- /*
41- * You could change the language here if you want.
42- * The default is "en".
43- */
44- client.lang = "en";
37+ auto client = new Client(sessionID);
4538
4639 foreach (index, string id; args[1..$]) {
47- scope illust = client.fetchIllustration(id);
40+ scope Illustration illust = client.fetchIllustration(id);
4841 writefln("Downloading illustration %s (%s)...", illust.id, illust.title);
49- illust.download(getcwd());
42+ client.downloadIllust(illust, getcwd(), /* overwrite = */ true);
5043
5144 if (index + 1 < args[1..$].length) {
5245 uint sleepDuration = uniform(2, 5);