Skip to content

Commit

Permalink
feat: make autoskip more sensitive to starting another show
Browse files Browse the repository at this point in the history
autoskip only checks the playing show every 6 seconds so the show could change and autoskip could get the new time before noticing the show has changed.  now when the show changes it will stop that check of the time and it will check the show right before a skip.
  • Loading branch information
lart2150 committed Dec 10, 2022
1 parent 34c89f8 commit 873135c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 97 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<project name="kmttg" basedir="." default="all">
<property name="rversion" value="v2.6-l-rc1"/>
<property name="rversion" value="v2.6-l"/>
<tstamp/>
<property name="bversion" value="${DSTAMP}-${TSTAMP}"/>
<property name="lib" value="lib"/>
Expand Down
2 changes: 1 addition & 1 deletion src/com/tivo/kmttg/main/config.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.tivo.kmttg.httpserver.kmttgServer;

public class config {
public static String kmttg = "kmttg v2.6-l-rc1";
public static String kmttg = "kmttg v2.6-l";

// encoding related
public static String encProfDir = "";
Expand Down
111 changes: 16 additions & 95 deletions src/com/tivo/kmttg/rpc/AutoSkip.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ private synchronized void skipPlayCheck(String tivoName, String contentId) {
monitor_count++;
if (monitor_count > monitor_interval) {
monitor_count = 1;
shouldStillMonitor();
if (!shouldStillMonitor()) {
return;
}
}
long pos = getPosition();
debug.print("pos=" + pos + " end1=" + end1);
Expand Down Expand Up @@ -224,6 +226,9 @@ private synchronized void skipPlayCheck(String tivoName, String contentId) {
if (skip) {
if (pos >= skipData.get(skipData.size()-1).get("end")) {
if (config.autoskip_jumpToEnd == 1) {
if (!shouldStillMonitor()) {
return;
}
if( posEnd != pos ) {
long jumpto = pos + (1000 * 60 * 24); // arbitrarily jump 1 day
print("(pos=" + SkipManager.toMinSec(pos) +
Expand All @@ -239,6 +244,9 @@ private synchronized void skipPlayCheck(String tivoName, String contentId) {
posEnd = -1;
long jumpto = getClosest(pos);
if (jumpto != -1) {
if (!shouldStillMonitor()) {
return;
}
String message = "(pos=" + SkipManager.toMinSec(pos) +
") IN COMMERCIAL. JUMPING TO: " + SkipManager.toMinSec(jumpto+pad_start);
if (pad_start != 0 || pad_stop != 0) {
Expand Down Expand Up @@ -319,10 +327,10 @@ private synchronized long getPosition() {

// RPC query to determine if show being monitored is still being played
// If whatsOn query does not have offerId => show no longer being played on TiVo
private synchronized void shouldStillMonitor() {
private synchronized boolean shouldStillMonitor() {
debug.print("");
if (r == null)
return;
return true;
if (monitor) {
JSONObject result = r.Command("whatsOnSearch", new JSONObject());
if (result == null) {
Expand All @@ -332,7 +340,7 @@ private synchronized void shouldStillMonitor() {
r = new Remote(tivoName);
if (! r.success) {
disable();
return;
return true;
}
} else {
try {
Expand All @@ -342,6 +350,7 @@ private synchronized void shouldStillMonitor() {
// Still playing back show so do nothing
} else {
disable();
return false;
}
}
} catch (JSONException e) {
Expand All @@ -350,7 +359,9 @@ private synchronized void shouldStillMonitor() {
}
} else {
disable();
return false;
}
return true;
}

// Stop monitoring and reset all variables
Expand Down Expand Up @@ -431,38 +442,7 @@ private synchronized long getClosest(long pos) {
}
return closest;
}

// Convert RPC data to skipData hash
/*public synchronized Stack<Hashtable<String,Long>> jsonToShowPoints(JSONObject clipData) {
debug.print("clipData=" + clipData);
Stack<Hashtable<String,Long>> points = new Stack<Hashtable<String,Long>>();
try {
if (clipData.has("segment")) {
JSONArray segment = clipData.getJSONArray("segment");
long offset = 0;
for (int i=0; i<segment.length(); ++i) {
JSONObject seg = segment.getJSONObject(i);
long start = Long.parseLong(seg.getString("startOffset"));
if (i == 0) {
offset = start;
}
start -= offset;
long end = Long.parseLong(seg.getString("endOffset"));
end -= offset;
Hashtable<String,Long> h = new Hashtable<String,Long>();
h.put("start", start);
h.put("end", end);
points.push(h);
}
} else {
error("jsonToShowPoints - segment data missing");
}
} catch (JSONException e) {
error("jsonToShowPoints - " + e.getMessage());
}
return points;
}*/


// Adjust skipData segment 1 end position and
// all subsequent segment points relative to it
private synchronized void adjustPoints(long point) {
Expand Down Expand Up @@ -541,66 +521,7 @@ synchronized Boolean readEntry(String contentId) {
return false;
}

// For Skip enabled program use a D press to detect end of 1st commercial point
/*public static synchronized Long visualDetect(String tivoName) {
Long point = -1L;
Remote r2 = new Remote(tivoName);
if (r2.success) {
try {
long starting = 0;
// Save current position
JSONObject result = r2.Command("Position", new JSONObject());
if (result != null && result.has("position")) {
starting = result.getLong("position");
}
// Jump to time 0
JSONObject json = new JSONObject();
json.put("offset", 0);
result = r2.Command("Jump", json);
Thread.sleep(900);
if (result != null) {
json.remove("offset");
json.put("event", "actionD");
// Send D press and collect time information
result = r2.Command("keyEventSend", json);
// Get position
Thread.sleep(100);
result = r2.Command("Position", new JSONObject());
if (result != null && result.has("position"))
point = result.getLong("position");
if (point < 60000) {
log.print("Too small - jumping again");
// Time likely too small - jump again
Thread.sleep(900);
// Send D press and collect time information
r2.Command("keyEventSend", json);
// Get position
Thread.sleep(100);
result = r2.Command("Position", new JSONObject());
if (result != null && result.has("position"))
point = result.getLong("position");
}
// Jump back to starting position
json.remove("event");
json.put("offset", starting);
result = r2.Command("Jump", json);
}
} catch (Exception e) {
error("visualDetect - " + e.getMessage());
}
r2.disconnect();
}
print("visualDetect point: " + toMinSec(point));

return point;
}*/

private synchronized Stack<Hashtable<String,Long>> hashCopy(Stack<Hashtable<String,Long>> orig) {
debug.print("orig=" + orig);
Expand Down

0 comments on commit 873135c

Please sign in to comment.