fixed lyrics for genius
This commit is contained in:
@@ -6,6 +6,7 @@ import com.vk.dto.music.MusicTrack;
|
||||
import com.vtosters.lite.R;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import ru.vtosters.lite.di.singleton.VtOkHttpClient;
|
||||
@@ -39,9 +40,7 @@ public class Genius {
|
||||
return null;
|
||||
}
|
||||
|
||||
Log.d("Genius", "/search/multi?q=" + URLEncoder.encode(artist + " " + track) + "&from_background=0");
|
||||
|
||||
var request = new Request.a()
|
||||
Request request = new Request.a()
|
||||
.b(URL + "/search/multi?q=" + URLEncoder.encode(artist + " " + track) + "&from_background=0")
|
||||
.a("User-Agent", "Genius/5.14.0 (Android; Android 13; Google Pixel 4 XL)")
|
||||
.a("Authorization", KEY)
|
||||
@@ -52,26 +51,29 @@ public class Genius {
|
||||
.b()
|
||||
.a();
|
||||
try {
|
||||
var payload = client.a(request).execute().a().g();
|
||||
var sections = new JSONObject(payload).getJSONObject("response").getJSONArray("sections");
|
||||
|
||||
Log.d("Genius", payload);
|
||||
String payload = client.a(request).execute().a().g();
|
||||
JSONArray sections = new JSONObject(payload).getJSONObject("response").getJSONArray("sections");
|
||||
|
||||
for (int i = 0; i < sections.length(); i++) {
|
||||
var json = sections.optJSONObject(i);
|
||||
JSONObject json = sections.optJSONObject(i);
|
||||
|
||||
if (json.optString("type").equals("song")) {
|
||||
var path = json.getJSONArray("hits").getJSONObject(0).getJSONObject("result").getString("api_path");
|
||||
JSONArray hits = json.getJSONArray("hits");
|
||||
|
||||
Log.d("Genius", path);
|
||||
for (int j = 0; j < hits.length(); j++) {
|
||||
JSONObject json2 = hits.optJSONObject(j);
|
||||
JSONObject result = json2.getJSONObject("result");
|
||||
|
||||
return getText(path);
|
||||
if (json2.optString("index").equals("song") && result.optString("path").contains("lyrics")) {
|
||||
return getText(result.getString("api_path"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AndroidUtils.getString("error_no_text");
|
||||
} catch (JSONException | IOException e) {
|
||||
return AndroidUtils.getString("error_no_text") + "\n\n" + AndroidUtils.getString(R.string.error) + ": \n" + e.getLocalizedMessage();
|
||||
return AndroidUtils.getString("error_no_text") + "\n\n" + AndroidUtils.getString(R.string.error) + ": \n" + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ public class Genius {
|
||||
return null;
|
||||
}
|
||||
|
||||
var request = new Request.a()
|
||||
Request request = new Request.a()
|
||||
.b(URL + track + "?text_format=plain")
|
||||
.a("User-Agent", "Genius/5.14.0 (Android; Android 13; Google Pixel 4 XL)")
|
||||
.a("Authorization", KEY)
|
||||
@@ -92,16 +94,15 @@ public class Genius {
|
||||
.b()
|
||||
.a();
|
||||
try {
|
||||
var payload = new JSONObject(client.a(request).execute().a().g());
|
||||
Log.d("Genius", String.valueOf(payload));
|
||||
JSONObject payload = new JSONObject(client.a(request).execute().a().g());
|
||||
|
||||
if (!payload.has("response")) {
|
||||
return AndroidUtils.getString("error_no_text");
|
||||
}
|
||||
|
||||
return " " + payload.getJSONObject("response").getJSONObject("song").getJSONObject("lyrics").getString("plain");
|
||||
return payload.getJSONObject("response").getJSONObject("song").getJSONObject("lyrics").getString("plain");
|
||||
} catch (JSONException | IOException e) {
|
||||
return AndroidUtils.getString("error_no_text") + "\n\n" + AndroidUtils.getString(R.string.error) + ": \n" + e.getLocalizedMessage();
|
||||
return AndroidUtils.getString("error_no_text") + "\n\n" + AndroidUtils.getString(R.string.error) + ": \n" + e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user