Skip to content
Merged

Dev #73

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '25'
java-version: '21'
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }}
Expand All @@ -39,10 +39,10 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '25'
java-version: '21'
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }}
Expand All @@ -61,10 +61,10 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 25
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '25'
java-version: '21'
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }}
Expand Down
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ A convenient tool to download pictures from various pixiv and APIs.
- Highly customizable naming rules and fetching urls

# Screenshots

![demo](https://github.com/user-attachments/assets/26091bfd-c9ec-47a0-9e62-21d39f9fc667)
![gif](https://user-images.githubusercontent.com/73475219/206824795-d3332057-41e5-4271-abdd-446a02a9db3c.gif)
![image](https://user-images.githubusercontent.com/73475219/206455033-dc49237b-b8f1-4a39-bfa5-3f64b6f71fb1.png)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GUI:
![image](https://user-images.githubusercontent.com/73475219/206438395-89e1eec5-f734-484f-94d9-2b82a6c63f69.png)

命令行:
![demo](https://github.com/user-attachments/assets/26091bfd-c9ec-47a0-9e62-21d39f9fc667)
![2022-11-18 19-42-43_2](https://user-images.githubusercontent.com/73475219/202701179-2b8439ac-0f0a-4f12-9fbc-9574a1620411.gif)

# 如何使用
Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<groupId>xyz.zcraft</groupId>
<artifactId>ACGPicDownload</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>

<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -94,17 +94,17 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>25</version>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>25</version>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>25</version>
<version>21</version>
</dependency>
<dependency>
<groupId>io.github.palexdev</groupId>
Expand Down Expand Up @@ -136,7 +136,7 @@
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>25</version>
<version>21</version>
</dependency>
</dependencies>
</project>
100 changes: 100 additions & 0 deletions src/main/java/xyz/zcraft/acgpicdownload/commands/pixiv/Complete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package xyz.zcraft.acgpicdownload.commands.pixiv;

import xyz.zcraft.acgpicdownload.util.Logger;
import xyz.zcraft.acgpicdownload.util.pixiv.PixivArtwork;
import xyz.zcraft.acgpicdownload.util.pixiv.PixivFetchUtil;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Stream;

public class Complete {
private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(Complete.class);
private static final Logger out = new Logger("Complete");

private int threads = 2;
private int retries = 5;

public List<PixivArtwork> invoke(List<String> argList, Profile profile, List<PixivArtwork> previous) throws Exception {
for (int i = 1; i < argList.size(); i++) {
switch (argList.get(i).toLowerCase()) {
case "-t", "-thread" -> {
if (argList.size() > i + 1) {
i++;
this.threads = Integer.parseInt(argList.get(i));
} else {
out.err("Please specify a thread count");
throw new IllegalArgumentException("Please specify a thread count");
}

}

case "-r", "-retry" -> {
if (argList.size() > i + 1) {
i++;
this.retries = Integer.parseInt(argList.get(i));
} else {
out.err("Please specify time of retries");
throw new IllegalArgumentException("Please specify time of retries");
}

}
}
}

final List<PixivArtwork> result = new LinkedList<>();

previous.stream().filter(p -> p.getLikeCount() != 0 || p.getBookmarkData() != null).forEach(result::add);
final List<PixivArtwork> list = previous.stream().filter(p -> p.getLikeCount() == 0 && p.getBookmarkData() == null).toList();
final List<PixivArtwork> failedList = new LinkedList<>();

out.info("Got " + list.size() + " artworks to complete data.");

AtomicInteger completed = new AtomicInteger();
AtomicInteger failed = new AtomicInteger();

try (ThreadPoolExecutor tpe = (ThreadPoolExecutor) Executors.newFixedThreadPool(threads)) {
list.forEach(t -> tpe.execute(() -> {
int tries = 1;
while (tries <= retries) {
try {
result.add(PixivFetchUtil.getArtwork(t.getId(), profile.cookie(), profile.proxyHost(), profile.proxyPort()));
completed.getAndIncrement();
return;
} catch (IOException e) {
tries++;
}
}

failedList.add(t);
failed.getAndIncrement();
}));

while (completed.get() + failed.get() < list.size()) {
System.out.print("\033[0K\033[32mCompleted: " + completed + "/" + list.size() +
(failed.get() == 0 ? "" : " \033[31mFailed: " + failed + "\033[32m") + "\033[0m\n");
System.out.print("\033[0K[");
int v = (int) (Math.floor(((double) (completed.get() + failed.get()) / list.size()) * 16.0));
for (int j = 0; j < v; j++) System.out.print("=");
for (int k = 0; k < (16 - v); k++) System.out.print(" ");
System.out.print("]\n");
Thread.sleep(1000);
System.out.print("\033[2F");
}
}

final String failedIds = failedList.stream()
.flatMap((Function<PixivArtwork, Stream<?>>) pixivArtwork -> Stream.of(pixivArtwork.getId()))
.toList().toString();

if (failed.get() > 0) out.err("Failed to complete " + failed + " artworks: " + failedIds);
else out.info("All artworks completed.");

return result;
}
}
Loading
Loading