Using Adblock Plus filter lists with BFilter
I have written filter that converts Adblock Plus filters into BFilter patterns that can be added to urls.local. Using the companion shell script and cron, you can keep your copy of BFilter up-to-date.
Here's all you need to do:
- Download the filter script and move it to some reasonable directory, like /usr/local/bin. Make sure the script is executable.
- Download the shell script, perhaps to /usr/local/bin, and make it executable.
- Use cron to make the shell script run periodically.
You should edit both the filter and shell scripts to make sure that the first line correctly points to Perl and BASH on your system. Currently, they use /usr/bin/perl and /usr/local/bin/bash. You may also want to change some of the configuration parameters at the top of each script.
Configuring the Filter script
The filter script accepts an Adblock Plus filter list on STDIN and emits a list of BFilter patterns on STDOUT.
There are parameters in the script for:
- Determining the BFilter "prefix" to use for each type of converted pattern.
- Block - strong. Default: ++++++
- Block - weak. Default: +++
- Exempt - strong. Default: ALLOW
- Exempt - weak. Default: ---
Configuring the Shell script
The shell script copies the current version of an Adblock Plus filter list to a temporary file, then creates a new version of urls.local by using cat to merge this file and the contents of urls.local.save (if it exists).
If you currently have your own BFilter patterns in the file urls.local, rename the file to urls.local.save.
There are parameters in the script for:
- The URL for the filter list to fetch. Default: http://easylist.adblockplus.org/adblock_rick752.txt
- The output file. Default: /usr/local/etc/bfilter/urls.local
- Your own local urls. Default: /usr/local/etc/bfilter/urls.local.save
- The temp file. Default: /tmp/bfilterList.tmp
- The path to wget. Default: /usr/local/bin/wget
- The path to cat. Default: /bin/cat
- The path to my Filter script. Default: /usr/local/bin/adblock2bfilter.pl
- The path to the script to restart bfilter. Default: /usr/local/etc/rc.d/bfilter
NOTE: This is a FreeBSD solution. You may have to change this part of the script for your OS.