diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-08-03 21:18:42 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-08-03 21:18:42 +0200 |
commit | 927f32d39b8a51450155974ce8df6696cabb380a (patch) | |
tree | 6246ff575ca2622318cdbd2b4152c7d85b1662f9 /src | |
parent | 941fa9062e2ac1709e8c99208e2f63226fe2c7a8 (diff) | |
parent | 356357373784e00ff6e06d36a3beaf3cdb562102 (diff) | |
download | AntennaPod-927f32d39b8a51450155974ce8df6696cabb380a.zip |
Merge branch 'mat-tso-inteligent_namefile' into develop
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/storage/DownloadRequester.java | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 29bd764dd..fb011d238 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.text.ExtendedMessageFormat; import android.content.Context; import android.content.Intent; @@ -61,7 +62,7 @@ public class DownloadRequester { .getName()) + "-" + i - + "." + + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(dest.getName()); if (AppConfig.DEBUG) Log.d(TAG, "Testing filename " + newName); @@ -289,8 +290,29 @@ public class DownloadRequester { } public String getMediafilename(FeedMedia media) { - return URLUtil.guessFileName(media.getDownload_url(), null, - media.getMime_type()); + String filename; + String titleBaseFilename = ""; + + // Try to generate the filename by the item title + if (media.getItem() != null && media.getItem().getTitle() != null) { + String title = media.getItem().getTitle(); + // Delete reserved characters + titleBaseFilename = title.replaceAll("[\\\\/%\\?\\*:|<>\"\\p{Cntrl}]", ""); + titleBaseFilename = titleBaseFilename.trim(); + } + + String URLBaseFilename = URLUtil.guessFileName(media.getDownload_url(), + null, media.getMime_type());; + + if (titleBaseFilename != "") { + // Append extension + filename = titleBaseFilename + FilenameUtils.EXTENSION_SEPARATOR + + FilenameUtils.getExtension(URLBaseFilename); + } else { + // Fall back on URL file name + filename = URLBaseFilename; + } + return filename; } } |