replace deprecated JAI method with new one.
[mir.git] / source / mircoders / media / MediaHandlerMp3.java
1 /*
2  * put your module comment here
3  */
4
5
6 package  mircoders.media;
7
8 import java.util.*;
9
10 import mir.media.*;
11 import mir.entity.*;
12 import mir.misc.*;
13 import mir.storage.*;
14
15
16 /**
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 
26  * add:
27  *
28  * audio/x-mpegurl                 m3u
29  * audio/x-scpl                    pls
30  *
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.
35  *
36  * If the web server is not apache, then your on your own.
37  * 
38  * @see mir.media.MirMedia
39  * @author mh <heckmann@hbe.ca>
40  * @version 01.12.2001
41  */
42
43 public class MediaHandlerMp3 extends MediaHandlerAudio implements MirMedia
44 {
45
46     public void produce (Entity ent, Entity mediaTypeEnt )
47       throws MirMediaException {
48       
49       // first check if the file exists
50       super.produce(ent, mediaTypeEnt);
51
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"; 
58
59       try {
60         //write the "meta" files
61         //first the .m3u since it only contains one line
62         FileUtil.write(getStoragePath()+"/"+datePath+"/"+mpegURLFile,
63                       mp3Pointer.getBytes());
64         //now the .pls file
65         FileUtil.write(getStoragePath()+"/"+datePath+"/"+playlistFile,
66                       mp3Pointer.getBytes());
67       } catch (Exception e) {
68           theLog.printError(e.toString()); 
69           throw new MirMediaException(e.toString());
70       }
71     }
72
73   public String getURL(Entity ent, Entity mediaTypeEnt)
74   {
75       String stringSize = ent.getValue("size");
76       if (stringSize == null)
77         return 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")+" "+
84         "streaming URL";
85       String plsTitle = ent.getValue("title")+
86         " - "+mediaTypeEnt.getValue("name")+" "+
87         "playlist URL";
88
89       String basePath=StringUtil.regexpReplace(ent.getValue("publish_path"), ".mp3$","");
90
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());
94     
95       return m3uURL+"\n<p>"+plsURL+"\n<p>"+rawURL;
96
97     }
98
99 }
100         
101         
102