rework of media handling vis a vis storage and producing. making it more
[mir.git] / source / mircoders / media / MediaHandlerMp3.java
index 2ac0aa0..270bc64 100755 (executable)
@@ -43,48 +43,35 @@ import mir.storage.*;
 public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
 {
 
-    public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt )
-        throws MirMediaException {
-
-        String ext = mediaTypeEnt.getValue("name");
-        String dir = MirConfig.getProp("Producer.Media.Path");
-        String mediaHost = MirConfig.getProp("Producer.Media.Host");
-        String date = ent.getValue("date");
-        String datePath = StringUtil.webdbDate2path(date);
-        String baseName = ent.getId();
-        String mediaFname = baseName+"."+ext;
-        String mp3Pointer = mediaHost+datePath+mediaFname;
-        String mpegURLFile = baseName+".m3u"; 
-        String playlistFile = baseName+".pls"; 
-        Integer size = new Integer(uploadedData.length);
-        try {
-            FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData);
-            //FileUtil.write(dir+"/"+mediaFname, uploadedData);
-            //were done with the data, dereference.
-            uploadedData=null;
-            
-            //write the "meta" files
-            //first the .m3u since it only contains one line
-            FileUtil.write(dir+"/"+datePath+"/"+mpegURLFile,mp3Pointer.getBytes());
-            //now the .pls file
-            FileUtil.write(dir+"/"+datePath+"/"+playlistFile,mp3Pointer.getBytes());
-            ent.setValueForProperty("is_produced", "1");
-            ent.setValueForProperty("icon_is_produced", "1");
-            ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
-            //ent.setValueForProperty("publish_path", mediaFname);
-            ent.setValueForProperty("publish_server", mediaHost);
-            ent.setValueForProperty("size", size.toString());
-            ent.update();
-        } catch (Exception e) {
-            theLog.printError(e.toString());
-            throw new MirMediaException(e.toString());
-        }
-
-        return true;
+    public void produce (Entity ent, Entity mediaTypeEnt )
+      throws MirMediaException {
+      
+      // first check if the file exists
+      super.produce(ent, mediaTypeEnt);
+
+      String baseName = ent.getId();
+      String date = ent.getValue("date");
+      String datePath = StringUtil.webdbDate2path(date);
+      String mp3Pointer = getPublishHost()+ent.getValue("publish_path");
+      String mpegURLFile = baseName+".m3u"; 
+      String playlistFile = baseName+".pls"; 
+
+      try {
+        //write the "meta" files
+        //first the .m3u since it only contains one line
+        FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
+                      mp3Pointer.getBytes());
+        //now the .pls file
+        FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
+                      mp3Pointer.getBytes());
+      } catch (Exception e) {
+          theLog.printError(e.toString()); 
+          throw new MirMediaException(e.toString());
+      }
     }
 
-    public String getURL(Entity ent, Entity mediaTypeEnt)
-    {
+  public String getURL(Entity ent, Entity mediaTypeEnt)
+  {
       String stringSize = ent.getValue("size");
       if (stringSize == null)
         return null;