001 package net.sourceforge.mp3dings.export;
002
003 /* Mp3dings - manage mp3 meta-information
004 * Copyright (C) 2003 Moritz Ringler
005 * $Id: M3uExporter.java 115 2007-11-05 23:46:25Z ringler $
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020 */
021
022 import java.util.Map;
023 import net.sourceforge.mp3dings.Field;
024 import java.io.Serializable;
025
026 /** Exports data as an M3u playlist.
027 * @author Moritz Ringler
028 * @version $Revision: 115 $ ($Date: 2007-11-06 00:46:25 +0100 (Di, 06 Nov 2007) $)
029 */
030 public class M3uExporter extends AbstractExporter implements Serializable{
031 static final long serialVersionUID = 198561272554442665L;
032
033 /** Creates a new M3UExporter with the encoding set to iso-latin (ISO-8859-1).
034 */
035 public M3uExporter(){
036 super();
037 super.setKeys(null,
038 new Field[]{Field.FULLPATH, Field.ARTIST, Field.TITLE, Field.LENGTH, Field.FILENAME},
039 null);
040 setEncoding("ISO-8859-1");
041 }
042
043 /**Returns two lines making up one playlist entry.
044 * <pre>
045 * #EXTINF: [length],[artist] - [title]<br>
046 * [filepath]
047 * </pre>
048 * @param fileIndex ignored
049 * @param blockdata a map containing the record data
050 */
051 public String getBlock(int fileIndex, Map blockdata){
052 StringBuffer sb = new StringBuffer("#EXTINF:");
053 Object len = blockdata.get(Field.LENGTH);
054 if(len == null){
055 sb.append(0);
056 } else {
057 sb.append(len);
058 }
059 sb.append(",");
060 sb.append(blockdata.get(Field.ARTIST)).append(" - ");
061 sb.append(blockdata.get(Field.TITLE)).append("\n");
062 sb.append(blockdata.get(Field.FULLPATH)).append("\n");
063 return sb.toString();
064 }
065
066 /** Returns the single line header.
067 * <pre>
068 * #ExtM3U
069 * </pre>
070 */
071 public String getHeader(){
072 return "#EXTM3U\n";
073 }
074
075 /** Returns an empty string.*/
076 public String getFooter(int numEntries){
077 return "";
078 }
079
080 /** Returns a string description of this exporter's target file type.
081 * @return the name of the target file type. Currently this is
082 * "M3u playlist (*.m3u)", but this may change in future
083 * versions.
084 */
085 public String getName(){
086 return "M3u playlist (*.m3u)";
087 }
088
089 /** Returns the file extension for this exporter's target file type.
090 * @return a file extension including the leading dot. Currently this is
091 * ".m3u", but this may change in future versions.
092 */
093 public String getExtension(){
094 return ".m3u";
095 }
096
097 /** Overriden to do nothing. This exporter uses no fields for the header and
098 * footer and
099 * <code>ARTIST</code>, <code>TITLE</code>, <code>FULLPATH</code>, and
100 * <code>LENGTH</code> as blockKeys.
101 */
102 public void setKeys(Object[] headerKeys, Object[] blockKeys, Object[] footerKeys){
103 }
104 }