summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2012-10-21 20:09:12 -0700
committerJesse Morgan <jesse@jesterpm.net>2012-10-21 20:09:12 -0700
commitff1ce22277fefb1502b333f99dfd3849bef9df4e (patch)
tree770d4c858ba8a0152b8e230b6986e5d5c3751ecf
parent765ce9068eae09c4654fe43e135b0014df985efa (diff)
Beginnings of UploadTask.
-rw-r--r--src/net/jesterpm/podcastuploader/control/UploadTask.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/net/jesterpm/podcastuploader/control/UploadTask.java b/src/net/jesterpm/podcastuploader/control/UploadTask.java
index 2ed1f85..09200e1 100644
--- a/src/net/jesterpm/podcastuploader/control/UploadTask.java
+++ b/src/net/jesterpm/podcastuploader/control/UploadTask.java
@@ -4,6 +4,11 @@
package net.jesterpm.podcastuploader.control;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import java.util.Date;
+
import net.jesterpm.podcastuploader.config.Config;
import net.jesterpm.podcastuploader.ui.ProgressWindow;
@@ -12,11 +17,89 @@ import net.jesterpm.podcastuploader.ui.ProgressWindow;
* @author Jesse Morgan <jesse@jesterpm.net>
*/
public class UploadTask {
+ /**
+ * This is the filename of the metadata file with a path separator prefixed.
+ */
+ private static final String METADATA_FILE =
+ System.getProperty("file.separator") + "/metadata.txt";
+
+ /**
+ * Progress window.
+ */
+ private final ProgressWindow mProgressWindow;
+
+ /**
+ * Application config.
+ */
+ private final Config mAppConfig;
+
+ /**
+ * Podcast metadata file.
+ */
+ private final Config mMetadata;
+
+ /**
+ * UploadTask Constructor.
+ * @param appconfig The application config
+ * @param win The progress window user interface.
+ * @param dir The directory to upload.
+ */
public UploadTask(final Config appconfig, final ProgressWindow win, final String dir) {
+ mProgressWindow = win;
+ mAppConfig = appconfig;
+ mMetadata = new Config(dir + METADATA_FILE);
}
+ /**
+ * Uploads the podcast described in the metadata file.
+ *
+ * Expected keys:
+ * date The podcast date.
+ * title The podcast title.
+ * author The podcast author.
+ *
+ * Optional keys:
+ * series The series the video is part of.
+ * video Name of the video file.
+ * audio Name of the audio file.
+ * video_lowres Name of the low-res video file
+ * image Image associated with the podcast
+ * mobileimage Image for mobile phones
+ * description Podcast description
+ *
+ * Video and/or audio is required, as without one of them there is nothing
+ * to upload.
+ */
public void run() {
+ DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT);
+ final Date date = fmt.parse(mMetadata.get("date"));
+
+ fmt = new SimpleDateFormat("yyyyMMdd");
+ final String baseFilename = fmt.format(date) + "-"
+ + safeString(mMetadata.get("title"));
+ }
+
+ private String safeString(String str) {
+ char[] newStr = str.trim().toLowerCase().toCharArray();
+ boolean firstSpace = true;
+ int p = 0;
+ for (int i = 0; i < newStr.length; i++) {
+ if (Character.isWhitespace(newStr[i])) {
+ if (firstSpace) {
+ newStr[p++] = '-';
+ firstSpace = false;
+ }
+
+ } else if (Character.isLetterOrDigit(newStr[i])) {
+ newStr[p++] = newStr[i];
+ firstSpace = true;
+ } else {
+ firstSpace = true;
+ }
+ }
+
+ return new String(newStr, 0, p);
}
}