parent
cc17eb0bd9
commit
83bb9e5805
@ -0,0 +1,104 @@ |
||||
/* |
||||
* To change this license header, choose License Headers in Project Properties. |
||||
* To change this template file, choose Tools | Templates |
||||
* and open the template in the editor. |
||||
*/ |
||||
package moe.nekojimi.chords; |
||||
|
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* |
||||
* @author jimj316 |
||||
*/ |
||||
class Format |
||||
{ |
||||
|
||||
private static final Pattern SIZE_PATTERN = Pattern.compile("\\b([0-9]+\\.?[0-9]*)([kkMmGg])i?[bB]\\b"); |
||||
private static final Pattern BITRATE_PATTERN = Pattern.compile("\\b([0-9]+)k(b(ps?))?\\b"); |
||||
|
||||
private final String code; |
||||
private final String extension; |
||||
private final String resolution; |
||||
private final String note; |
||||
|
||||
public Format(String code, String extension, String resolution, String note) |
||||
{ |
||||
this.code = code; |
||||
this.extension = extension; |
||||
this.resolution = resolution; |
||||
this.note = note; |
||||
} |
||||
|
||||
public boolean isAudioOnly() |
||||
{ |
||||
return resolution.trim().toLowerCase().contains("audio only"); |
||||
} |
||||
|
||||
public long getSize() |
||||
{ |
||||
// try to find eg. "1.32MiB" inside note
|
||||
Matcher matcher = SIZE_PATTERN.matcher(note); |
||||
if (matcher.find()) |
||||
{ |
||||
double value = Double.parseDouble(matcher.group(1)); |
||||
String mag = matcher.group(2).toUpperCase(); |
||||
long mult = 1; |
||||
switch (mag) |
||||
{ |
||||
case "K": |
||||
mult = 1024; |
||||
break; |
||||
case "M": |
||||
mult = 1024 * 1024; |
||||
break; |
||||
case "G": |
||||
mult = 1024 * 1024 * 1024; |
||||
break; |
||||
} |
||||
value *= mult; |
||||
return (long) value; |
||||
|
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
public int getBitrate() |
||||
{ |
||||
// try to find eg. "51k" inside note
|
||||
Matcher matcher = BITRATE_PATTERN.matcher(note); |
||||
if (matcher.find()) |
||||
{ |
||||
return Integer.parseInt(matcher.group(1)) * 1000; |
||||
} |
||||
return -1; |
||||
} |
||||
|
||||
public String getCode() |
||||
{ |
||||
return code; |
||||
} |
||||
|
||||
public String getExtension() |
||||
{ |
||||
return extension; |
||||
} |
||||
|
||||
public String getResolution() |
||||
{ |
||||
return resolution; |
||||
} |
||||
|
||||
public String getNote() |
||||
{ |
||||
return note; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() |
||||
{ |
||||
return "Format{" + "code=" + code + ", extension=" + extension + ", resolution=" + resolution + ", note=" + note + '}'; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue