Add Spotless
This commit is contained in:
parent
2af13a4e6c
commit
defcd86152
286 changed files with 15604 additions and 13757 deletions
|
@ -18,54 +18,55 @@ import android.util.SparseArray;
|
|||
|
||||
public abstract class AbsSynchronizedLyrics extends Lyrics {
|
||||
|
||||
private static final int TIME_OFFSET_MS = 500; // time adjustment to display line before it actually starts
|
||||
private static final int TIME_OFFSET_MS =
|
||||
500; // time adjustment to display line before it actually starts
|
||||
|
||||
protected final SparseArray<String> lines = new SparseArray<>();
|
||||
protected final SparseArray<String> lines = new SparseArray<>();
|
||||
|
||||
protected int offset = 0;
|
||||
protected int offset = 0;
|
||||
|
||||
public String getLine(int time) {
|
||||
time += offset + AbsSynchronizedLyrics.TIME_OFFSET_MS;
|
||||
public String getLine(int time) {
|
||||
time += offset + AbsSynchronizedLyrics.TIME_OFFSET_MS;
|
||||
|
||||
int lastLineTime = lines.keyAt(0);
|
||||
int lastLineTime = lines.keyAt(0);
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
int lineTime = lines.keyAt(i);
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
int lineTime = lines.keyAt(i);
|
||||
|
||||
if (time >= lineTime) {
|
||||
lastLineTime = lineTime;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lines.get(lastLineTime);
|
||||
if (time >= lineTime) {
|
||||
lastLineTime = lineTime;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
parse(false);
|
||||
return lines.get(lastLineTime);
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@Override
|
||||
public String getText() {
|
||||
parse(false);
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.valueAt(i);
|
||||
sb.append(line).append("\r\n");
|
||||
}
|
||||
if (valid) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
return sb.toString().trim().replaceAll("(\r?\n){3,}", "\r\n\r\n");
|
||||
}
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.valueAt(i);
|
||||
sb.append(line).append("\r\n");
|
||||
}
|
||||
|
||||
return super.getText();
|
||||
return sb.toString().trim().replaceAll("(\r?\n){3,}", "\r\n\r\n");
|
||||
}
|
||||
|
||||
public boolean isSynchronized() {
|
||||
return true;
|
||||
}
|
||||
return super.getText();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
parse(true);
|
||||
return valid;
|
||||
}
|
||||
public boolean isSynchronized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
parse(true);
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,74 +14,72 @@
|
|||
|
||||
package code.name.monkey.retromusic.model.lyrics;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Lyrics {
|
||||
|
||||
private static final ArrayList<Class<? extends Lyrics>> FORMATS = new ArrayList<>();
|
||||
private static final ArrayList<Class<? extends Lyrics>> FORMATS = new ArrayList<>();
|
||||
|
||||
static {
|
||||
Lyrics.FORMATS.add(SynchronizedLyricsLRC.class);
|
||||
}
|
||||
static {
|
||||
Lyrics.FORMATS.add(SynchronizedLyricsLRC.class);
|
||||
}
|
||||
|
||||
public String data;
|
||||
public Song song;
|
||||
protected boolean parsed = false;
|
||||
protected boolean valid = false;
|
||||
public String data;
|
||||
public Song song;
|
||||
protected boolean parsed = false;
|
||||
protected boolean valid = false;
|
||||
|
||||
public static boolean isSynchronized(String data) {
|
||||
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
||||
try {
|
||||
Lyrics lyrics = format.newInstance().setData(null, data);
|
||||
if (lyrics.isValid()) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static boolean isSynchronized(String data) {
|
||||
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
||||
try {
|
||||
Lyrics lyrics = format.newInstance().setData(null, data);
|
||||
if (lyrics.isValid()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Lyrics parse(Song song, String data) {
|
||||
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
||||
try {
|
||||
Lyrics lyrics = format.newInstance().setData(song, data);
|
||||
if (lyrics.isValid()) {
|
||||
return lyrics.parse(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static Lyrics parse(Song song, String data) {
|
||||
for (Class<? extends Lyrics> format : Lyrics.FORMATS) {
|
||||
try {
|
||||
Lyrics lyrics = format.newInstance().setData(song, data);
|
||||
if (lyrics.isValid()) {
|
||||
return lyrics.parse(false);
|
||||
}
|
||||
return new Lyrics().setData(song, data).parse(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new Lyrics().setData(song, data).parse(false);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.data.trim().replaceAll("(\r?\n){3,}", "\r\n\r\n");
|
||||
}
|
||||
public String getText() {
|
||||
return this.data.trim().replaceAll("(\r?\n){3,}", "\r\n\r\n");
|
||||
}
|
||||
|
||||
public boolean isSynchronized() {
|
||||
return false;
|
||||
}
|
||||
public boolean isSynchronized() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
this.parse(true);
|
||||
return this.valid;
|
||||
}
|
||||
public boolean isValid() {
|
||||
this.parse(true);
|
||||
return this.valid;
|
||||
}
|
||||
|
||||
public Lyrics parse(boolean check) {
|
||||
this.valid = true;
|
||||
this.parsed = true;
|
||||
return this;
|
||||
}
|
||||
public Lyrics parse(boolean check) {
|
||||
this.valid = true;
|
||||
this.parsed = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Lyrics setData(Song song, String data) {
|
||||
this.song = song;
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
public Lyrics setData(Song song, String data) {
|
||||
this.song = song;
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,72 +19,73 @@ import java.util.regex.Pattern;
|
|||
|
||||
class SynchronizedLyricsLRC extends AbsSynchronizedLyrics {
|
||||
|
||||
private static final Pattern LRC_LINE_PATTERN = Pattern.compile("((?:\\[.*?\\])+)(.*)");
|
||||
private static final Pattern LRC_LINE_PATTERN = Pattern.compile("((?:\\[.*?\\])+)(.*)");
|
||||
|
||||
private static final Pattern LRC_TIME_PATTERN = Pattern.compile("\\[(\\d+):(\\d{2}(?:\\.\\d+)?)\\]");
|
||||
private static final Pattern LRC_TIME_PATTERN =
|
||||
Pattern.compile("\\[(\\d+):(\\d{2}(?:\\.\\d+)?)\\]");
|
||||
|
||||
private static final Pattern LRC_ATTRIBUTE_PATTERN = Pattern.compile("\\[(\\D+):(.+)\\]");
|
||||
private static final Pattern LRC_ATTRIBUTE_PATTERN = Pattern.compile("\\[(\\D+):(.+)\\]");
|
||||
|
||||
private static final float LRC_SECONDS_TO_MS_MULTIPLIER = 1000f;
|
||||
private static final float LRC_SECONDS_TO_MS_MULTIPLIER = 1000f;
|
||||
|
||||
private static final int LRC_MINUTES_TO_MS_MULTIPLIER = 60000;
|
||||
private static final int LRC_MINUTES_TO_MS_MULTIPLIER = 60000;
|
||||
|
||||
@Override
|
||||
public SynchronizedLyricsLRC parse(boolean check) {
|
||||
if (this.parsed || this.data == null || this.data.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String[] lines = this.data.split("\r?\n");
|
||||
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher attrMatcher = SynchronizedLyricsLRC.LRC_ATTRIBUTE_PATTERN.matcher(line);
|
||||
if (attrMatcher.find()) {
|
||||
try {
|
||||
String attr = attrMatcher.group(1).toLowerCase().trim();
|
||||
String value = attrMatcher.group(2).toLowerCase().trim();
|
||||
if ("offset".equals(attr)) {
|
||||
this.offset = Integer.parseInt(value);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Matcher matcher = SynchronizedLyricsLRC.LRC_LINE_PATTERN.matcher(line);
|
||||
if (matcher.find()) {
|
||||
String time = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
|
||||
Matcher timeMatcher = SynchronizedLyricsLRC.LRC_TIME_PATTERN.matcher(time);
|
||||
while (timeMatcher.find()) {
|
||||
int m = 0;
|
||||
float s = 0f;
|
||||
try {
|
||||
m = Integer.parseInt(timeMatcher.group(1));
|
||||
s = Float.parseFloat(timeMatcher.group(2));
|
||||
} catch (NumberFormatException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
int ms = (int) (s * LRC_SECONDS_TO_MS_MULTIPLIER) + m * LRC_MINUTES_TO_MS_MULTIPLIER;
|
||||
|
||||
this.valid = true;
|
||||
if (check) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.lines.append(ms, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
|
||||
return this;
|
||||
@Override
|
||||
public SynchronizedLyricsLRC parse(boolean check) {
|
||||
if (this.parsed || this.data == null || this.data.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String[] lines = this.data.split("\r?\n");
|
||||
|
||||
for (String line : lines) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher attrMatcher = SynchronizedLyricsLRC.LRC_ATTRIBUTE_PATTERN.matcher(line);
|
||||
if (attrMatcher.find()) {
|
||||
try {
|
||||
String attr = attrMatcher.group(1).toLowerCase().trim();
|
||||
String value = attrMatcher.group(2).toLowerCase().trim();
|
||||
if ("offset".equals(attr)) {
|
||||
this.offset = Integer.parseInt(value);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
Matcher matcher = SynchronizedLyricsLRC.LRC_LINE_PATTERN.matcher(line);
|
||||
if (matcher.find()) {
|
||||
String time = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
|
||||
Matcher timeMatcher = SynchronizedLyricsLRC.LRC_TIME_PATTERN.matcher(time);
|
||||
while (timeMatcher.find()) {
|
||||
int m = 0;
|
||||
float s = 0f;
|
||||
try {
|
||||
m = Integer.parseInt(timeMatcher.group(1));
|
||||
s = Float.parseFloat(timeMatcher.group(2));
|
||||
} catch (NumberFormatException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
int ms = (int) (s * LRC_SECONDS_TO_MS_MULTIPLIER) + m * LRC_MINUTES_TO_MS_MULTIPLIER;
|
||||
|
||||
this.valid = true;
|
||||
if (check) {
|
||||
return this;
|
||||
}
|
||||
|
||||
this.lines.append(ms, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue