How do I block ads on YouTube?

I currently use the list above and additionally blacklisted "googlesyndication.com".

At the moment I get no advertising on Youtube and I have for me no impairment on other sides found.

EDIT:

In the meantime advertising has shown.
I blocked also:

i9.ytimg.com
r3---sn-4g57kn7e.googlevideo.com
r2---sn-4g5e6n7d.googlevideo.com
r5---sn-5hne6n7s.googlevideo.com
r18---sn-4g57knd7.googlevideo.com

Ok, a few hours after the first tests comes again more frequent advertising. I have now created a list. I will try to keep them as up-to-date as possible. Feel free to test them.

https://raw.githubusercontent.com/HenningVanRaumle/pihole-ytadblock/master/ytadblock.txt

4 Likes

At the moment I am using the list on the top of this thread and I have noticed that not all ads are blocked.
I will try out your updated list, thank you very much @Henning.

I still get ads on my android devices and searching for *.googlevideo.com in pi-hole's log brings up results that were still not in any of the compiled lists. It's really a whack-a-mole situation.
I was looking up how to use regex in dnsmasq and it seems that there is a patch but it has to be compiled, which I have never done.
http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2013q2/007124.html
GitHub - cuckoohello/dnsmasq-regex: Dnsmasq 2.72 with regex support for server and ipset
Homebrew Formula for installing dnsmasq with regex patch from Jan Seiffert See: http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2013q2/007124.html ยท GitHub

Yes it is and I think even with regex support we will end up in a over blocking dead end, because we can not be sure that all domains serve ads maybe some of them are vital to play the videos.

So it is. I am currently collecting my YT data to see if there are overlaps. Currently I have a domain which apparently transmits advertising and normal videos. But could also be a mistake on my part.

Here is a link to my collected data.

3 Likes

Can you please make a version of the advertisement server list that can be imported into Pi-hole?

A few posts further up I already wrote the link.
Just write in "/etc/pihole/adlist.list"

Here are a few more to add to your list.

r3---sn-25ge7nes.googlevideo.com
r3.sn-25ge7nes.googlevideo.com
r5---sn-a5mlrn7z.googlevideo.com
r5.sn-a5mlrn7z.googlevideo.com
r5---sn-u2bpouxgoxu-hxaz.googlevideo.com
r5.sn-u2bpouxgoxu-hxaz.googlevideo.com

Thanks for the work.

Steve

I created a new python file called

/etc/dnsdumpster/googlevideo-dns.py

with the following code:

#!env python
# -*- coding: utf-8 -*-

from DNSDumpsterAPI import DNSDumpsterAPI

res = DNSDumpsterAPI(False).search('googlevideo.com')

for entry in res['dns_records']['host']:
    host = "{domain}".format(**entry)

    if host != 'googlevideo.com':
        print(host)

and then changed Giblet's script to:

#!/bin/sh
python /etc/dnsdumpster/googlevideo-dns.py > /var/www/html/youtube.txt
pihole -g

There's no need to delete the youtube.txt file. The > causes the file to be overwritten.

If you want to create a bind compatible file change the print line to:

print('zone "' + host + '" { type master; notify no; file "/var/lib/bind/dummy-block"; };')

-- I don't use pi-hole, but I am building my own ad blocking router, using bind, and came across this thread. Thanks for the info.

Am I correct in the assumption that the scipt lists all googlevideo.com domains?

If so, it will use little. Because you will also block the normal videos.

Yes, it will add all of them. I'm in the process of testing which domains serve video.

@Henning, thank you very much! It seems to work. :slight_smile:

I'm going to try your list. Added now.

@Henning This is fantastic thank you for your efforts. It has worked well for me

Using both dnsdumpster method from @Giblet and @Henning's list has worked well for me the last few days. Thanks

For dnsdumpster I use cron to update the list btw:
3 * * * * { /usr/local/bin/googlevideo-dns.py > /var/www/html/youtube.txt && /usr/local/bin/pihole -g; } >/dev/null 2>&1

And I added http://localhost/youtube.txt to /etc/pihole/adlists.list and added Henning's not-block-this.txt to /etc/pihole/whitelist.txt

You cannot use file:///youtube.list in adlists.list because gravity.sh uses cut -d'/' -f3 to determine the filename of the list :frowning:

Previously I used a script to grep all googlevideo.com domains from pihole logs but as stated they also contain content. In case anyone still wants it: https://git.io/vyHPi

P.S. Some of these domains seems pretty ... interesting :slight_smile:

$ whois $( host -4 -t a r2.sn-oxmua5txg-8pxe.googlevideo.com | awk '{ print $NF }' ) | grep '\(descr\|country\)'
descr:          Google Node Server
country:        AT
descr:          Provider Local Registry Block
descr:          next layer Telekommunikationsdienstleistungs- GmbH

$ host $( host r1.sn-j5ou8-cghs.googlevideo.com | awk '{ print $NF }' )
12.78.248.201.in-addr.arpa domain name pointer 201-248-78-12.dyn.dsl.cantv.net.

$ whois $( host r4.sn-qxau5-btqz.googlevideo.com | awk '{ print $NF }' ) | grep '\(descr\|country\)'
descr:          DELTA  Wimax  Network
country:        AZ
descr:          Delta Telecom IP Range
descr:          International Communication Operator
1 Like

Hey so I have noticed that many of the domains that google uses for their ads are very similar except for the first section. See these examples that I pulled from ads that came up on youtube:

r4---sn-ni5f-t8gl
r7---sn-ni5f-t8gl

r3---sn-ni5f-t8ge
r2---sn-ni5f-t8ge
r1---sn-ni5f-t8ge

I would block one exactly like so: "r4---sn-ni5f-t8gl.googlevideo.com" only to have the same ad show up later with this domain: "r7---sn-ni5f-t8gl.googlevideo.com".

Seeing this pattern I decided to try using a wildcard like so: "sn-ni5f-t8gl.googlevideo.com" and it seems to have worked quite well. Currently I am only using these blacklisted wildcard domains to block youtube ads. I deactivated the adlist that was posted here just to verify and it still works quite well. I think that if this doesn't end up causing problems with desired video content then it could be a porwerful tool to help us weed out these ads.

let me know what you guys think.

2 Likes

Edit: nevermind, ads still load...

Might have had a bit of a breakthrough here. check out this Reddit thread.

They have a list of domains, some of which aren't on any adlists that I have been using.

Using this list (minus the www.youtube.com/api/ entry cause that blocks access to the site entirely) in addition to the googlevideo.com entries we have collected I have had a much greater success rate in blocking ads.

It seems that google has a way of detecting when a specific googlevideo.com domain doesn't load and then tries to load an alternate. I noticed that an ad wouldn't load for 3-5 seconds like it does when it's blocked, but then the ad would play anyways after that pause. looking in the Query section of the ad console i could see it trying to load different domains before it found one that went through successfully as seen here:

This needs more testing and I'm but a simple truck driver. I'm sure you guys would be able to use this info in a better way than I can.

Good luck and thanks for all the hard work!

1 Like

I think we are getting closer!

Blocking absolutely every rxxxsnxxxx.googlevideo.com prevented me from playing any videos on youtube (Win10 & Android). All the images and comments load, but if played the buffering circle keeps going for like a minute, followed by an error.

I compiled dnsmasq with regex patch especially to test this.

address=/:r\d+\W+sn-.*.googlevideo.com:/192.168.1.5

PS: With a default pi-hole setup, I only see ads in the Android YT app; no ads on desktop browsers with or without blocker-addons.