(copy of my original Reddit post here)
After a day and a half or so of running, the auto-populated list is at 122 hostnames and the number of ads I have see I can count on one hand. Only one since this morning and YouTube has been running all day.
You may well see ads appear, but if they are from a new googlevideo hostname, it will be added to the list when you run the script again. Mine is cron'd to run every few minutes and has been working well.
[original post]
A year and a half ago I made a post which showed how I was able to block, or at least reduce, ads on YouTube. Many people commented that they had decent, if mixed, results.
Quarantine time has my mind wandering a bit from my work and I though to revisit this. After poring over hundreds of megabytes of tcpdumps I found that name lookups are done on some of the googlevideo hostnames immediately before an ad ran. The returned IPs were often different than they were in earlier lookups.
So on a hunch I wrote this crap script this morning more as a "what if?" and have been running it all day. It seems to be working well; two hours of Peppa Pig as a test and no ads. (mind numbing...)
It's a very short script and up on Gitlab so others can mess around with it and see how it works for them. More of a proof-of-concept before I do anything further.
Running randoms scripts as root that some guy links to is not a good idea so only run it if you've examined it yourself and understand the risks.
What to do:
EDIT: see README.md for install/uninstall directions.
What it does:
- Checks for a file in your /etc/dnsmasq.d folder that will configure dnsmasq to add a new host file for use. Creates it if it does not exist.
- greps out any "-.googlevideo.com" hostnames from your Pi-hole logs.
- Adds the IP from $forceIP and the hostname from #2 in the new hosts file.
- Sorts it and removes dupes.
Should probably have it auto-update $forceIP and change the hosts file accordingly. May do that if people report back with good results.
My Pi-hole uses the local hosts files in lookups. I don't recall if that is stock practice or something I added after-the-fact.
Again: Running randoms scripts as root that some guy links to is not a good idea so only run it if you've examined it yourself and understand the risks.
Good luck and please report back results.