Skip to content

Commit a45d1d3

Browse files
committed
Added playcount threshold for watch activity. #448
1 parent 3ddcc4e commit a45d1d3

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

README.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,29 @@
2424

2525
## Environmental Variables
2626

27-
| Env | Default | Example | Description |
28-
| ----------------------------------- | --------- | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
29-
| POSTGRES_USER `REQUIRED` | `null` | `postgres` | Username that will be used in postgres database |
30-
| POSTGRES_PASSWORD `REQUIRED` | `null` | `postgres` | Password that will be used in postgres database |
31-
| POSTGRES_IP `REQUIRED` | `null` | `jellystat-db` or `192.168.0.5` | Hostname/IP of postgres instance |
32-
| POSTGRES_PORT `REQUIRED` | `null` | `5432` | Port Postgres is running on |
33-
| POSTGRES_SSL_ENABLED | `null` | `true` | Enable SSL connections to Postgres |
34-
| POSTGRES_SSL_REJECT_UNAUTHORIZED | `null` | `false` | Verify Postgres SSL certificates when POSTGRES_SSL_ENABLED=true |
35-
| JS_LISTEN_IP | `0.0.0.0` | `0.0.0.0` or `::` | Enable listening on specific IP or `::` for IPv6 |
36-
| JWT_SECRET `REQUIRED` | `null` | `my-secret-jwt-key` | JWT Key to be used to encrypt JWT tokens for authentication |
37-
| TZ `REQUIRED` | `null` | `Etc/UTC` | Server timezone (Can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) |
38-
| JS_BASE_URL | `/` | `/` | Base url |
39-
| JS_USER | `null` | `User` | Master Override User in case username or password used during setup is forgotten (Both `JS_USER` and `JS_PASSWORD` required to work) |
40-
| JS_PASSWORD | `null` | `Password` | Master Override Password in case username or password used during setup is forgotten (Both `JS_USER` and `JS_PASSWORD` required to work) |
41-
| POSTGRES_DB | `jfstat` | `jfstat` | Name of postgres database |
42-
| REJECT_SELF_SIGNED_CERTIFICATES | `true` | `false` | Allow or deny self signed SSL certificates |
43-
| JS_GEOLITE_ACCOUNT_ID | `null` | `123456` | maxmind.com user id to be used for Geolocating IP Addresses (Can be found at https://www.maxmind.com/en/accounts/current/edit) |
44-
| JS_GEOLITE_LICENSE_KEY | `null` | `ASDWdaSdawe2sd186` | License key you need to generate on maxmind to use their services |
45-
| MINIMUM_SECONDS_TO_INCLUDE_PLAYBACK | `1` | `10` | The minimum time (in seconds) to include a playback record, which can be used to exclude short playbacks |
46-
| IS_EMBY_API | `false` | `true` | Set to true if using Emby instead of Jellyfin |
47-
| JF_USE_WEBSOCKETS | `true` | `false` | Enables using Jellyfins websocket connection for session data (No effect on Emby) |
48-
| JS_USE_EXTERNAL_HOST | `false` | `true` | Prioritises using External host value for some internal communications and processes |
27+
| Env | Default | Example | Description |
28+
| ----------------------------------- | --------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
29+
| POSTGRES_USER `REQUIRED` | `null` | `postgres` | Username that will be used in postgres database |
30+
| POSTGRES_PASSWORD `REQUIRED` | `null` | `postgres` | Password that will be used in postgres database |
31+
| POSTGRES_IP `REQUIRED` | `null` | `jellystat-db` or `192.168.0.5` | Hostname/IP of postgres instance |
32+
| POSTGRES_PORT `REQUIRED` | `null` | `5432` | Port Postgres is running on |
33+
| POSTGRES_SSL_ENABLED | `null` | `true` | Enable SSL connections to Postgres |
34+
| POSTGRES_SSL_REJECT_UNAUTHORIZED | `null` | `false` | Verify Postgres SSL certificates when POSTGRES_SSL_ENABLED=true |
35+
| JS_LISTEN_IP | `0.0.0.0` | `0.0.0.0` or `::` | Enable listening on specific IP or `::` for IPv6 |
36+
| JWT_SECRET `REQUIRED` | `null` | `my-secret-jwt-key` | JWT Key to be used to encrypt JWT tokens for authentication |
37+
| TZ `REQUIRED` | `null` | `Etc/UTC` | Server timezone (Can be found at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) |
38+
| JS_BASE_URL | `/` | `/` | Base url |
39+
| JS_USER | `null` | `User` | Master Override User in case username or password used during setup is forgotten (Both `JS_USER` and `JS_PASSWORD` required to work) |
40+
| JS_PASSWORD | `null` | `Password` | Master Override Password in case username or password used during setup is forgotten (Both `JS_USER` and `JS_PASSWORD` required to work) |
41+
| POSTGRES_DB | `jfstat` | `jfstat` | Name of postgres database |
42+
| REJECT_SELF_SIGNED_CERTIFICATES | `true` | `false` | Allow or deny self signed SSL certificates |
43+
| JS_GEOLITE_ACCOUNT_ID | `null` | `123456` | maxmind.com user id to be used for Geolocating IP Addresses (Can be found at https://www.maxmind.com/en/accounts/current/edit) |
44+
| JS_GEOLITE_LICENSE_KEY | `null` | `ASDWdaSdawe2sd186` | License key you need to generate on maxmind to use their services |
45+
| MINIMUM_SECONDS_TO_INCLUDE_PLAYBACK | `1` | `10` | The minimum time (in seconds) to include a playback record, which can be used to exclude short playbacks |
46+
| IS_EMBY_API | `false` | `true` | Set to true if using Emby instead of Jellyfin |
47+
| JF_USE_WEBSOCKETS | `true` | `false` | Enables using Jellyfins websocket connection for session data (No effect on Emby) |
48+
| JS_USE_EXTERNAL_HOST | `false` | `true` | Prioritises using External host value for some internal communications and processes |
49+
| NEW_WATCH_EVENT_THRESHOLD_HOURS | 1 | 1-12 | This value sets the max time between watch sessions to determine if a watch is a new session or should be added onto the last session thats happened within this threshold. EG last watch within the last 1 hour. After 1 hour, a new session for the same item will be considered a new watch event. |
4950

5051
## Getting Started with Development
5152

backend/tasks/ActivityMonitor.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const MINIMUM_SECONDS_TO_INCLUDE_PLAYBACK = process.env.MINIMUM_SECONDS_TO_INCLU
1313
? Number(process.env.MINIMUM_SECONDS_TO_INCLUDE_PLAYBACK)
1414
: 1;
1515

16+
const NEW_WATCH_EVENT_THRESHOLD_HOURS = process.env.NEW_WATCH_EVENT_THRESHOLD_HOURS
17+
? Math.max(Math.min(Number(process.env.NEW_WATCH_EVENT_THRESHOLD_HOURS), 12), 1)
18+
: 1;
19+
1620
// const webhookManager = new WebhookManager();
1721

1822
async function getSessionsInWatchDog(SessionData, WatchdogData) {
@@ -168,7 +172,7 @@ async function ActivityMonitor(defaultInterval) {
168172
if (hasActiveSessions !== lastHadActiveSessions || settingsChanged) {
169173
if (hasActiveSessions !== lastHadActiveSessions) {
170174
console.log(
171-
`[ActivityMonitor] Switching to ${hasActiveSessions ? "active" : "idle"} polling mode (${currentInterval}ms)`
175+
`[ActivityMonitor] Switching to ${hasActiveSessions ? "active" : "idle"} polling mode (${currentInterval}ms)`,
172176
);
173177
lastHadActiveSessions = hasActiveSessions;
174178
}
@@ -299,14 +303,14 @@ async function ActivityMonitor(defaultInterval) {
299303
/////get data from jf_playback_activity within the last hour with progress of <=80% for current items in session
300304

301305
const ExistingRecords = await db
302-
.query(`SELECT * FROM jf_recent_playback_activity(1)`)
306+
.query(`SELECT * FROM jf_recent_playback_activity(${NEW_WATCH_EVENT_THRESHOLD_HOURS})`)
303307
.then((res) => {
304308
if (res.rows && Array.isArray(res.rows) && res.rows.length > 0) {
305309
return res.rows.filter(
306310
(row) =>
307311
playbackToInsert.some(
308-
(pbi) => pbi.NowPlayingItemId === row.NowPlayingItemId && pbi.EpisodeId === row.EpisodeId
309-
) && row.Progress <= 80.0
312+
(pbi) => pbi.NowPlayingItemId === row.NowPlayingItemId && pbi.EpisodeId === row.EpisodeId,
313+
) && row.Progress <= 80.0,
310314
);
311315
} else {
312316
return [];
@@ -351,8 +355,8 @@ async function ActivityMonitor(defaultInterval) {
351355
(pb) =>
352356
pb.PlaybackDuration >= MINIMUM_SECONDS_TO_INCLUDE_PLAYBACK &&
353357
!ExistingRecords.some(
354-
(er) => er.NowPlayingItemId === pb.NowPlayingItemId && er.EpisodeId === pb.EpisodeId && er.UserId === pb.UserId
355-
)
358+
(er) => er.NowPlayingItemId === pb.NowPlayingItemId && er.EpisodeId === pb.EpisodeId && er.UserId === pb.UserId,
359+
),
356360
);
357361

358362
//remove items where PlaybackDuration===0

0 commit comments

Comments
 (0)