From 921d329825f8b7a5f1d6cf3208d3456b6172ccae Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 9 Oct 2018 11:58:30 -0400 Subject: [PATCH 1/4] Reddit ripper no longer tries to make files with long names --- .../com/rarchives/ripme/ripper/rippers/RedditRipper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java index 20d31d78..86a2f204 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java @@ -252,6 +252,11 @@ public class RedditRipper extends AlbumRipper { addURLToDownload(parseRedditVideoMPD(urls.get(0).toExternalForm()), new File(savePath)); } else { + // File names longer than this won't work on ext4 file systems + if (title.length() >= 235) { + LOGGER.info("File name is more than 254 chars, shortening"); + title = title.substring(0,235); + } addURLToDownload(urls.get(0), id + title, "", theUrl, null); } } else if (urls.size() > 1) { From cb124ae25e7de3da95a2d56d24cf2712b5a17eb6 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 9 Oct 2018 12:26:22 -0400 Subject: [PATCH 2/4] Removed filename length check from redditripper --- .../com/rarchives/ripme/ripper/rippers/RedditRipper.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java index 86a2f204..20d31d78 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java @@ -252,11 +252,6 @@ public class RedditRipper extends AlbumRipper { addURLToDownload(parseRedditVideoMPD(urls.get(0).toExternalForm()), new File(savePath)); } else { - // File names longer than this won't work on ext4 file systems - if (title.length() >= 235) { - LOGGER.info("File name is more than 254 chars, shortening"); - title = title.substring(0,235); - } addURLToDownload(urls.get(0), id + title, "", theUrl, null); } } else if (urls.size() > 1) { From ce4ea6ef84a3a07ffa71cb406f38898fd86e65a1 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 9 Oct 2018 12:26:53 -0400 Subject: [PATCH 3/4] Added max file name length work around to DownloadFileThread --- .../ripme/ripper/DownloadFileThread.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java index 2f8a1503..a74b50e7 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java @@ -1,11 +1,6 @@ package com.rarchives.ripme.ripper; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.lang.reflect.Array; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; @@ -210,7 +205,21 @@ class DownloadFileThread extends Thread { if (statusCode == 206) { fos = new FileOutputStream(saveAs, true); } else { - fos = new FileOutputStream(saveAs); + try { + fos = new FileOutputStream(saveAs); + } catch (FileNotFoundException e) { + // We do this because some filesystems have a max name length + if (e.getMessage().contains("File name too long")) { + logger.error("The filename " + saveAs.getName() + " is to long to be saved on this file system."); + logger.info("Shortening filename"); + String[] saveAsSplit = saveAs.getName().split("\\."); + String fileExt = saveAsSplit[saveAsSplit.length - 1]; + logger.info(saveAs.getName().substring(0, 254 - fileExt.length()) + fileExt); + String filename = saveAs.getName().substring(0, 254 - fileExt.length()) + "." + fileExt; + saveAs = new File(saveAs.getParentFile().getAbsolutePath() + "/" + filename); + fos = new FileOutputStream(saveAs); + } + } } byte[] data = new byte[1024 * 256]; int bytesRead; From c1047ec0baa8a5261a3a78b07eeb76562c5990d1 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 9 Oct 2018 12:41:43 -0400 Subject: [PATCH 4/4] Added some comments --- .../java/com/rarchives/ripme/ripper/DownloadFileThread.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java index a74b50e7..2563aba0 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java @@ -213,9 +213,14 @@ class DownloadFileThread extends Thread { logger.error("The filename " + saveAs.getName() + " is to long to be saved on this file system."); logger.info("Shortening filename"); String[] saveAsSplit = saveAs.getName().split("\\."); + // Get the file extension so when we shorten the file name we don't cut off the file extension String fileExt = saveAsSplit[saveAsSplit.length - 1]; + // The max limit for filenames on Linux with Ext3/4 is 255 bytes, on windows it's 256 chars so rather than + // bother with code with both platforms we just cut the file name down to 254 chars logger.info(saveAs.getName().substring(0, 254 - fileExt.length()) + fileExt); String filename = saveAs.getName().substring(0, 254 - fileExt.length()) + "." + fileExt; + // We can't just use the new file name as the saveAs because the file name doesn't include the + // users save path, so we get the user save path from the old saveAs saveAs = new File(saveAs.getParentFile().getAbsolutePath() + "/" + filename); fos = new FileOutputStream(saveAs); }