Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from shinovon/r3-dev
Browse files Browse the repository at this point in the history
Release 2 patch 4
  • Loading branch information
shinovon authored Dec 14, 2021
2 parents 889ebe8 + b7fd570 commit a68bcf5
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Application Descriptor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIDlet-Version: 1.3.6
MIDlet-Version: 1.3.8
MicroEdition-Configuration: CLDC-1.0
Nokia-MIDlet-UID-1: 0xAFCE0816
MIDlet-Name: JTube
Expand Down
51 changes: 42 additions & 9 deletions src/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public class App implements CommandListener, Constants {

public static String ver = "r2patch2";
public static final String ver = "release2patch4";

// Settings
public static String videoRes;
Expand Down Expand Up @@ -119,6 +119,8 @@ public void scheduleRunnable(Runnable r) {
public static int width;
public static int height;

private static Displayable lastd;

public void startApp() {
region = System.getProperty("user.country");
if(region == null) {
Expand All @@ -128,8 +130,6 @@ public void startApp() {
} else if(region.length() == 5) {
region = region.substring(3, 5);
} else if(region.length() > 2) {
region = region.substring(0, 2);
} else {
region = "US";
}
} else if(region.length() > 2) {
Expand All @@ -142,6 +142,9 @@ public void startApp() {
tasksThread.setPriority(4);
tasksThread.start();
Settings.loadConfig();
if(region.toLowerCase().equals("en")) {
region = "US";
}
if(!Settings.isLowEndDevice() && asyncLoading) {
v1 = new Vector();
v2 = new Vector();
Expand Down Expand Up @@ -170,7 +173,7 @@ private void loadForm() {
}
gc();
} catch (InvidiousException e) {
error(this, Errors.App_loadForm, e + "\n JSON: \n" + e.getJSON());
error(this, Errors.App_loadForm, e);
} catch (OutOfMemoryError e) {
gc();
error(this, Errors.App_loadForm, "Out of memory!");
Expand Down Expand Up @@ -213,22 +216,28 @@ public static AbstractJSON invApi(String s) throws InvidiousException, IOExcepti
}

public static AbstractJSON invApi(String s, String fields) throws InvidiousException, IOException {
String url = s;
if(!s.endsWith("?")) s = s.concat("&");
s = s.concat("region=" + region);
if(fields != null) {
s = s.concat("&fields=" + fields + ",error,errorBacktrace,code");
}
s = Util.getUtf(inv + "api/" + s);
String dbg = "Region=" + region + " Fields=" + fields;
try {
s = Util.getUtf(inv + "api/" + s);
} catch (IOException e) {
throw new NetRequestException(e, s);
}
AbstractJSON res;
if(s.charAt(0) == '{') {
res = JSON.getObject(s);
if(((JSONObject) res).has("code")) {
System.out.println(res.toString());
throw new InvidiousException((JSONObject) res, ((JSONObject) res).getString("code") + ": " + ((JSONObject) res).getNullableString("message"));
throw new InvidiousException((JSONObject) res, ((JSONObject) res).getString("code") + ": " + ((JSONObject) res).getNullableString("message"), url, dbg);
}
if(((JSONObject) res).has("error")) {
System.out.println(res.toString());
throw new InvidiousException((JSONObject) res);
throw new InvidiousException((JSONObject) res, null, url, dbg);
}
} else {
res = JSON.getArray(s);
Expand Down Expand Up @@ -332,7 +341,7 @@ private void search(String q) {
}
stopDoingAsyncTasks();
try {
JSONArray j = (JSONArray) invApi("v1/search?q=" + Util.url(q), SEARCH_FIELDS + ",type" + (videoPreviews ? ",videoThumbnails" : "") + (searchChannels || searchPlaylists ? ",authorThumbnails,playlistId,videoCount&type=all" : ""));
JSONArray j = (JSONArray) invApi("v1/search?q=" + Util.url(q) + "&type=all", SEARCH_FIELDS + ",type" + (videoPreviews ? ",videoThumbnails" : "") + (searchChannels || searchPlaylists ? ",authorThumbnails,playlistId,videoCount" : ""));
int l = j.size();
for(int i = 0; i < l; i++) {
Item item = parseAndMakeItem(j.getObject(i), true, i);
Expand Down Expand Up @@ -660,6 +669,7 @@ public void commandAction(Command c, Displayable d) {
}
display(settingsForm);
settingsForm.show();
return;
}
if(c == searchCmd && d instanceof Form) {
stopDoingAsyncTasks();
Expand All @@ -672,6 +682,7 @@ public void commandAction(Command c, Displayable d) {
t.addCommand(searchOkCmd);
t.addCommand(cancelCmd);
display(t);
return;
}
if(c == idCmd && d instanceof Form) {
stopDoingAsyncTasks();
Expand All @@ -681,6 +692,11 @@ public void commandAction(Command c, Displayable d) {
t.addCommand(goCmd);
t.addCommand(cancelCmd);
display(t);
return;
}
if(c == qrCmd) {
msg("don't touch it.");
return;
}
/*if(c == browserCmd) {
try {
Expand All @@ -692,12 +708,14 @@ public void commandAction(Command c, Displayable d) {
}*/
if(c == cancelCmd && d instanceof TextBox) {
display(mainForm);
return;
}
if(c == backCmd && d == searchForm) {
if(mainForm == null) return;
stopDoingAsyncTasks();
display(mainForm);
disposeSearchForm();
return;
}
if(c == switchToPopularCmd) {
startScreen = 1;
Expand All @@ -714,6 +732,7 @@ public void commandAction(Command c, Displayable d) {
}
loadPopular();
Settings.saveConfig();
return;
}
if(c == switchToTrendsCmd) {
startScreen = 0;
Expand Down Expand Up @@ -756,7 +775,12 @@ public static void display(Displayable d) {
b = true;
}
}
Display.getDisplay(midlet).setCurrent(d);
if(!(d instanceof Alert)) {
lastd = d;
Display.getDisplay(midlet).setCurrent(d);
} else {
Display.getDisplay(midlet).setCurrent((Alert) d, lastd);
}
if(b) inst.loadForm();
}

Expand Down Expand Up @@ -875,6 +899,15 @@ public static void warn(Object o, String str) {
}

public static void error(Object o, int i, Throwable e) {
if(e instanceof InvidiousException) {
error(o, i, e.toString(), ((InvidiousException)e).toErrMsg());
return;
}
if(e instanceof NetRequestException) {
NetRequestException e2 = (NetRequestException) e;
error(o, i, e2.getCause().toString(), "URL: " + e2.getUrl());
return;
}
error(o, i, e.toString(), null);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public interface Constants extends LocaleConstants {

public static Command cVideosCmd = new Command(Locale.s(CMD_Videos), Command.ITEM, 3);

public static Command qrCmd = new Command("qr scan", Command.SCREEN, 1);

// Limits
static final int TRENDS_LIMIT_S60 = 25;
static final int SEARCH_LIMIT_S60 = 35;
Expand Down
2 changes: 1 addition & 1 deletion src/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void run() {
while((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
downloaded += read;
if(i++ % 4 == 0) {
if(i++ % 10 == 0) {
if(cancel) return;
long t2 = System.currentTimeMillis();
String spd = "(" + ((int) (((((double) (downloaded - s) / (t2 - t)) * 1000) / 1024D) * 10) / 10D) + " KB/s)";
Expand Down
18 changes: 17 additions & 1 deletion src/InvidiousException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
public class InvidiousException extends RuntimeException {

private JSONObject json;
private String url;
private String msg2;

public InvidiousException(JSONObject j) {
super(j.getNullableString("error"));
json = j;
}

public InvidiousException(JSONObject j, String msg) {
public InvidiousException(JSONObject j, String msg, String url, String msg2) {
super(msg);
json = j;
this.url = url;
this.msg2 = msg2;
}

public JSONObject getJSON() {
Expand All @@ -21,5 +25,17 @@ public JSONObject getJSON() {
public String toString() {
return "API error: " + getMessage();
}

public String toErrMsg() {
boolean j = json != null;
boolean bt = j && json.has("backtrace");
boolean u = url != null;
boolean m2 = msg2 != null;
return (j ? "Raw json: " + json.build() : "") + (u ? " \nAPI request: " + url : "") + (m2 ? " \n" + msg2 : "") + (bt ? " \nBacktrace: " + json.getString("backtrace") : "");
}

public String getUrl() {
return url;
}

}
22 changes: 22 additions & 0 deletions src/NetRequestException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import java.io.IOException;

public class NetRequestException extends IOException {

private String url;
private IOException cause;

public NetRequestException(IOException e, String url) {
super(url);
cause = e;
this.url = url;
}

public String getUrl() {
return url;
}

public IOException getCause() {
return cause;
}

}
2 changes: 1 addition & 1 deletion src/models/ChannelModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void parse(JSONObject o, boolean extended) {

public ChannelModel extend() throws InvidiousException, IOException {
if(!extended) {
parse((JSONObject) App.invApi("v1/channels/" + authorId, CHANNEL_EXTENDED_FIELDS), true);
parse((JSONObject) App.invApi("v1/channels/" + authorId + "?", CHANNEL_EXTENDED_FIELDS + (App.videoPreviews ? "authorThumbnails" : "")), true);
}
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/models/VideoModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void parse(JSONObject j, boolean extended) {

public VideoModel extend() throws InvidiousException, IOException {
if(!extended) {
parse((JSONObject) App.invApi("v1/videos/" + videoId, (App.videoPreviews ? ",videoThumbnails,authorThumbnails" : "")), true);
parse((JSONObject) App.invApi("v1/videos/" + videoId + "?", VIDEO_EXTENDED_FIELDS + (App.videoPreviews ? ",videoThumbnails,authorThumbnails" : "")), true);
}
return this;
}
Expand Down
26 changes: 18 additions & 8 deletions src/ui/Settings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ui;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

Expand Down Expand Up @@ -137,7 +136,8 @@ public static void loadConfig() {
App.videoRes = "360p";
App.downloadDir = "C:/";
} else {
if(!PlatformUtils.isS40()) {
boolean s40 = PlatformUtils.isS40();
if(!s40) {
getRoots();
String root = "";
for(int i = 0; i < rootsVector.size(); i++) {
Expand Down Expand Up @@ -203,10 +203,10 @@ else if(downloadDir.startsWith("file:///"))
if(PlatformUtils.isAsha()) {
App.videoPreviews = true;
App.customItems = true;
} else if(PlatformUtils.isS40() || (PlatformUtils.isNotS60() && !PlatformUtils.isS603rd() && PlatformUtils.startMemory > 512 * 1024 && PlatformUtils.startMemory < 2024 * 1024)) {
} else if(s40 || (PlatformUtils.isNotS60() && !PlatformUtils.isS603rd() && PlatformUtils.startMemory > 512 * 1024 && PlatformUtils.startMemory < 2024 * 1024)) {
App.videoPreviews = true;
App.customItems = true;
App.rmsPreviews = true;
if(s40) App.rmsPreviews = true;
}
int min = Math.min(App.width, App.height);
// Symbian 9.4 can't handle H.264/AVC
Expand Down Expand Up @@ -328,7 +328,10 @@ public static void saveConfig() {

private void dirListOpen(String f, String title) {
dirList = new List(title, List.IMPLICIT);
dirList.setTitle(title);
dirList.addCommand(backCmd);
dirList.addCommand(List.SELECT_COMMAND);
dirList.setSelectCommand(List.SELECT_COMMAND);
dirList.setCommandListener(this);
dirList.addCommand(dirSelectCmd);
dirList.append("- " + Locale.s(CMD_Select), null);
Expand All @@ -342,7 +345,7 @@ private void dirListOpen(String f, String title) {
}
}
fc.close();
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
}
App.display(dirList);
Expand All @@ -358,6 +361,9 @@ public void commandAction(Command c, Displayable d) {
if(curDir.indexOf("/") == -1) {
dirList = new List("", List.IMPLICIT);
dirList.addCommand(backCmd);
dirList.setTitle("");
dirList.addCommand(List.SELECT_COMMAND);
dirList.setSelectCommand(List.SELECT_COMMAND);
dirList.setCommandListener(this);
for(int i = 0; i < rootsVector.size(); i++) {
String s = (String) rootsVector.elementAt(i);
Expand All @@ -372,10 +378,12 @@ public void commandAction(Command c, Displayable d) {
String sub = curDir.substring(0, curDir.lastIndexOf('/'));
String fn = "";
if(sub.indexOf('/') != -1) {
fn = sub.substring(sub.lastIndexOf('/'));
fn = sub.substring(sub.lastIndexOf('/') + 1);
} else {
fn = sub;
}
curDir = sub;
dirListOpen(sub, fn);
dirListOpen(sub + "/", fn);
}
}
if(c == dirOpenCmd || c == List.SELECT_COMMAND) {
Expand All @@ -392,7 +400,7 @@ public void commandAction(Command c, Displayable d) {
}
f += is;
curDir = f;
dirListOpen(f, is);
dirListOpen(f + "/", is);
return;
}
if(c == dirSelectCmd) {
Expand Down Expand Up @@ -421,6 +429,8 @@ public void commandAction(Command c, Item item) {
if(s.endsWith("/")) s = s.substring(0, s.length() - 1);
dirList.append(s, null);
}
dirList.addCommand(List.SELECT_COMMAND);
dirList.setSelectCommand(List.SELECT_COMMAND);
dirList.addCommand(backCmd);
dirList.setCommandListener(this);
App.display(dirList);
Expand Down

0 comments on commit a68bcf5

Please sign in to comment.