Skip to content

Commit 69e44b2

Browse files
Update AI Overhaul plugin for 0.9.2 (#655)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c981bc4 commit 69e44b2

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

plugins/AIOverhaul/AIOverhaul.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: AIOverhaul
22
description: AI Overhaul for Stash with a full plugin engine included to install and manage asynchronous stash plugins for AI or other purposes.
3-
version: 0.9.1
3+
version: 0.9.2
44
url: https://discourse.stashapp.cc/t/aioverhaul/4847
55
ui:
66
javascript:
@@ -26,6 +26,9 @@ ui:
2626
- http://localhost:4153
2727
- ws://localhost:4153
2828
- https://localhost:4153
29+
- http://127.0.0.1:4153
30+
- ws://127.0.0.1:4153
31+
- https://127.0.0.1:4153
2932
# Add additional urls here for the stash-ai-server if your browser is not on the same host
3033
interface: raw
3134
exec:

plugins/AIOverhaul/InteractionTracker.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,18 @@ class InteractionTracker {
817817
handlePageContext(ctx) {
818818
if (!ctx)
819819
return;
820-
if (!ctx.isDetailView || !ctx.entityId)
820+
// When leaving detail views, allow future entries (even same entity) to re-fire
821+
if (!ctx.isDetailView || !ctx.entityId) {
822+
this.lastDetailKey = null;
823+
// Clear scene context so subsequent scene visits don't reuse stale ids
824+
this.lastScenePageEntered = null;
825+
if (this.currentScene) {
826+
this.cleanupVideoElement(this.currentScene.video);
827+
this.detachVideoJsWatcher(this.currentScene);
828+
this.currentScene = undefined;
829+
}
821830
return;
831+
}
822832
const key = ctx.page + ':' + ctx.entityId;
823833
if (key === this.lastDetailKey)
824834
return;
@@ -1248,12 +1258,14 @@ class InteractionTracker {
12481258
const delay = attempt === 0 ? 0 : Math.min(600, 80 + attempt * 80);
12491259
const handle = window.setTimeout(() => {
12501260
this.playerReinstrumentTimers.delete(player);
1251-
const success = this.instrumentSceneWithVideoJs(sceneId, { player, attempt });
1261+
const targetSceneId = this.resolveSceneIdFromContext() || sceneId;
1262+
// If navigation switched scenes, avoid applying the old scene id
1263+
const success = this.instrumentSceneWithVideoJs(targetSceneId, { player, attempt });
12521264
if (success) {
12531265
this.pendingVideoJsPlayers.delete(player);
12541266
}
12551267
else if (attempt < 6) {
1256-
this.queuePlayerReinstrument(sceneId, player, attempt + 1);
1268+
this.queuePlayerReinstrument(targetSceneId, player, attempt + 1);
12571269
}
12581270
}, delay);
12591271
this.playerReinstrumentTimers.set(player, handle);
@@ -1354,17 +1366,24 @@ class InteractionTracker {
13541366
}
13551367
this.currentScene = state;
13561368
this.cleanupVideoElement(video);
1357-
const onPlay = () => {
1369+
const beginPlayback = () => {
13581370
var _a, _b, _c, _d;
1371+
if (state.lastPlayTs != null)
1372+
return; // already marked playing
13591373
const snapshot = this.getPlaybackSnapshot(state);
1360-
state.lastPlayTs = Date.now();
1374+
// If we attached mid-autoplay with no segments yet, backfill start time from current position
1375+
const now = Date.now();
1376+
const backfill = snapshot.position !== undefined && snapshot.position > 0.5 && state.segments.length === 0;
1377+
state.lastPlayTs = backfill ? now - snapshot.position * 1000 : now;
13611378
if (snapshot.position !== undefined)
13621379
state.lastPosition = snapshot.position;
13631380
this.trackInternal('scene_watch_start', 'scene', sceneId, {
13641381
position: (_b = (_a = snapshot.position) !== null && _a !== void 0 ? _a : state.lastPosition) !== null && _b !== void 0 ? _b : (isFinite(video.currentTime) ? video.currentTime : undefined),
13651382
duration: (_d = (_c = snapshot.duration) !== null && _c !== void 0 ? _c : state.duration) !== null && _d !== void 0 ? _d : (isFinite(video.duration) ? video.duration : undefined)
13661383
});
13671384
};
1385+
const onPlay = () => { beginPlayback(); };
1386+
const onPlaying = () => { beginPlayback(); };
13681387
const onPause = () => {
13691388
var _a, _b, _c, _d;
13701389
const added = this.captureSegment();
@@ -1416,24 +1435,30 @@ class InteractionTracker {
14161435
state.duration = video.duration;
14171436
};
14181437
video.addEventListener('play', onPlay);
1438+
video.addEventListener('playing', onPlaying);
14191439
video.addEventListener('pause', onPause);
14201440
video.addEventListener('ended', onEnded);
14211441
video.addEventListener('timeupdate', onTimeUpdate);
14221442
video.addEventListener('loadedmetadata', onLoaded);
14231443
video._aiInteractionCleanup = () => {
14241444
video.removeEventListener('play', onPlay);
1445+
video.removeEventListener('playing', onPlaying);
14251446
video.removeEventListener('pause', onPause);
14261447
video.removeEventListener('ended', onEnded);
14271448
video.removeEventListener('timeupdate', onTimeUpdate);
14281449
video.removeEventListener('loadedmetadata', onLoaded);
14291450
};
14301451
if (state.player)
14311452
this.attachVideoJsWatcher(state, sceneId, state.player);
1453+
const triggerIfAlreadyPlaying = () => {
1454+
if (!video.isConnected)
1455+
return;
1456+
if (!video.paused || (isFinite(video.currentTime) && video.currentTime > 0))
1457+
beginPlayback();
1458+
};
1459+
triggerIfAlreadyPlaying();
14321460
if (!video.paused) {
1433-
setTimeout(() => {
1434-
if (video.isConnected && !video.paused)
1435-
onPlay();
1436-
}, 0);
1461+
setTimeout(() => { triggerIfAlreadyPlaying(); }, 0);
14371462
}
14381463
}
14391464
trackImageView(imageId, opts) {

0 commit comments

Comments
 (0)