bb330f8063b45edacb43cad1af07c8da75d887c0
[mir.git] / source / mircoders / media / MediaHandlerRealAudio.java
1 /*
2  * put your module comment here
3  */
4
5
6 package  mircoders.media;
7
8 import java.util.*;
9
10 import freemarker.template.SimpleList;
11 import freemarker.template.SimpleHash;
12
13 import mir.media.*;
14 import mir.entity.*;
15 import mir.misc.*;
16 import mir.storage.*;
17
18
19
20 /**
21  * Handles realAudio .it manages the ram file.
22  *
23  * 03.2002 - reworked Realmedia handling. -mh
24  *
25  * @see mir.media.MediaHandlerGeneric
26  * @see mir.media.MirMedia
27  * @author john <john@manifestor.org>, mh <heckmann@hbe.ca>
28  * @version 11.10.2001
29  */
30
31
32 public class MediaHandlerRealAudio extends MediaHandlerAudio implements
33   MirMedia
34 {
35   public void produce (Entity ent, Entity mediaTypeEnt )
36     throws MirMediaException {
37
38     // first see if the file exists
39     super.produce(ent, mediaTypeEnt);
40
41     String baseName = ent.getId();
42     String date = ent.getValue("date");
43     String datePath = StringUtil.webdbDate2path(date);
44     String rtspDir = MirConfig.getProp("Producer.RealMedia.Path");
45     String rtspMediaHost = MirConfig.getProp("Producer.RealMedia.Host");
46
47     String RealMediaPointer = rtspMediaHost+ent.getValue("publish_path");
48     String RealMediaFile = datePath+ent.getId()+".ram";
49     try {
50       //write an rm (ram?. -mh) file
51       FileUtil.write(super.getStoragePath()+"/"+RealMediaFile,
52                       RealMediaPointer.getBytes());
53     } catch (Exception e) {
54       theLog.printError(e.toString());
55       throw new MirMediaException(e.toString());
56     }
57   }
58
59   public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
60   {
61     SimpleList theList = new SimpleList();
62
63     //String stringSize = ent.getValue("size");
64     //int size = Integer.parseInt(stringSize, 10)/1024;
65     theList.add(ent);
66    
67     String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"),
68                                             ".ra$","");
69
70     // @todo the texts ("title") below urgently need to be sanely localizaeble
71     // somehow
72     SimpleHash ramHash = new SimpleHash();
73     ramHash.put("publish_path", basePath+".ram");
74     ramHash.put("publish_server", MirConfig.getProp("Producer.Media.Host"));
75     ramHash.put("title", "stream URL");
76     theList.add(ramHash);
77
78     return theList;
79
80   }
81
82   public String getStoragePath()
83   {
84     return MirConfig.getProp("Producer.RealMedia.Path");
85   }
86
87   public String getDescr(Entity mediaType)
88   {
89     return "RealMedia Audio";
90   }
91
92   public String getPublishHost()
93   {
94     return MirConfig.getProp("Producer.RealMedia.Host");
95   }
96
97 }
98         
99         
100