diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-01-13 17:27:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-13 17:27:16 +0100 |
commit | 63e9d7f6965a859947209a4f287469b2e8789403 (patch) | |
tree | 4223b2aeb98a8fae2e1f782f9914e4c983191245 /core | |
parent | c5b34114cdc1a7bd0de2716dc4d7d3da66f95a2d (diff) | |
parent | 941ebbdc2bc4edc60f3f036dcc71f2ade40d7cb0 (diff) | |
download | AntennaPod-63e9d7f6965a859947209a4f287469b2e8789403.zip |
Merge pull request #6265 from ByteHamster/fix_duplicate_name
Fix downloads when feeds with same name have items with the same name
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java index 6fcb471bd..d6a4b8378 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadRequestCreator.java @@ -39,7 +39,7 @@ public class DownloadRequestCreator { final boolean partiallyDownloadedFileExists = media.getFile_url() != null && new File(media.getFile_url()).exists(); File dest; - if (media.getFile_url() != null && new File(media.getFile_url()).exists()) { + if (partiallyDownloadedFileExists) { dest = new File(media.getFile_url()); } else { dest = new File(getMediafilePath(media), getMediafilename(media)); @@ -102,7 +102,7 @@ public class DownloadRequestCreator { if (feed.getTitle() != null && !feed.getTitle().isEmpty()) { filename = feed.getTitle(); } - return "feed-" + FileNameGenerator.generateFileName(filename); + return "feed-" + FileNameGenerator.generateFileName(filename) + feed.getId(); } private static String getMediafilePath(FeedMedia media) { @@ -112,7 +112,6 @@ public class DownloadRequestCreator { } private static String getMediafilename(FeedMedia media) { - String filename; String titleBaseFilename = ""; // Try to generate the filename by the item title @@ -123,18 +122,17 @@ public class DownloadRequestCreator { String urlBaseFilename = URLUtil.guessFileName(media.getDownload_url(), null, media.getMime_type()); + String baseFilename; if (!titleBaseFilename.equals("")) { - // Append extension - final int filenameMaxLength = 220; - if (titleBaseFilename.length() > filenameMaxLength) { - titleBaseFilename = titleBaseFilename.substring(0, filenameMaxLength); - } - filename = titleBaseFilename + FilenameUtils.EXTENSION_SEPARATOR - + FilenameUtils.getExtension(urlBaseFilename); + baseFilename = titleBaseFilename; } else { - // Fall back on URL file name - filename = urlBaseFilename; + baseFilename = urlBaseFilename; + } + final int filenameMaxLength = 220; + if (baseFilename.length() > filenameMaxLength) { + baseFilename = baseFilename.substring(0, filenameMaxLength); } - return filename; + return baseFilename + FilenameUtils.EXTENSION_SEPARATOR + media.getId() + + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(urlBaseFilename); } } |