diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2013-08-14 15:46:30 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2013-08-14 15:46:30 +0200 |
commit | a1b0b5ac095c5fbe5f87f648f635eda15ddbd044 (patch) | |
tree | 63521ad898557acb17765c53aa9e1fefa0e15e31 | |
parent | cb27c28c09b3d363d2a037b40dc3b4e74fa064b7 (diff) | |
download | AntennaPod-a1b0b5ac095c5fbe5f87f648f635eda15ddbd044.zip |
Re-added pull-request
Was accidentally removed during merge
-rw-r--r-- | src/de/danoeh/antennapod/storage/DownloadRequester.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/de/danoeh/antennapod/storage/DownloadRequester.java b/src/de/danoeh/antennapod/storage/DownloadRequester.java index 4e74d5e98..246b8bdfd 100644 --- a/src/de/danoeh/antennapod/storage/DownloadRequester.java +++ b/src/de/danoeh/antennapod/storage/DownloadRequester.java @@ -63,7 +63,7 @@ public class DownloadRequester { .getName()) + "-" + i - + "." + + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(dest.getName()); if (AppConfig.DEBUG) Log.d(TAG, "Testing filename " + newName); @@ -293,8 +293,28 @@ 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; + } } |