Fix downloads when feeds with same name have items with the same name
This commit is contained in:
parent
88289d02ae
commit
941ebbdc2b
|
@ -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;
|
||||
}
|
||||
return filename;
|
||||
final int filenameMaxLength = 220;
|
||||
if (baseFilename.length() > filenameMaxLength) {
|
||||
baseFilename = baseFilename.substring(0, filenameMaxLength);
|
||||
}
|
||||
return baseFilename + FilenameUtils.EXTENSION_SEPARATOR + media.getId()
|
||||
+ FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(urlBaseFilename);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue