|
10 | 10 | import java.util.List;
|
11 | 11 | import java.util.Random;
|
12 | 12 | import java.util.Scanner;
|
| 13 | +import java.util.concurrent.CompletableFuture; |
| 14 | +import java.util.concurrent.Executors; |
13 | 15 |
|
14 | 16 | import net.dv8tion.jda.api.entities.emoji.Emoji;
|
15 | 17 | import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
@@ -1489,59 +1491,65 @@ else if (mentionsList.size() < 1) {
|
1489 | 1491 | }
|
1490 | 1492 |
|
1491 | 1493 | private void AutoCropVideo(Message inputMessage, boolean autoautocrop) throws InterruptedException, IOException {
|
1492 |
| - String filename; |
1493 |
| - final Emoji converting = Emoji.fromUnicode("U+1F504"); |
1494 |
| - final Emoji uploading = Emoji.fromUnicode("U+1F4E4"); |
1495 |
| - String autocropmessage = ""; |
1496 |
| - if(autoautocrop) |
1497 |
| - autocropmessage = "Your video has large black bars in it that can be autocropped out. " + |
1498 |
| - "I will run s!autocrop on it, but if this is incorrect please report this to othello7. "; |
1499 |
| - |
1500 |
| - try { //get attachments |
1501 |
| - Attachment attachment = inputMessage.getAttachments().get(0); |
1502 |
| - if(attachment.isVideo()) { |
1503 |
| - filename = (DownloadFile(attachment, "autocrop")); |
1504 |
| - } else { |
1505 |
| - channel.sendMessage("Attachment is not a video").queue(); |
1506 |
| - return; |
1507 |
| - } |
1508 |
| - } catch (Exception e) { //get link |
1509 |
| - String content = inputMessage.getContentRaw(); |
1510 |
| - if (content.contains("http")) { |
1511 |
| - // Extract link from message |
1512 |
| - String link = content.substring(content.indexOf("http")); |
1513 |
| - |
1514 |
| - // Check if link leads to a video |
1515 |
| - //Connection.Response response = Jsoup.connect(link).execute(); |
1516 |
| - String contentType = "video";//response.contentType(); |
1517 |
| - |
1518 |
| - if (contentType.startsWith("video")) { |
1519 |
| - filename = DownloadFile(link, "autocrop"); |
| 1494 | + CompletableFuture.runAsync(() -> { |
| 1495 | + DeleteFiles("autocrop"); |
| 1496 | + String filename; |
| 1497 | + final Emoji converting = Emoji.fromUnicode("U+1F504"); |
| 1498 | + final Emoji uploading = Emoji.fromUnicode("U+1F4E4"); |
| 1499 | + String autocropmessage = ""; |
| 1500 | + if(autoautocrop) |
| 1501 | + autocropmessage = "Your video has large black bars in it that can be autocropped out. " + |
| 1502 | + "I will run s!autocrop on it, but if this is incorrect please report this to othello7. "; |
| 1503 | + |
| 1504 | + try { //get attachments |
| 1505 | + Attachment attachment = inputMessage.getAttachments().get(0); |
| 1506 | + if(attachment.isVideo()) { |
| 1507 | + filename = (DownloadFile(attachment, "autocrop")); |
1520 | 1508 | } else {
|
1521 |
| - channel.sendMessage("Link doesn't lead to a video!").queue(); |
| 1509 | + channel.sendMessage("Attachment is not a video").queue(); |
| 1510 | + return; |
| 1511 | + } |
| 1512 | + } catch (Exception e) { //get link |
| 1513 | + String content = inputMessage.getContentRaw(); |
| 1514 | + if (content.contains("http")) { |
| 1515 | + // Extract link from message |
| 1516 | + String link = content.substring(content.indexOf("http")); |
| 1517 | + |
| 1518 | + // Check if link leads to a video |
| 1519 | + //Connection.Response response = Jsoup.connect(link).execute(); |
| 1520 | + String contentType = "video";//response.contentType(); |
| 1521 | + |
| 1522 | + if (contentType.startsWith("video")) { |
| 1523 | + filename = DownloadFile(link, "autocrop"); |
| 1524 | + } else { |
| 1525 | + channel.sendMessage("Link doesn't lead to a video!").queue(); |
| 1526 | + return; |
| 1527 | + } |
| 1528 | + } |
| 1529 | + else{ |
| 1530 | + channel.sendMessage("No attachment or link").queue(); |
1522 | 1531 | return;
|
1523 | 1532 | }
|
1524 | 1533 | }
|
1525 |
| - else{ |
1526 |
| - channel.sendMessage("No attachment or link").queue(); |
1527 |
| - return; |
1528 |
| - } |
1529 |
| - } |
1530 |
| - |
1531 |
| - //convert |
1532 |
| - inputMessage.addReaction(converting).queue(); |
1533 |
| - ProcessBuilder pb = new ProcessBuilder("sh", "autocrop.sh", "autocrop/" + filename); |
1534 |
| - pb.directory(new File(System.getProperty("user.dir") + "/bot/")); |
1535 |
| - pb.start().waitFor(); |
1536 | 1534 |
|
1537 |
| - //upload |
1538 |
| - inputMessage.addReaction(uploading).queue(); |
1539 |
| - int dotindex = filename.lastIndexOf('.'); |
1540 |
| - String newfilename = filename.substring(0, dotindex) + "_autocrop" + filename.substring(dotindex); |
1541 |
| - File cropDir = new File(System.getProperty("user.dir") + "/bot/autocrop/"); |
1542 |
| - channel.sendMessage(autocropmessage + "Cropped:").addFiles(FileUpload.fromData(new File(cropDir, newfilename))).queue(); |
1543 |
| - |
1544 |
| - DeleteFiles("autocrop"); |
| 1535 | + try { |
| 1536 | + //convert |
| 1537 | + inputMessage.addReaction(converting).queue(); |
| 1538 | + ProcessBuilder pb = new ProcessBuilder("sh", "autocrop.sh", "autocrop/" + filename); |
| 1539 | + pb.directory(new File(System.getProperty("user.dir") + "/bot/")); |
| 1540 | + pb.start().waitFor(); |
| 1541 | + } catch (IOException | InterruptedException e) { |
| 1542 | + channel.sendMessage("Error processing your video :(").queue(); |
| 1543 | + } |
| 1544 | + |
| 1545 | + |
| 1546 | + //upload |
| 1547 | + inputMessage.addReaction(uploading).queue(); |
| 1548 | + int dotindex = filename.lastIndexOf('.'); |
| 1549 | + String newfilename = filename.substring(0, dotindex) + "_autocrop" + filename.substring(dotindex); |
| 1550 | + File cropDir = new File(System.getProperty("user.dir") + "/bot/autocrop/"); |
| 1551 | + channel.sendMessage(autocropmessage + "Cropped:").addFiles(FileUpload.fromData(new File(cropDir, newfilename))).queue(); |
| 1552 | + }, Executors.newSingleThreadExecutor()); |
1545 | 1553 | }
|
1546 | 1554 |
|
1547 | 1555 | private void UpdateEconomy() {
|
|
0 commit comments