How do I block ads on YouTube?

OK @jaykepeters , no problem.
To block all youtube ads with pihole is impossible, i spend may hours in all topics on these forum, i read and treid a lot of things until i ruined my pihole and start over from scratch again... haha, the only way is to add "uBlock Origin" as browser extension, anyway, that is what i use on my regular PC.
So it has no sence to block any googlevideo.com domain, there are many thousands of them.

I auto download new vids from my sub feed on my NAS, no ads that way

1 Like

How do you manage to do that?

If I had the time, I would create a Google Chrome extension that detects video ads and submits those domains to pi-hole via the api. I don’t even know how that would work, but I could create a php script to add it to a file in the web root and then pihole will use that as an ad list and update every Sunday night or whenever that cron job is scheduled. Still working on some other projects at the moment.

That will only work if you load youtube on a PC (no blocking extension needed).

Anything that will be loaded on a mobile device (connected to the same network with Pi-hole as DNS, phone or tablet) will never load due to the way the mobile platform queries youtube.

It seems that anything loaded via mobile (youtube app or browser) has a bit check or something (some sort of validation) at video load, originating from those (seemingly) random domain names that never validates, and the video will not load.

1 Like

Using synology download station

1 Like

Hey guys,

I've been following all of this here, Reddit and the web pretty closely and been playing with DD-WRT IPTables to intercept all port 53 requests and redirect them to Pi-Hole / some other DNS server.

I've also tried several Regex expressions and it's mostly a failure, and the videos get broken quickly and the ads keep playing anyway.

One thing I might have noticed is that, depending on the upstream DNS used, you get "more" or "less" ads. For example, if I leave my DNS from the ISP, Cloudflare or similar, I get all the crappy cookie, cleaners, etc. local ads. If I use a crazy russian DNS (I'd rather not post it here so Google spies don't get a heads up! :slight_smile:), I mostly stop seeing ads; maybe that white YouTube logo 5 second silent thing at most, every so often. But if I leave my local DNS from the ISP, I get bombarded with ads.

Have any of you guys noticed this behavior and can confirm it? Maybe we can find an even crazier DNS that show even less ads? My silly theory is that, since ads seem to be localized, a DNS in a specific country might not have advertisers paying to show ads there; hence why I'm experiencing this behavior. Or, I'm going crazy after having wasted countless hours with this! :stuck_out_tongue:

Also, as another solution, wouldn't it be great to have a proxy service running on a computer/server that would intercept the YouTube Chromecast calls, get the video, if it's less than 1 minute (check by size or whatever), drop it and send the Chromecast the next video? How crazy is that?

Thanks and let me know what you think!

That last proxy solution is well beyond the scope of Pi-Hole.

I have had very good success with a basic collection of block lists (Wally3K ticked) and uBlock Origin on Mac Safari. No ads.

With the basic blocklists on another Pi-Hole, and no uBlock, I get just a few ads on IOS devices and just skip them after 5 seconds.

I logged into a European IP via VPN, turned off uBlock, and got one ad in an 8 minute YouTube video.

HI jfb,

Yes, of course the proxy solution would be a different thing running on a different server/docker/VM (UNRAID for example), but that might be something that could be developed by someone who has some free time and knowledge! :slight_smile:

And about uBlock and the other countless of blockers, they work great by themselves - they don't even need Pi-Hole for that. The problem is when you are trying to block ads in Chromecast (or any other embedded YouTube app for that matter), you can only relay on intercepting/proxying the requests that it makes and returning something cleaner, without the ads. For every device we are more than covered (PC, Android, etc.); what we are missing sadly is those embedded apps blocking.

Thanks!

here are the regex that will block the random stuff google tries to throw:

this will block all other ads instream:

(^r[[:digit:]]+(\.|\-+)[[:alnum:]]+\-+[[:alnum:]]+\-+[[:alnum:]]+\.)(googlevideo|gvt1)\.com$

this will block preroll but as of writing 8 out of 10 times it will stop the video from playing as google keeps redirecting to a different site randomly which is also blocked by the regex therefore the video wont play until a response is sent of a successful connection:

(^r[[:digit:]]+(\.|\-+)[[:alnum:]]+\-+[[:alnum:]]+\.)(googlevideo|gvt1)\.com$
2 Likes

I dont mind an ad at the beginning but blocking just the ones random ones while playing would be nice.

I've written a Python script that can be run as a cronjob or separately. It will search the logs for youtube advertisement queries and add them to the local blacklist automatically.
It also creates a file blocklist.txt for further use.
For now when I detect an ad I run the script manually over ssh. Otherwise it runs once a day.

You can find it here.

Hope this helps

2 Likes

To clarify your terminology, you are adding these domains to your "blacklist" (a local file), not to blocklists (publicly accessible lists of domains).

That's correct. It also creates a local file with the domains.

Thanks for the idea eLVee!

But how is that different than blocking those domains with a simple RegEx? Plus, you can't know for sure that does are YouTube ads - you'll be blocking pretty much every video...

Please correct me if I'm wrong, thanks!

Not really different. Just experimenting! So far it still plays all video's and block almost everything from my side. But ran into some errors with .sn-. domains.
Regex is a lot simpler than this, but still. Liked a challenge to see how far I would come.

1 Like

this will block preroll but as of writing 8 out of 10 times it will stop the video from playing as google keeps redirecting to a different site randomly which is also blocked by the regex therefore the video wont play until a response is sent of a successful connection:

So what is needed to fix this? I guess BLOCKINGMODE=IP doesn't work. Some people have reported that pointing the ad server domains back to the IP address serving manifest.googlevideo.com works for some reason, but you don't seem to be able to do that with regex blocking.

This thread is a bit on the verbose side. So how does one block YouTube ads.

Great add-on but the problem is it does not work on things like smart TV's or Fire Sticks..

I don't mind an add at the beginning, but you start throwing random ads in 4 times in a 12 min video that's just greedy.