How do I block ads on YouTube?

So is this working?

The script works, but the result doesn't. In other words blocks legit videos and you are going to still watch ads.

1 Like

I followed SoNic67's advice in the previous post and added the uBlock Origin's uAssets, and I haven't seen any YouTube ads on my devices since!

For those curious, I added the following URLs into Settings > Block Lists:

https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/experimental.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resources.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt
1 Like

Did the adding of ublock origin filters in my Settings > Block Lists but the number of domains blacklisted didn't increase in my dashboard. Is there something else I should do?

Make sure you select "save and update" on the block list screen. If you just "save" it won't update all the lists.

Or, from the Pi terminal, run pihole -g to update the gravity list.

> [i] Neutrino emissions detected...
>   [✓] Pulling blocklist source list into range
> 
>   [i] Target: raw.githubusercontent.com (hosts)
>   [✓] Status: Retrieval successful
> 
>   [i] Target: mirror1.malwaredomains.com (justdomains)
>   [✓] Status: No changes detected
> 
>   [i] Target: sysctl.org (hosts)
>   [✓] Status: No changes detected
> 
>   [i] Target: zeustracker.abuse.ch (blocklist.php?download=domainblocklist)
>   [✓] Status: No changes detected
> 
>   [i] Target: s3.amazonaws.com (simple_tracking.txt)
>   [✓] Status: No changes detected
> 
>   [i] Target: s3.amazonaws.com (simple_ad.txt)
>   [✓] Status: No changes detected
> 
>   [i] Target: hosts-file.net (ad_servers.txt)
>   [✓] Status: No changes detected
> 
>   [i] Target: raw.githubusercontent.com (annoyances.txt)
>   [✓] Status: Retrieval successful
>   [i] Format: Adblockcomm: file 1 is not in sorted order
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (badware.txt)
>   [✓] Status: Retrieval successful
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (experimental.txt)
>   [✓] Status: Retrieval successful
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (filters.txt)
>   [✓] Status: Retrieval successful
>   [i] Format: Adblockcomm: file 1 is not in sorted order
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (privacy.txt)
>   [✓] Status: Retrieval successful
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (resource-abuse.txt)
>   [✓] Status: Retrieval successful
>   [✓] Format: Adblock
> 
>   [i] Target: raw.githubusercontent.com (resources.txt)
>   [✓] Status: Retrieval successful
> 
>   [i] Target: raw.githubusercontent.com (unbreak.txt)
>   [✓] Status: Retrieval successful
>   [i] Format: Adblockcomm: file 1 is not in sorted order
>   [✓] Format: Adblock
> 
>   [✓] Consolidating blocklists
>   [✓] Extracting domains from blocklists
>   [i] Number of domains being pulled in by gravity: 155602
>   [✓] Removing duplicate domains
>   [i] Number of unique domains trapped in the Event Horizon: 132116
>   [i] Nothing to whitelist!
>   [✓] Parsing domains into hosts format
>   [✓] Cleaning up stray matter
> 
>   [✓] Force-reloading DNS service
>   [✓] DNS service is running
>   [✓] Pi-hole blocking is Enabled

this is the output when I ran pihole -g, but the number of domains blocked didn't go up. It's still in 132K domains which was the same number before I added the ublock origin filters.

these are the lists in /etc/pihole

>  16:43 adlists.list
>  16:46 GitHubVersions
>  16:55 gravity.list
>  14:06 install.log
>  16:55 list.0.raw.githubusercontent.com.domains
>  16:55 list.10.raw.githubusercontent.com.domains
>  16:55 list.11.raw.githubusercontent.com.domains
>  16:55 list.12.raw.githubusercontent.com.domains
>  16:55 list.13.raw.githubusercontent.com.domains
>  16:55 list.14.raw.githubusercontent.com.domains
>  14:06 list.1.mirror1.malwaredomains.com.domains
>  14:06 list.2.sysctl.org.domains
>  14:06 list.3.zeustracker.abuse.ch.domains
>  14:06 list.4.s3.amazonaws.com.domains
>  14:06 list.5.s3.amazonaws.com.domains
>  14:07 list.6.hosts-file.net.domains
>  16:55 list.7.raw.githubusercontent.com.domains
>  16:55 list.8.raw.githubusercontent.com.domains
>  16:55 list.9.raw.githubusercontent.com.domains
>  16:55 list.preEventHorizon
>  17:30 localbranches
>  16:55 local.list
>  17:30 localversions
>  14:06 logrotate
>  17:32 pihole-FTL.db
>  14:06 setupVars.conf

does this mean that the pihole has successfully added the ublock filters eventhough my domains on blocklists have not increased?

It doesn't look like any loaded. Doing some thinking and I'll get back to you.

Those files are not supported by Pi-hole.

Pi-hole uses host like format for it's adlists.

I think the user above that reported no ads, either used it on his client (via a browser plugin) or it was a pure coincidence that he didn't get any ads.

The files above (with the exception of a few entries here and there that actually mess up gravity), are useless (and ignored) in Pi-hole.

1 Like

Here's a related post on the topic of block list formats: How do I add additional block lists to Pi-hole?

Hi all,
So, did someone found a pattern to block youtube ads?
Once the pattern is found it's easy to catch with regex (no need for scripts etc.).

I guess this is impossible, I checked domains which provides videos and those who provide ads, there are the same, no difference, no pattern to discriminate both. It seems that all domains are generated randomly.
Maybe Adblock extension creators have an idea about it...

So, do any of these methods/scripts currently work? I have read through this thread and I am not really sure which of the above solutions actually work or are suggested. I am just wondering if one of the above solutions works. If so, which?

Not really. They (the ads) are self hosted so it's hard to block them at DNS level.

The scripts above DO work on PC but they break Mobile apps (like Youtube and Youtube Music).

However, regex is available in the new version of Pi-hole and that's a path worth looking into ...

check my script for blocking the sites:

1 Like

Should Regex blocking with this string work correctly?

^r[0-9]+*sn-*\.googlevideo\.com$

You can check your expressions here: https://regexper.com.

Yours throws an error there.

Thanks, I'm testing the following now, it doesn't block video (yet?):
r[0-9]+.sn-.\.googlevideo\.com

UPDATE: I had a working one that also blocks video... they are not that stupid

1 Like

Thanks for this.. I'm testing it as well.. so far, no videos blocked, and very few ads getting through. I need to do more detective work on the ones slipping past the block.

Thank you very much for the regex expression!
I also have a few ads which still get through.
I think I have found which domain names still cause these ads.

For example:
r2.sn-4g5edney.googlevideo.com
r2---sn-4g5edney.googlevideo.com
r1.sn-mn4vg5aa-5hnz.googlevideo.com
r1---sn-mn4vg5aa-5hnz.googlevideo.com

The first and third domain names are blocked with the previous regex. The second and fourth domain name (the ones with the tree dashes) still let some ads through.

Can someone create an regex for these domain names ?
Thanks in advance.

I tried a other (more specific) one I made but it has the same problem: it also blocks some video's. But here it is:

r[0-9]*([-]{1,3}|.)sn-[a-z0-9]{8}\.googlevideo\.com

I think YouTube/Google thought of this. Unless someone discovers a more specific pattern in the subdomains that loads the ads.

This is a good tool to check your RegEx against the domains: https://regexr.com