D wrapper around (some) of the pixiv web API
Révision | b1bd23854879047a369ecef3075b1981f9a767c7 (tree) |
---|---|
l'heure | 2023-01-28 14:59:11 |
Auteur | supercell <stigma@disr...> |
Commiter | supercell |
Update examples to use new API.
@@ -19,34 +19,37 @@ import core.time : seconds; | ||
19 | 19 | import std.random : uniform; |
20 | 20 | |
21 | 21 | import pixivd; |
22 | +import pixivd.types; | |
22 | 23 | |
23 | 24 | int main(string[] args) |
24 | 25 | { |
25 | 26 | write("Please enter your PHPSESSID: "); |
26 | 27 | string sessionId = readln().strip(); |
27 | 28 | |
28 | - auto client = Client(sessionId); | |
29 | + auto client = new Client(sessionId); | |
29 | 30 | |
30 | 31 | /* fetch the first page of daily illustrations */ |
31 | - long[] ids = client.fetchIllustrationsFollowing(); | |
32 | + Thumbnail[] thumbnails = client.fetchIllustrationsFollowing(); | |
32 | 33 | |
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); | |
37 | 38 | string artistDir = buildPath(getcwd(), |
38 | - illust.user.id ~ "_" ~ illust.user.name); | |
39 | + illust.userId ~ "_" ~ illust.userName); | |
39 | 40 | |
40 | 41 | if (false == exists(artistDir)) |
41 | 42 | mkdir(artistDir); |
42 | 43 | |
43 | - illust.download(artistDir); | |
44 | + client.downloadIllust(illust, artistDir); | |
44 | 45 | |
45 | - if (index + 1 < ids.length) { | |
46 | + if (index + 1 < thumbnails.length) { | |
47 | + /* So we don't spam the server too much. */ | |
46 | 48 | int sleepDuration = uniform(3, 8); |
47 | 49 | writefln("Sleeping for %d seconds...", sleepDuration); |
48 | 50 | Thread.sleep(sleepDuration.seconds); |
49 | 51 | } |
50 | 52 | } |
53 | + | |
51 | 54 | return 0; |
52 | 55 | } |
@@ -21,6 +21,7 @@ import core.time : seconds; | ||
21 | 21 | import std.random : uniform; |
22 | 22 | |
23 | 23 | import pixivd; |
24 | +import pixivd.types; | |
24 | 25 | |
25 | 26 | int main(string[] args) |
26 | 27 | { |
@@ -33,20 +34,12 @@ int main(string[] args) | ||
33 | 34 | write("enter your PHPSESSID: "); |
34 | 35 | scope sessionID = readln().strip(); |
35 | 36 | |
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); | |
45 | 38 | |
46 | 39 | foreach (index, string id; args[1..$]) { |
47 | - scope illust = client.fetchIllustration(id); | |
40 | + scope Illustration illust = client.fetchIllustration(id); | |
48 | 41 | writefln("Downloading illustration %s (%s)...", illust.id, illust.title); |
49 | - illust.download(getcwd()); | |
42 | + client.downloadIllust(illust, getcwd(), /* overwrite = */ true); | |
50 | 43 | |
51 | 44 | if (index + 1 < args[1..$].length) { |
52 | 45 | uint sleepDuration = uniform(2, 5); |