Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions app/src/main/java/free/rm/skytube/app/SkyTubeApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,40 +369,44 @@ public Settings getAppSettings() {
return settings;
}

public static void notifyUserOnError(@NonNull Context ctx, @Nullable Throwable throwable) {
if (throwable == null) {
return;
}
public static void notifyUserOnError(@NonNull Context ctx, @Nullable Throwable throwable) {
if (throwable == null) {
return;
}
if (throwable instanceof ReCaptchaException) {
handleRecaptchaException(ctx, (ReCaptchaException) throwable);
return;
}
final String message;
if (throwable instanceof GoogleJsonResponseException) {
GoogleJsonResponseException exception = (GoogleJsonResponseException) throwable;
List<GoogleJsonError.ErrorInfo> errors = exception.getDetails().getErrors();
if (errors != null && !errors.isEmpty()) {
message = "Server error:" + errors.get(0).getMessage()+ ", reason: "+ errors.get(0).getReason();
} else {
message = exception.getDetails().getMessage();
}
} else {
message = throwable.getMessage();
}
if (message != null) {
Log.e(TAG, "Error: "+message);

String toastText = message;
if(message.contains("resolve host")) {
toastText = "No internet connection available";
}
if(message.contains("JavaScript player")) {
return; // Error from Player when watching downloaded videos offline
}
final String message = getMessage(throwable);
if (message != null) {
Log.e(TAG, "Error: " + message);

String toastText = message;
if (message.contains("resolve host")) {
toastText = "No internet connection available";
}
if (message.contains("JavaScript player")) {
return; // Error from Player when watching downloaded videos offline
}

Toast.makeText(ctx, toastText, Toast.LENGTH_LONG).show();
}
}

Toast.makeText(ctx, toastText, Toast.LENGTH_LONG).show();
}
}
@Nullable
private static String getMessage(@NonNull Throwable throwable) {
if (throwable instanceof GoogleJsonResponseException) {
GoogleJsonResponseException exception = (GoogleJsonResponseException) throwable;
List<GoogleJsonError.ErrorInfo> errors = exception.getDetails().getErrors();
if (errors != null && !errors.isEmpty()) {
return "Server error:" + errors.get(0).getMessage()+ ", reason: "+ errors.get(0).getReason();
} else {
return exception.getDetails().getMessage();
}
} else {
return throwable.getMessage();
}
}

private static void handleRecaptchaException(Context context, ReCaptchaException reCaptchaException) {
// remove "pbj=1" parameter from YouYube urls, as it makes the page JSON and not HTML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
public class NewPipeService {
// TODO: remove this singleton
private static NewPipeService instance;
private final static boolean VERBOSE_DISLIKE_COUNT_LOG = false;

private final StreamingService streamingService;
private final Settings settings;
Expand Down Expand Up @@ -464,7 +465,11 @@ public Long getDislikeCountFromApi(String videoId) {
Logger.i(this, "for "+ url +" -> "+jsonObject);
return jsonObject.getLong("dislikes");
} catch (IOException | JSONException | ReCaptchaException e) {
Logger.e(this, "getDislikeCount: error: " + e.getMessage() + " for url:" + url, e);
if (VERBOSE_DISLIKE_COUNT_LOG) {
Logger.e(this, "getDislikeCount: error: " + e.getMessage() + " for url:" + url, e);
} else {
Logger.i(this, "getDislikeCount: error: " + e.getMessage() + " for url:" + url);
}
}
} else {
Logger.i(this, "Like fetching disabled for " + videoId);
Expand Down