2 * put your module comment here
16 * Please note: this media handler produces
17 * 3 media files, the raw .mp3, a .m3u which is
18 * contains the URL for the mp3 and a .pls which
19 * contains the URL to the mp3 in shoutcast playlist
20 * format. What's important is that the web server (of
21 * the media host) must recognize the .m3u and .pls file
22 * extensions and send the proper "audio/x-mpegurl"
23 * and "audio/x-scpls" mime-types respectively.
24 * If the web server is apache, it's easy, just
30 * to the file pointed to by the "TypesConfig"
31 * command in your apache config file. Or add
32 * and equivalent AddType command to your httpd.conf.
33 * Of course this assumes that the mod_mime is loaded.
35 * If the web server is not apache, then your on your own.
37 * @see mir.media.MirMedia
38 * @author mh <heckmann@hbe.ca>
42 public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
45 public boolean set (byte[] uploadedData, Entity ent, Entity mediaTypeEnt ) {
46 String ext = mediaTypeEnt.getValue("name");
47 String dir = MirConfig.getProp("Producer.Media.Path");
48 String mediaHost = MirConfig.getProp("Producer.Media.Host");
49 String date = ent.getValue("date");
50 String datePath = StringUtil.webdbDate2path(date);
51 String baseName = ent.getId();
52 String mediaFname = baseName+"."+ext;
53 String mp3Pointer = mediaHost+datePath+mediaFname;
54 String mpegURLFile = baseName+".m3u";
55 String playlistFile = baseName+".pls";
56 Integer size = new Integer(uploadedData.length);
57 if(FileUtil.write(dir+"/"+datePath+"/"+mediaFname, uploadedData)) {
58 //if(FileUtil.write(dir+"/"+mediaFname, uploadedData)) {
59 //were done with the data, dereference.
63 //write the "meta" files
64 //first the .m3u since it only contains one line
65 FileUtil.write(dir+"/"+datePath+"/"+mpegURLFile,mp3Pointer.getBytes());
67 FileUtil.write(dir+"/"+datePath+"/"+playlistFile,mp3Pointer.getBytes());
68 ent.setValueForProperty("is_produced", "1");
69 ent.setValueForProperty("icon_is_produced", "1");
70 ent.setValueForProperty("publish_path",datePath+"/"+mediaFname);
71 //ent.setValueForProperty("publish_path", mediaFname);
72 ent.setValueForProperty("publish_server", mediaHost);
73 ent.setValueForProperty("size", size.toString());
75 } catch (StorageObjectException e) {
76 theLog.printError("StorageObjectException: "+e.toString());
80 theLog.printError("could not write FILE!");
87 public String getURL(Entity ent, Entity mediaTypeEnt)
89 String stringSize = ent.getValue("size");
90 if (stringSize == null)
92 int size = Integer.parseInt(stringSize, 10)/1024;
93 String rawTitle = ent.getValue("title")+
94 " - "+mediaTypeEnt.getValue("name")+" "+
95 size+" KB "+"download";
96 String m3uTitle = ent.getValue("title")+
97 " - "+mediaTypeEnt.getValue("name")+" "+
99 String plsTitle = ent.getValue("title")+
100 " - "+mediaTypeEnt.getValue("name")+" "+
103 String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".mp3$","");
105 String m3uURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".m3u", m3uTitle, imageRoot, getBigIcon());
106 String plsURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".pls", plsTitle, imageRoot, getBigIcon());
107 String rawURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ent.getValue("publish_path"), rawTitle, imageRoot, getBigIcon());
109 return m3uURL+"\n<p>"+plsURL+"\n<p>"+rawURL;