Merge pull request #518 from tva2000hn/master
Synced .lrc lyrics without putting in the /RetroMusic folder
This commit is contained in:
commit
99ed3d3bbb
4 changed files with 79 additions and 25 deletions
|
@ -7,6 +7,7 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
|
@ -150,8 +151,13 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
private fun showSyncedLyrics() {
|
||||
var content = ""
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
||||
} catch (e: Exception) {
|
||||
try{
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
} catch ( e2 : Exception){
|
||||
|
||||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
|
@ -161,7 +167,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
input(hint = getString(R.string.paste_lyrics_here),
|
||||
prefill = content,
|
||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) { _, input ->
|
||||
LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString())
|
||||
LyricUtil.writeLrcToLoc(song.data, song.artistName, input.toString())
|
||||
}
|
||||
positiveButton(android.R.string.ok) {
|
||||
updateSong()
|
||||
|
@ -364,8 +370,12 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage
|
|||
|
||||
private fun loadLRCLyrics() {
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
||||
} else {
|
||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
|
|||
|
||||
override fun doInBackground(vararg params: Song): Lyrics? {
|
||||
try {
|
||||
var data: String? = LyricUtil.getStringFromFile(params[0].title, params[0].artistName)
|
||||
var data: String? = LyricUtil.getStringFromFile(params[0].data, params[0].artistName)
|
||||
return if (TextUtils.isEmpty(data)) {
|
||||
data = MusicUtil.getLyrics(params[0])
|
||||
return if (TextUtils.isEmpty(data)) {
|
||||
|
|
|
@ -42,8 +42,8 @@ public class LrcHelper {
|
|||
|
||||
private static final String CHARSET = "utf-8";
|
||||
//[03:56.00][03:18.00][02:06.00][01:07.00]原谅我这一生不羁放纵爱自由
|
||||
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2}])+)(.*)";
|
||||
private static final String TIME_REGEX = "\\[(\\d{2}):(\\d{2})\\.(\\d{2})]";
|
||||
private static final String LINE_REGEX = "((\\[\\d{2}:\\d{2}\\.\\d{2,3}])+)(.*)";
|
||||
private static final String TIME_REGEX = "\\[(\\d{2}):(\\d{2})\\.(\\d{2,3})]";
|
||||
|
||||
public static List<Lrc> parseLrcFromAssets(Context context, String fileName) {
|
||||
try {
|
||||
|
@ -127,8 +127,14 @@ public class LrcHelper {
|
|||
String mil = timeMatcher.group(3);
|
||||
Lrc lrc = new Lrc();
|
||||
if (content != null && content.length() != 0) {
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil) * 10);
|
||||
if(Integer.parseInt(mil)< 100){
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil) * 10);}
|
||||
else{
|
||||
lrc.setTime(Long.parseLong(min) * 60 * 1000 + Long.parseLong(sec) * 1000
|
||||
+ Long.parseLong(mil)
|
||||
);
|
||||
}
|
||||
lrc.setText(content);
|
||||
lrcs.add(lrc);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -40,11 +41,11 @@ public class LyricUtil {
|
|||
public static File writeLrcToLoc(@NonNull String title, @NonNull String artist, @NonNull String lrcContext) {
|
||||
FileWriter writer = null;
|
||||
try {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
File file = new File(getLrcPath2(title, artist));
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
writer = new FileWriter(getLrcPath(title, artist));
|
||||
writer = new FileWriter(getLrcPath2(title, artist));
|
||||
writer.write(lrcContext);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
|
@ -70,17 +71,46 @@ public class LyricUtil {
|
|||
return file.exists();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
} else {
|
||||
return new File("lyric file not exist");
|
||||
}
|
||||
public static boolean isLrcFile2Exist(@NonNull String title, @NonNull String artist) {
|
||||
File file = new File(getLrcPath2(title, artist));
|
||||
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
private static String getLrcPath(String title, String artist) {
|
||||
@NonNull
|
||||
public static File getLocalLyricFile(@NonNull String title, @NonNull String artist) {
|
||||
try{
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
File file2 = new File(getLrcPath2(title, artist));
|
||||
if (file.exists()) {
|
||||
|
||||
return file;
|
||||
} else if (file2.exists()) {
|
||||
|
||||
return file2;
|
||||
}
|
||||
else {
|
||||
|
||||
return new File("lyric file not exist");
|
||||
}} catch (Exception dfs){
|
||||
dfs.printStackTrace();
|
||||
return new File("lyric file not exist");
|
||||
|
||||
}
|
||||
}
|
||||
public static String getLrcPath2(String title, String artist) {
|
||||
String x2;
|
||||
if(title.endsWith(".flac")||title.endsWith(".mogg")||title.endsWith(".alac")||title.endsWith(".aiff")||title.endsWith(".webv")){
|
||||
x2= title.substring(0, title.length() -5 ) + ".lrc";
|
||||
}
|
||||
else{
|
||||
x2= title.substring(0, title.length() -4 ) + ".lrc";}
|
||||
|
||||
|
||||
return x2;
|
||||
}
|
||||
|
||||
public static String getLrcPath(String title, String artist) {
|
||||
return lrcRootPath + title + " - " + artist + ".lrc";
|
||||
}
|
||||
|
||||
|
@ -103,10 +133,18 @@ public class LyricUtil {
|
|||
|
||||
@NonNull
|
||||
public static String getStringFromFile(@NonNull String title, @NonNull String artist) throws Exception {
|
||||
File file = new File(getLrcPath(title, artist));
|
||||
File file;
|
||||
File file2 = new File(getLrcPath(title, artist));
|
||||
File file3 = new File(getLrcPath2(title, artist));
|
||||
if(file2.exists()){
|
||||
file = file2;
|
||||
} else {
|
||||
file = file3;
|
||||
}
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
String ret = convertStreamToString(fin);
|
||||
fin.close();
|
||||
// Log.d("damn2",ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue