diff options
Diffstat (limited to 'src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java')
| -rw-r--r-- | src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java new file mode 100644 index 0000000..34fe49b --- /dev/null +++ b/src/YalpInputs/YalpPGSqlInput/YalpPGSQLIndexer/FileInfoManager.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2006 Manuel Traut and Volker Dahnke + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: Manuel Traut and Volker Dahnke + */ + +package YalpServer; + +import java.io.File; +import java.io.IOException; +import java.io.FileNotFoundException; + +import de.hampelratte.id3.*; + +import YalpInterfaces.*; + +/* + * Class FileInfoManager + * + * <em>Creates a Result out of FileInformations (ID3, etc)</em> + * + * @author Volker Dahnke / Manuel Traut + * + * @version 0.1 14-12-2005<br> + * + * @see ServerControl + */ + +public class FileInfoManager { + + private Media fileInfo; + private EncodingType eType; + +/* + * Constructor: tries to get all Informations about a file + * + * @param file + */ + + public FileInfoManager(File file) { + + this.eType = EncodingType.UNKNOWN; + this.fileInfo = new Media(); + this.fileInfo.path = file.getParent()+file.separator; + this.fileInfo.fileName = file.getName(); + + /* check extensions is mp3 */ + if( this.fileInfo.fileName.substring( this.fileInfo.fileName.length() - 3, + this.fileInfo.fileName.length()).equalsIgnoreCase( "mp3" ) ) + { + this.eType = EncodingType.MP3; + } + + switch(this.eType.value()) { + case EncodingType._MP3: + try + { + /* opening mp3 file for reading and writing */ + MP3File mp3 = new de.hampelratte.id3.MP3File(file.toString(), "r"); + this.fileInfo.type = MediaType.SOUND; + + if(mp3.hasID3v1Tag){ + ID3v1Tag tag = mp3.readID3v1Tag(); + /* t.b.d. create StringProperties + this.fileInfo.album = tag.getAlbum(); + this.fileInfo.author = tag.getArtist(); + this.fileInfo.category = tag.getGenre(); + this.fileInfo.name = tag.getTrack() +" - "+tag.getTitle(); + this.fileInfo.year = tag.getYear(); + */ + } + + if(mp3.hasID3v2Tag){ + + // reading the ID3v2Tag + ID3v2Tag tag = mp3.readID3v2Tag(); + /* t.b.d. create StringProperties + this.fileInfo.album = tag.getAlbum(); + this.fileInfo.author = tag.getArtist(); + this.fileInfo.category = tag.getGenre(); + this.fileInfo.year = tag.getYear(); + */ + if( !(tag.getTrack().equals(""))){ + this.fileInfo.name = tag.getTrack() +" - "+tag.getTitle(); + } else { + this.fileInfo.name = tag.getTitle(); + } + } + + if (this.fileInfo.name.equals("")) { + + this.fileInfo.name = + file.getName().substring( 0, file.getName().length() - 4 ); + } + + mp3.close(); + } catch (Exception e) { + + this.fileInfo.name = + file.getName().substring(0,file.getName().length() - 4); + } + break; + + default: + this.fileInfo.name = + file.getName().substring(0,file.getName().length()-4); + + this.fileInfo.type = MediaType.VIDEO; + break; + } + } + +/* + * returns the information to an media, found + * @return MediaChange + * Informations about the media + */ + + public Media getInfo(){ + return this.fileInfo; + } +} |
