blob: 47dd62a27ea5d28c2eae68fdb41c8f46e9b5b152 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
* 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();
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
{
MP3File mp3 = new de.hampelratte.id3.MP3File(file.toString(), "r");
this.fileInfo.type = MediaType.SOUND;
if(mp3.hasID3v1Tag){
ID3v1Tag tag = mp3.readID3v1Tag();
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();
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;
}
}
*/
|