Skip to content

Commit

Permalink
yt-dlpの更新処理時にログが出るように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Aug 10, 2024
1 parent 87e5b2f commit 6f968f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataInput;
import java.io.DataOutput;
Expand Down Expand Up @@ -59,6 +61,8 @@ public NicoAudioSourceManager() {
this(null, null);
}

private static final Logger log = LoggerFactory.getLogger(NicoAudioSourceManager.class);

public HttpInterfaceManager getHttpInterfaceManager() {
return httpInterfaceManager;
}
Expand Down Expand Up @@ -86,11 +90,13 @@ public NicoAudioSourceManager(String email, String password) {
public void updateYtDlp() {
Runtime runtime = Runtime.getRuntime();
try {
log.info("Updating yt-dlp.");
Process process = runtime.exec("python3 -m pip install -U --pre \"yt-dlp\"");
process.waitFor();
process.destroy();
log.info("yt-dlp update completed.");
} catch (Exception e) {
throw new RuntimeException(e);
log.error("Failed to update yt-dlp. Please run \"python3 -m pip install -U --pre yt-dlp\" to update.");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.parser.Parser;
Expand Down Expand Up @@ -87,15 +88,13 @@ public void process(LocalAudioTrackExecutor localExecutor) throws Exception {
}

//
private File downloadAudio(){
private @NotNull File downloadAudio(){
String path = new File(".").getAbsoluteFile().getParent();
Path file = Path.of(path,"cache" + File.separator + getIdentifier() + ".wav");

if (!Files.notExists(file)) {
return file.toFile();
} else {
if (Files.notExists(file)) {
try {
log.debug("downloading...");
log.info("Downloading NicoNico track from: {}", getIdentifier());
Runtime runtime = Runtime.getRuntime();
String command = "yt-dlp --extract-audio --audio-format wav https://www.nicovideo.jp/watch/" + getIdentifier() + " --output cache/" + getIdentifier() + ".wav";
Process process = runtime.exec(command);
Expand Down Expand Up @@ -132,8 +131,8 @@ private File downloadAudio(){
} catch (Exception e) {
throw new RuntimeException(e);
}
return file.toFile();
}
return file.toFile();
}

private String extractHlsAudioPlaylistUrl(HttpInterface httpInterface, String videoPlaylistUrl) throws IOException {
Expand Down

0 comments on commit 6f968f3

Please sign in to comment.