Skip to content

Commit

Permalink
implemented garbageCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Nov 13, 2024
1 parent 008d711 commit 0074f5d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 24 deletions.
2 changes: 1 addition & 1 deletion AuthorHours.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"time":"499h16m40s"}
{"time":"499h30m8s"}
1 change: 1 addition & 0 deletions chrome/cr.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const defaultSettings = {
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: "2024-01-01",
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "1.1.48",
"version": "1.1.49",

"homepage_url": "https://github.com/Dreamlinerm/Netflix-Prime-Auto-Skip",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion chrome/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<img class="Logo" src="../icons/NetflixAmazon Auto-Skip.svg" alt="Logo">
<div class="flex-center flex-col">
<h2 class="title" data-i18n>pageTitle</h2>
<p style="color: grey; font-size: 1em">v.1.1.48</p>
<p style="color: grey; font-size: 1em">v.1.1.49</p>
</div>
</div>
<a target="_blank" class="flex-center flex-col" style="text-align: center; text-decoration: none"
Expand Down
10 changes: 8 additions & 2 deletions chrome/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<img class="Logo" src="../icons/NetflixAmazon Auto-Skip.svg" alt="Logo">
<div class="flex-center flex-col">
<h2 class="title" data-i18n>pageTitle</h2>
<p style="font-size: 1em">v.1.1.48</p>
<p style="font-size: 1em">v.1.1.49</p>
</div>
</div>
<a target="_blank" class="flex-center flex-col" style="text-align: center; text-decoration: none"
Expand Down Expand Up @@ -735,7 +735,13 @@ <h2 data-i18n>ImportSettings</h2>
<h2>Changelog</h2>
<div>
<div class="line flex">
<h2>1.1.48</h2>
<h2>1.1.49</h2>
<ul>
<li>implemented GarbageCollection for DBcache, which deletes ratings older than 30 days</li>
</ul>
</div>
<div class="line flex">
<p>1.1.48</p>
<ul>
<li>Removed section Extras from TMDB ratings on Disney+</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions chrome/popup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const defaultSettings = {
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: "2024-01-01",
},
},
};
Expand Down
32 changes: 25 additions & 7 deletions chrome/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const isEdge = /edg/i.test(ua);
// const isFirefox = /firefox/i.test(ua);
// const isChrome = /chrome/i.test(ua);
const htmlLang = document.documentElement.lang;
const version = "1.1.48";
const date = new Date();
const today = date.toISOString().split("T")[0];
const version = "1.1.49";
if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO) {
/* eslint-env root:true */
// global variables in localStorage
Expand Down Expand Up @@ -89,6 +91,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: today,
},
},
};
Expand All @@ -100,6 +103,23 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
videoSpeed = speed;
}
resetBadge();
// how long a record should be kept in the cache
const GCdiff = 30;
async function garbageCollection() {
// clear every rating older than 30 days
// clear every rating where db != tmdb
log("garbageCollection started, deleting old ratings:");
const keys = Object.keys(DBCache);
for (let key of keys) {
if (getDiffInDays(DBCache[key].date, date) >= GCdiff || DBCache[key].db != "tmdb") {
console.log(DBCache[key].date, key);
delete DBCache[key];
}
}
settings.General.GCdate = today;
setStorage();
setDBCache();
}
async function getDBCache() {
chrome.storage.local.get("DBCache", function (result) {
DBCache = result?.DBCache;
Expand All @@ -117,6 +137,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
if (settings.Disney?.showRating) startShowRatingInterval();
} else if (isPrimeVideo && settings.Amazon?.showRating) startShowRatingInterval();
else if (isHBO && settings.HBO?.showRating) startShowRatingInterval();
if (getDiffInDays(settings.General.GCdate, date) >= GCdiff) garbageCollection();
});
}
function logStartOfAddon() {
Expand Down Expand Up @@ -231,7 +252,6 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
}
}
// ...args
const date = new Date();
function log(...args) {
console.log(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(), ...args);
}
Expand All @@ -241,16 +261,14 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
const kiloBytes = size / 1024;
const megaBytes = kiloBytes / 1024;
if (megaBytes < 5) {
log("updateDBCache, MegaBytes:", megaBytes.toFixed(2));
log("updateDBCache size:", megaBytes.toFixed(4) + " MB");
chrome.storage.local.set({ DBCache });
} else {
log("DBCache cleared", megaBytes);
DBCache = {};
chrome.storage.local.set({ DBCache });
}
}
// chrome.storage.local.set({ DBCache: {} });
const today = date.toISOString().split("T")[0];
async function getMovieInfo(title, card, year = null) {
// justwatch api
// const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
Expand Down Expand Up @@ -354,11 +372,11 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
vote_count < 100 &&
// did not refresh rating in the last 2 days
getDiffInDays(DBCache[title].date, date) > 2 &&
// release date is in the last 30 days after not many people will
// release date is in the last 50 days after not many people will
getDiffInDays(DBCache[title]?.release_date, date) <= 50;

// refresh rating if older than 30 days or release date is in last month and vote count is under 100
if (getDiffInDays(DBCache[title].date, date) >= 30 || diffInReleaseDate) {
if (getDiffInDays(DBCache[title].date, date) >= GCdiff || diffInReleaseDate) {
if (diffInReleaseDate)
log("update recent movie:", title, ",Age:", getDiffInDays(DBCache[title]?.release_date, date), "Vote count:", vote_count);
else log("update old rating:", title, ",Age:", getDiffInDays(DBCache[title].date, date));
Expand Down
1 change: 1 addition & 0 deletions firefox/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ if (isMobile) {
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: "2024-01-01",
},
},
};
Expand Down
1 change: 1 addition & 0 deletions firefox/cr.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const defaultSettings = {
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: "2024-01-01",
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "1.1.48",
"version": "1.1.49",
"homepage_url": "https://github.com/Dreamlinerm/Netflix-Prime-Auto-Skip",
"icons": {
"16": "icons/NetflixAmazon Auto-Skip.svg",
Expand Down
2 changes: 1 addition & 1 deletion firefox/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<img class="Logo" src="../icons/NetflixAmazon Auto-Skip.svg" alt="Logo">
<div class="flex-center flex-col">
<h2 class="title" data-i18n>pageTitle</h2>
<p style="color: grey; font-size: 1em">v.1.1.48</p>
<p style="color: grey; font-size: 1em">v.1.1.49</p>
</div>
</div>
<a target="_blank" class="flex-center flex-col" style="text-align: center; text-decoration: none"
Expand Down
10 changes: 8 additions & 2 deletions firefox/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<img class="Logo" src="../icons/NetflixAmazon Auto-Skip.svg" alt="Logo">
<div class="flex-center flex-col">
<h2 class="title" data-i18n>pageTitle</h2>
<p style="font-size: 1em">v.1.1.48</p>
<p style="font-size: 1em">v.1.1.49</p>
</div>
</div>
<a target="_blank" class="flex-center flex-col" style="text-align: center; text-decoration: none"
Expand Down Expand Up @@ -735,7 +735,13 @@ <h2 data-i18n>ImportSettings</h2>
<h2>Changelog</h2>
<div>
<div class="line flex">
<h2>1.1.48</h2>
<h2>1.1.49</h2>
<ul>
<li>implemented GarbageCollection for DBcache, which deletes ratings older than 30 days</li>
</ul>
</div>
<div class="line flex">
<p>1.1.48</p>
<ul>
<li>Removed section Extras from TMDB ratings on Disney+</li>
</ul>
Expand Down
1 change: 1 addition & 0 deletions firefox/popup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const defaultSettings = {
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: "2024-01-01",
},
},
};
Expand Down
32 changes: 25 additions & 7 deletions firefox/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const isEdge = /edg/i.test(ua);
// const isFirefox = /firefox/i.test(ua);
// const isChrome = /chrome/i.test(ua);
const htmlLang = document.documentElement.lang;
const version = "1.1.48";
const date = new Date();
const today = date.toISOString().split("T")[0];
const version = "1.1.49";
if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO) {
/* eslint-env root:true */
// global variables in localStorage
Expand Down Expand Up @@ -89,6 +91,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
filterDub: true,
filterQueued: true,
savedCrunchyList: [],
GCdate: today,
},
},
};
Expand All @@ -100,6 +103,23 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
videoSpeed = speed;
}
resetBadge();
// how long a record should be kept in the cache
const GCdiff = 30;
async function garbageCollection() {
// clear every rating older than 30 days
// clear every rating where db != tmdb
log("garbageCollection started, deleting old ratings:");
const keys = Object.keys(DBCache);
for (let key of keys) {
if (getDiffInDays(DBCache[key].date, date) >= GCdiff || DBCache[key].db != "tmdb") {
console.log(DBCache[key].date, key);
delete DBCache[key];
}
}
settings.General.GCdate = today;
setStorage();
setDBCache();
}
async function getDBCache() {
browser.storage.local.get("DBCache", function (result) {
DBCache = result?.DBCache;
Expand All @@ -117,6 +137,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
if (settings.Disney?.showRating) startShowRatingInterval();
} else if (isPrimeVideo && settings.Amazon?.showRating) startShowRatingInterval();
else if (isHBO && settings.HBO?.showRating) startShowRatingInterval();
if (getDiffInDays(settings.General.GCdate, date) >= GCdiff) garbageCollection();
});
}
function logStartOfAddon() {
Expand Down Expand Up @@ -231,7 +252,6 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
}
}
// ...args
const date = new Date();
function log(...args) {
console.log(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds(), ...args);
}
Expand All @@ -241,16 +261,14 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
const kiloBytes = size / 1024;
const megaBytes = kiloBytes / 1024;
if (megaBytes < 5) {
log("updateDBCache, MegaBytes:", megaBytes.toFixed(2));
log("updateDBCache size:", megaBytes.toFixed(4) + " MB");
browser.storage.local.set({ DBCache });
} else {
log("DBCache cleared", megaBytes);
DBCache = {};
browser.storage.local.set({ DBCache });
}
}
// browser.storage.local.set({ DBCache: {} });
const today = date.toISOString().split("T")[0];
async function getMovieInfo(title, card, year = null) {
// justwatch api
// const url = `https://apis.justwatch.com/content/titles/${locale}/popular?language=en&body={"page_size":1,"page":1,"query":"${title}","content_types":["show","movie"]}`;
Expand Down Expand Up @@ -354,11 +372,11 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
vote_count < 100 &&
// did not refresh rating in the last 2 days
getDiffInDays(DBCache[title].date, date) > 2 &&
// release date is in the last 30 days after not many people will
// release date is in the last 50 days after not many people will
getDiffInDays(DBCache[title]?.release_date, date) <= 50;

// refresh rating if older than 30 days or release date is in last month and vote count is under 100
if (getDiffInDays(DBCache[title].date, date) >= 30 || diffInReleaseDate) {
if (getDiffInDays(DBCache[title].date, date) >= GCdiff || diffInReleaseDate) {
if (diffInReleaseDate)
log("update recent movie:", title, ",Age:", getDiffInDays(DBCache[title]?.release_date, date), "Vote count:", vote_count);
else log("update old rating:", title, ",Age:", getDiffInDays(DBCache[title].date, date));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "streaming-enhanced",
"version": "1.1.48",
"version": "1.1.49",
"description": "Automatically skip Ads, Intros, Credits and add Speed Control, etc. on Netflix, Prime video, Disney+ & Hotstar and Crunchyroll.",
"scripts": {
"start": "web-ext run --keep-profile-changes --firefox-profile=test --profile-create-if-missing",
Expand Down

0 comments on commit 0074f5d

Please sign in to comment.