summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/storage
diff options
context:
space:
mode:
authormat tso <mat-tso@topmail.ie>2013-05-15 23:15:55 +0200
committermat tso <mat-tso@topmail.ie>2013-05-16 00:06:48 +0200
commit92a0b322da7ce88447d8d8489fa0b931af99e00c (patch)
tree874ee900774fa38f3016b2141150a3210f70c2fd /src/de/danoeh/antennapod/storage
parent4707139def5500f1039de669e53822d47855008c (diff)
downloadAntennaPod-92a0b322da7ce88447d8d8489fa0b931af99e00c.zip
Build media file name based on item title
Use the media item title as a filename base if exist, fallback on the url name otherwise.
Diffstat (limited to 'src/de/danoeh/antennapod/storage')
-rw-r--r--src/de/danoeh/antennapod/storage/DownloadRequester.java28
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;
}
}