Skip to content

Commit

Permalink
Add support for AdGuard's mp4 filter option
Browse files Browse the repository at this point in the history
Related discussion:
- uBlockOrigin/uBlock-issues#701 (comment)

The `mp4` filter option will be converted to `redirect=noopmp4-1s`
internally, and `media` type will be assumed.
  • Loading branch information
gorhill committed Aug 13, 2019
1 parent 40cdcea commit 68ae847
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/js/redirect-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ const RedirectEngine = function() {

RedirectEngine.prototype.reset = function() {
this.rules = new Map();
this.ruleTypes = new Set();
this.ruleSources = new Set();
this.ruleDestinations = new Set();
this.modifyTime = Date.now();
Expand Down Expand Up @@ -384,7 +383,6 @@ RedirectEngine.prototype.toURL = function(fctxt) {
RedirectEngine.prototype.addRule = function(src, des, type, pattern, redirect) {
this.ruleSources.add(src);
this.ruleDestinations.add(des);
this.ruleTypes.add(type);
const key = `${src} ${des} ${type}`,
entries = this.rules.get(key);
if ( entries === undefined ) {
Expand Down Expand Up @@ -475,6 +473,10 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {
redirect = 'empty';
continue;
}
if ( option === 'mp4' ) {
redirect = 'noopmp4-1s';
continue;
}
if ( option.startsWith('domain=') ) {
srchns = option.slice(7).split('|');
continue;
Expand All @@ -496,8 +498,13 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {

// Need one single type -- not negated.
if ( type === undefined ) {
if ( redirect !== 'empty' ) { return; }
type = '*';
if ( redirect === 'empty' ) {
type = '*';
} else if ( redirect === 'noopmp4-1s' ) {
type = 'media';
} else {
return;
}
}

if ( deshn === '' ) {
Expand Down Expand Up @@ -562,7 +569,6 @@ RedirectEngine.prototype.toSelfie = function(path) {
`${path}/main`,
JSON.stringify({
rules: rules,
ruleTypes: Array.from(this.ruleTypes),
ruleSources: Array.from(this.ruleSources),
ruleDestinations: Array.from(this.ruleDestinations)
})
Expand All @@ -580,7 +586,6 @@ RedirectEngine.prototype.fromSelfie = function(path) {
}
if ( selfie instanceof Object === false ) { return false; }
this.rules = new Map(selfie.rules);
this.ruleTypes = new Set(selfie.ruleTypes);
this.ruleSources = new Set(selfie.ruleSources);
this.ruleDestinations = new Set(selfie.ruleDestinations);
this.modifyTime = Date.now();
Expand Down
2 changes: 1 addition & 1 deletion src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,7 @@ FilterParser.prototype.parseOptions = function(s) {
continue;
}
// Used by Adguard, purpose is unclear -- just ignore for now.
if ( opt === 'empty' ) {
if ( opt === 'empty' || opt === 'mp4' ) {
if ( this.redirect !== 0 ) {
this.unsupported = true;
break;
Expand Down

0 comments on commit 68ae847

Please sign in to comment.