How do I block ads on YouTube?

@Stephen304

I successfully use "\ S" (any non-whitespace) in my regex.
Of course you can also write [a-zA-Z0-9].
I also came to the conclusion that with Pi-hole it is almost impossible to successfully block advertising in Youtube. Youtube is doing a very good job.

Speedy70

Hmmm I'm not sure why your form of the regex doesn't work in that case. I've decided to give up on using pihole to block youtube ads and went with youtube vanced instead - that seems to be working great. I'll just keep pihole to catch everything else, but I'm now mostly reliant on uBlock origin and other browser addons.

@Stephen304
Unfortunately, I'm not a regex specialist either.
But originally I also had problems with the spelling. That's why I decided to build the regex so that it does not match the beginning of the domain "r0 ---".

just tested in Pi-hole ... With this spelling match the regex the domains ...

grafik

grafik

yt

@kliopa10

Hello
Since your information has turned out a bit bulky, I suspect you want to use your regex to filter domains that contain the text -q0c?.googlevideo.com ?

Oh well.
I would use the following regex for this:

grafik

or

grafik

Speedy7090

I've found that the only way to get rid of youtube ads is to buy their premium subscription.
I've bought mine through a VPN in a european country so am only paying $4.5 pr. month.

Not sure if this will do anything for me or not. I have no regex experience.

r5.sn-vgqsknez.googlevideo.com
r2.sn-vgqsrnll.googlevideo.com
r2.sn-vgqskned.googlevideo.com
r1.sn-vgqsenls.googlevideo.com
r2.sn-vgqs7ns7.googlevideo.com

i suppose this part?

sn-vgqs

they all have an n too huh..

nez.googlevideo.com
nll.googlevideo.com
ned.googlevideo.com
nls.googlevideo.com
ns7.googlevideo.com

I am pretty sure pi-hole lies. I wrote this regex: * r[0-9]+-+sn-[\w\d]{8}.googlevideo.com which according to regex101.com is an exact match to the URL's YouTube goes to and it still doesn't work.

Pi-Hole uses POSIX ERE regex. Other forms of regex will pass the checks at regex101 and will not work with Pi-Hole. To determine conclusively if your regex will work with Pi-Hole, enable regex debugging per the Pi-Hole documentation, and then dig a domain that you think should be blocked with your new regex. If the domain is blocked by the regex, there will be an entry in /var/log/pihole-FTL.log.

https://docs.pi-hole.net/ftldns/configfile/

1 Like

for information

Youtube seems to use new video domains.

r3---sn-uxax3vh50nugp5-8px6.gvt1.com

Speedy70

1 Like

So can someone please explain, how does ublock/adblock successfully block ALL youtube ads (at least in Waterfox/Firefox)? Why can't pi-hole do the same?

[EDIT]
nvm pi-hole is not aware of full url...

r[0-9]+.sn-vgqs[\w\d]+\.googlevideo\.com

1 Like

:hugs: thanks buddy!

I usually download the YouTube videos offline.
Allavsoft can download YouTube videos and music wihtou ads

I added an regex in my pinole a few days ago as followed
^r.+sn.+(.googlevideo.com)$
It work fine until today my YouTube app on my Samsung smart TV not playing any video anymore. The query list have all the rxxx.googlevideo.com blocked by regex. I remove the entry and YouTube video playing again but when I put it in again the same incident occurs.
For now I do not have YouTube block and the ads are showing up occasionally. Do you know what should I do the preserve the functionality I enjoy a few days ago
Thanks
Edit. The . In regex () group have escape character \ but it not show in the post not sure why

I used a REGEX which blocks all these domains, but unfortunately it also blocks the video playback:
(r)[0-9]---sn-([0-z]){8}.googlevideo.com
This basically means block domains with the following pattern:
r#---sn-XXXXXXXX.googlevideo.com
Where, # is any numer from 0 to 9, and XXXXXXXX is any string of 8 alpha-numerics.

The problem is that I don't know the how to distinguish between the video playback domains and the ad domains.

Any hints on what the pattern is so that I can fix the REGEX?

@Alecz
Hello

I've been studying this topic for some time and came to the conclusion that there are no recognizable features that could be used to uniquely identify Adds.
Youtube does a very good job of misleading DNS-based add-blockers.
I made a regex, which - for me - works quite well.
grafik
But that does not mean that it gives the same result to other users as well. It even makes a difference in which country you are at home or at what time you watch Youtube.
In short. With Pi-Hole Youtube will never be 100% ad-free.
But a combination of add-blocker in the browser and pi-hole as a DNS filter gives very good results.

Speedy 70

Forgive my ignorance, but what is the mechanism behind ublock origin that allows it to recognize ads impregnated into YT video's? Could that mechanism be used as basis for auto-generating blocklists?

1 Like

I don't believe Pi-Hole receives entire address, just the domain, hens it's impossible for it to recognize ads that resides on the same domain as regular videos.

Auf den Bildern erkennt man Nix, bitte korrigieren.