2 * put your module comment here
6 package mircoders.media;
10 import freemarker.template.SimpleList;
11 import freemarker.template.SimpleHash;
20 * Please note: this media handler produces
21 * 3 media files, the raw .mp3, a .m3u which is
22 * contains the URL for the mp3 and a .pls which
23 * contains the URL to the mp3 in shoutcast playlist
24 * format. What's important is that the web server (of
25 * the media host) must recognize the .m3u and .pls file
26 * extensions and send the proper "audio/x-mpegurl"
27 * and "audio/x-scpls" mime-types respectively.
28 * If the web server is apache, it's easy, just
34 * to the file pointed to by the "TypesConfig"
35 * command in your apache config file. Or add
36 * and equivalent AddType command to your httpd.conf.
37 * Of course this assumes that the mod_mime is loaded.
39 * If the web server is not apache, then your on your own.
41 * @see mir.media.MirMedia
42 * @author mh <heckmann@hbe.ca>
46 public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
49 public void produce (Entity ent, Entity mediaTypeEnt )
50 throws MirMediaException {
52 // first check if the file exists
53 super.produce(ent, mediaTypeEnt);
55 String baseName = ent.getId();
56 String date = ent.getValue("date");
57 String datePath = StringUtil.webdbDate2path(date);
58 String mp3Pointer = getPublishHost()+ent.getValue("publish_path");
59 String mpegURLFile = baseName+".m3u";
60 String playlistFile = baseName+".pls";
63 //write the "meta" files
64 //first the .m3u since it only contains one line
65 FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
66 mp3Pointer.getBytes());
68 FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
69 mp3Pointer.getBytes());
70 } catch (Exception e) {
71 theLog.printError(e.toString());
72 throw new MirMediaException(e.toString());
76 public SimpleList getURL(Entity ent, Entity mediaTypeEnt)
78 SimpleList theList = new SimpleList();
80 //String stringSize = ent.getValue("size");
81 //int size = Integer.parseInt(stringSize, 10)/1024;
84 String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"),
87 // @todo the texts ("title") below urgently need to be sanely localizaeble
89 SimpleHash m3uHash = new SimpleHash();
90 m3uHash.put("publish_path", basePath+".m3u");
91 m3uHash.put("publish_server", ent.getValue("publish_server"));
92 m3uHash.put("title", "stream URL");
95 SimpleHash plsHash = new SimpleHash();
96 plsHash.put("publish_path", basePath+".pls");
97 plsHash.put("publish_server", ent.getValue("publish_server"));
98 plsHash.put("title", "playlist URL");
105 public String getDescr()