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 void produce (Entity ent, Entity mediaTypeEnt )
47 throws MirMediaException {
49 // first check if the file exists
50 super.produce(ent, mediaTypeEnt);
52 String baseName = ent.getId();
53 String date = ent.getValue("date");
54 String datePath = StringUtil.webdbDate2path(date);
55 String mp3Pointer = getPublishHost()+ent.getValue("publish_path");
56 String mpegURLFile = baseName+".m3u";
57 String playlistFile = baseName+".pls";
60 //write the "meta" files
61 //first the .m3u since it only contains one line
62 FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
63 mp3Pointer.getBytes());
65 FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
66 mp3Pointer.getBytes());
67 } catch (Exception e) {
68 theLog.printError(e.toString());
69 throw new MirMediaException(e.toString());
73 public String getURL(Entity ent, Entity mediaTypeEnt)
75 String stringSize = ent.getValue("size");
76 if (stringSize == null)
78 int size = Integer.parseInt(stringSize, 10)/1024;
79 String rawTitle = ent.getValue("title")+
80 " - "+mediaTypeEnt.getValue("name")+" "+
81 size+" KB "+"download";
82 String m3uTitle = ent.getValue("title")+
83 " - "+mediaTypeEnt.getValue("name")+" "+
85 String plsTitle = ent.getValue("title")+
86 " - "+mediaTypeEnt.getValue("name")+" "+
89 String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".mp3$","");
91 String m3uURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".m3u", m3uTitle, imageRoot, getBigIcon());
92 String plsURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+basePath+".pls", plsTitle, imageRoot, getBigIcon());
93 String rawURL = StringUtil.createURLLinks(ent.getValue("publish_server")+"/"+ent.getValue("publish_path"), rawTitle, imageRoot, getBigIcon());
95 return m3uURL+"\n<p>"+plsURL+"\n<p>"+rawURL;