How do I block ads on YouTube?

blacklisting

#239

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


#240

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


#241

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


#242

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


#248

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!


#249

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.


#250

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.


#251

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


#252

One can’t use Pi-hole for that.

I use uBlock org. for Youtube and many other rascals.


#253

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


#254

That a loss for us and win for Alphabet.

Create a free service and when everbody can’t do without it any more you are going to have return on your investment by introducing advertising and subscribtions.


#255

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.


#257

pk198105’s solution works, it just needs that last issue to be resolved somehow.


#258

I tried the python script and it ended up blocking most youtube video streams.

Had to disable it and remove the blocked domains it had blacklisted. It did more than just block the ads DNS hosts.


#259

this will also block mobile ads or just youtube on pc in general?


#260

Have blocked 100% ads on pc
Later make solution more easy for pi hole :smiley:


#261

The exact same domains and ips now serve both ads and videos.

I guess uBlock blocks at the browser by checking the request urls. Blocking with dns isn’t going to work anymore :frowning:

I read someone talk about using a dns from a remote country to reduce the number of ads served but I don’t see how that would work since the ads are served based on request ip not resolving the dns.

Any other ideas?


#262

Ads are based on ip address location


#263

I’m not so sure about that. Using a vpn recently as a test the IP was located in US - checked the geo location of the IP and with trace route. But the ads were showing from Dubai.

I wonder if the dns configured there was resolving for Dubai instead of sending a geo local YouTube ip in US

Very odd anyway.


#264

That’s not correct. Yes, you can block ads/trackers delivered by 3rd-party services like doubleclick.net. That’s why Pi-hole works so well as it works on the DNS level.

However, if a (reputable) site like https://www.example.com delivers ads via, say,

http://www.example.com/ads/annoying.js

or

http://www.example.com/adserver/bs.jpg

or whatever you can’t block this with Pi-hole - you would have to block www.example.com completely (which is not what you want). You need an adblocker like uBlock Origin as the filter syntax used in its filterlists is much more flexible.

An ad like

http:// www.spiegel.de/staticgen/data_imports/gutscheine/SpiegelHPWidget_Small_390x85px_rewe_23-10-18RR.jpg

can easily be blocked by uBO with the following filter rule:

||www.spiegel.de/staticgen/data_imports/gutscheine/$image

You can’t do that with Pi-hole.