Improve PREROLL based on user feedback
This commit is contained in:
parent
1fcfbe5360
commit
1c10d8005a
@ -24,9 +24,11 @@ import {
|
|||||||
} from "./state";
|
} from "./state";
|
||||||
|
|
||||||
const PREROLL_HEURISTICS = /dl|attach|download|name|file|get|retr|^n$|\.(php|asp|py|pl|action|htm|shtm)/i;
|
const PREROLL_HEURISTICS = /dl|attach|download|name|file|get|retr|^n$|\.(php|asp|py|pl|action|htm|shtm)/i;
|
||||||
|
const PREROLL_HOSTS = /4cdn|chan/;
|
||||||
const PREROLL_TIMEOUT = 10000;
|
const PREROLL_TIMEOUT = 10000;
|
||||||
const SHELF_TIMEOUT = 2000;
|
const PREROLL_NOPE = new Set<string>();
|
||||||
|
|
||||||
|
const SHELF_TIMEOUT = 2000;
|
||||||
|
|
||||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||||
// ignored
|
// ignored
|
||||||
@ -71,7 +73,8 @@ function parseDisposition(disp: MimeType) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
const reenableShelf = debounce(() => setShelfEnabled(true), SHELF_TIMEOUT, true);
|
const reenableShelf = debounce(
|
||||||
|
() => setShelfEnabled(true), SHELF_TIMEOUT, true);
|
||||||
|
|
||||||
type Header = {name: string; value: string};
|
type Header = {name: string; value: string};
|
||||||
interface Options {
|
interface Options {
|
||||||
@ -133,7 +136,7 @@ export class Download extends BaseDownload {
|
|||||||
this.updateStateFromBrowser();
|
this.updateStateFromBrowser();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (state[0].state == "complete") {
|
if (state[0].state === "complete") {
|
||||||
this.changeState(DONE);
|
this.changeState(DONE);
|
||||||
this.updateStateFromBrowser();
|
this.updateStateFromBrowser();
|
||||||
return;
|
return;
|
||||||
@ -224,17 +227,23 @@ export class Download extends BaseDownload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get shouldPreroll() {
|
private get shouldPreroll() {
|
||||||
const {pathname, search} = this.uURL;
|
const {pathname, search, host} = this.uURL;
|
||||||
|
if (PREROLL_NOPE.has(host)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!this.renamer.p_ext) {
|
if (!this.renamer.p_ext) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (search.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (this.uURL.pathname.endsWith("/")) {
|
if (this.uURL.pathname.endsWith("/")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (PREROLL_HEURISTICS.test(pathname)) {
|
if (PREROLL_HEURISTICS.test(pathname)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (search.length) {
|
if (PREROLL_HOSTS.test(host)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -347,7 +356,10 @@ export class Download extends BaseDownload {
|
|||||||
this.cancel();
|
this.cancel();
|
||||||
this.error = "SERVER_UNAUTHORIZED";
|
this.error = "SERVER_UNAUTHORIZED";
|
||||||
}
|
}
|
||||||
else if (status >= 400) {
|
else if (status === 400) {
|
||||||
|
PREROLL_NOPE.add(this.uURL.host);
|
||||||
|
}
|
||||||
|
else if (status > 400 && status < 500) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.error = "SERVER_FAILED";
|
this.error = "SERVER_FAILED";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user