How do I block ads on YouTube?

Which script are you referring to?

GitHub - kboghdady/youTube_ads_4_pi-hole: YouTube script to add the new Ads list for Pi-hole this one

Hello

Here is my opinion on this topic...

  1. It makes no sense to collect all links from Youtube videos and put them in a blocklist.
    Reason: There is - in my opinion - no clear differentiation between "good" and "bad" links. This means that every link is able to deliver advertising. Sooner or later, this will probably mean that most video links will end up on the blacklist and than no or only a few videos will be displayed.

  2. I also found out that it makes a difference which country you've just connected to Youtube. Also, the DNS servers used seem to somehow have an influence on which and how much advertising gets presented.

For my part, I have come to terms with it and live by the fact that once more or less advertising is displayed. My regex (from above) fulfills its purpose for me. This blocked video links, which are based on the pattern "sn-xxxxxxx-xxxx.googlevideo.com".

so long ...
Speedy70

please excuse my english ... i had to try the google translator :slight_smile:

1 Like

I'm using the script from GitHub - kboghdady/youTube_ads_4_pi-hole: YouTube script to add the new Ads list for Pi-hole
I run the cron job every 5 mins.
I am having no luck at all playing videos when I use a Wired connection unless I disable the Pihole.
The Wired connection's static IP is showing in the blacklist I am unsure why.

I have been using the script for a while and I have videos that wont start unless I disable the pihole.

blacklist.txt Its refreshed every 15 seconds via cron job
http://wagnwashcloud.dogrusoz.net/index.php/s/pekrxZoY3BSia2c/download

.*sn-\S{4,}-\S{4,}\.googlevideo\.com

screenshot
youtube-regex
I've added the above regex. (Hope it's correct)

My youtube domains is tailing out these. I've checked with a regex checker and it's not catching it. Different because of region location?

r1---sn-ogul7n7z.googlevideo.com
r1---sn-ogul7n7z.googlevideo.com
r3---sn-oguesnze.googlevideo.com
r3---sn-oguesnze.googlevideo.com
r3---sn-ogul7n7z.googlevideo.com
r3---sn-oguesnzd.googlevideo.com
r3---sn-oguesnzd.googlevideo.com
r4---sn-ogueln7y.googlevideo.com

Hello @duceduc

Your regex
grafik
and blocking result are perfectly fine that way. The regex does exactly what it was built for. Namely, find domains that have a very specific structure.
please refer:
grafik

The reason why I built the regex is that - at least for me - a lot of advertising come from domains, which have exactly this structure. As stated above, it is almost impossible to get the advertising on Youtube using Regex under control. The only thing that currently helps against this type of advertising is a browser extension (AddBlocker).

greeting
Speedy70

Hi @Speedy70
Thanks for your confirmation. I monitored my youtube videos and it doesn't seem the patterns are the same as yours. However, I think I may have spotted a pattern in mine whenever the initial video ads pops in the beginning of the video.
From the looks of it, ads pop up whenever there are this partial strings 'ogue'. Would you be so kind and adjust the regex so I can test if it's true? Thanks.

r4---sn-oguesnzd.googlevideo.com
r2---sn-oguelnl7.googlevideo.com
r4---sn-oguelnl7.googlevideo.com
r1---sn-oguelned.googlevideo.com
r6---sn-ogueln7k.googlevideo.com
r6---sn-ogueln7z.googlevideo.com
r6---sn-oguesnsy.googlevideo.com
r3---sn-oguelned.googlevideo.com
r3---sn-ogueln7s.googlevideo.com
r5---sn-oguesnzd.googlevideo.com
r2---sn-oguesnzs.googlevideo.com
r3---sn-oguesnzz.googlevideo.com

@duceduc

Hello

try this regex. :slightly_smiling_face:
grafik

greetings
Speedy

@Speedy70
Thank you mate, your regex helped a lot.

r1---sn-ux3n588t-mjhl.googlevideo.com
r4---sn-ux3n588t-mjhe.googlevideo.com
r3---sn-ux3n588t-mjhz.googlevideo.com
r4---sn-ux3n588t-mjh6.googlevideo.com
r3---sn-ux3n588t-mjh6.googlevideo.com


.*sn-\S{4,}-\S{3}[0-9]\.googlevideo\.com

For me, only the last two was serving ads and the rest serving videos.
So I had to modify the regex slightly so that it matches "mjh"+ number.

1 Like

Cheers @kajal09 and @Speedy70, going to try this regex as well.

Gave this a test today and they seem to be serving the ads from the same domain as the video. Any progress on your testing?

Anyone assist to make a regex for this:

r6---sn-h5mpn-30ad.googlevideo.com
r1---sn-h5mpn-30al.googlevideo.com
r6---sn-h5mpn-30ad.googlevideo.com
r1---sn-h5mpn-30al.googlevideo.com
r3---sn-h5mpn-30ay.googlevideo.com
r6---sn-h5mpn-30ad.googlevideo.com

Thank you.

also for this two

r4---sn-4g5ednsz.googlevideo.com
r1---sn-hgn7yn76.googlevideo.com

@ssneoh

Try this regex
grafik

This should match the following variants of your domains.
grafik

Speedy70

@afikzach

Since I can not recognize a clear search pattern for your two domains, I advise you to simply put these domains in the blacklist (Pi-hole ---> Frontend ---> Blacklist ---> Add exact).
Building a matching regex does not really make sense, since almost all video links on Youtube have this structure.
Thus, a regex would match your two video links, synonymous match all other videos with the same link structure and thus block.

Speedy70

correct me if i'm wrong:

r4—sn-4g5ednsz.googlevideo.com
r1—sn-hgn7yn76.googlevideo.com

r[0-9-]*-sn-[a-z0-9]{8}.googlevideo.com

is it correct syntax ? just made it up according to my logic nut i'm not sure

@afikzach

Hello
Your regex would not work because [0-9-] is not a valid expression in my opinion.
Try this regex.
grafik

This should match the following variants of your domains.
grafik

Look at this website https://regex101.com
Here you can try very well, if your regex works and which inputs are matched.

Speedy70

thank you i'll check it

Thank you.

I wasn't able to get your regex to work, I suspect it might be something with the pihole regex engine and the regex features you used. It works fine in regex101's tester, but pasting the exact same in pihole with regex debugging on results in no logged matches and those queries getting through. I reworked it more crudely as r[0-9]+[-]+sn[-]+[A-Za-z0-9]+\.googlevideo\.com, but still no success. Checking my logs it's catching every rx-sn-xxx subdomain and doesn't seem to be blocking anything extraneous according to the regex debug log, but now videos won't load at all. I wonder if youtube has started serving the videos themselves using these random subdomains? At least in the android app, I don't use pihole for laptops/desktops that can use uBlock origin.

Edit: Or, another thing they could have done is refuse to load the video until the ad successfully loads. That would be pretty shitty.