From ff1ce22277fefb1502b333f99dfd3849bef9df4e Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 21 Oct 2012 20:09:12 -0700 Subject: Beginnings of UploadTask. --- .../podcastuploader/control/UploadTask.java | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'src') 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 */ 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); } } -- cgit v1.2.3