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