How do I block ads on YouTube?

Frequent advertising in the mobile application is gone.)

Hi All

I have not checked this thread for over two years.

Has anyone found a solution to block YouTube ads on TV Apps for Apple TV, Fire TV etc?

Are the following block list URLs still any good?

https://raw.githubusercontent.com/HenningVanRaumle/pihole-ytadblock/master/ytadblock.txt 1.3k
https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt

Thanks

Hi,

We didn't find reliable method based on DNS request (Pi-hole). For the moment, the only way is to have a web browser that can detect ads from html/url/javascrit.
So you will be able to remove ads if you can install this type of application on the Fire TV, otherwise no.

If you have web browser on the FireTV (I haven't it, I don't know), maybe this post can help you.

1 Like

After I configured Pi-Hole, for a week, I saw ads that are un-skippable 15-seconds only. I did not see 5-seconds skip ads for a whole week. And the ads were more frequent. Its like, Google knows you are trying to block and it was like a punishment.

Now, the ads are high in number, but still skippable sometimes.

On a laptop browser, I don't care, as AbBlock is handling well enough. Only issue is with mobile devices like phones and iPads which we are a bit more frequent.

BTW, I noticed, I see less ads on my Samsung 43 and 65 Smart TV YouTube app.
I see ads on Apple TV -YouTube app on my Samsung 65".

1 Like

Please check similar to how vanced is managing as well.

I have to see if vanced is compatible with OnePlus Two. Thats the only android I have.

this two script are working for me

1º script /etc/pihole/temp.sh

#!/bin/sh
# This script will fetch the Googlevideo ad domains and append them to the Pi-hole block list.
# Run this script daily with a cron job (don't forget to chmod +x)
# More info here: https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/136

# File to store the YT ad domains
FILE=/etc/temp/temp.txt

# Wolfram Alfa AppID
APPID="Register at https://www.wolframalpha.com/ put your id here"

# Fetch the list of domains, remove the ip's and save them
curl 'https://api.hackertarget.com/hostsearch/?q=googlevideo.com' \
| awk -F, 'NR>1{print $1}' \
| grep -vE "redirector|manifest" > $FILE

# Replace r*.sn*.googlevideo.com URLs to r*---sn-*.googlevideo.com
# and add those to the list too
curl "http://api.wolframalpha.com/v2/query?input=googlevideo.com&appid=${APPID}&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More" \
| grep -Po "r\d+---sn-.+.googlevideo.com" >> $FILE

# Scan log file for previously accessed domains
grep r*.googlevideo.com /var/log/pihole.log \
| awk '{print $6}' \
| grep -v '^googlevideo.com\|redirector\|manifest' \
| sort | uniq >> $FILE

# Replace r*.sn*.googlevideo.com URLs to r*---sn-*.googlevideo.com
# and add those to the list too
cat $FILE | sed -i $FILE -re 's/(^r[[:digit:]]+)(\.)(sn)/\1---\3-/' >> $FILE

#delete duplicates
perl -i -ne 'print if ! $x{$_}++' /etc/temp/temp.txt

#demonstrative
cat $FILE >>  /var/www/html/temp.txt

2º script /etc/pihole/youtube-ads.sh

echo off

#copy file to blacklist
cat /etc/temp/temp.txt >> /var/www/html/youtube.txt

#delete duplicates
perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube.txt

#removes the temporary file on the raspberry pi
rm /var/www/html/temp.txt

#updates pihole blacklist/whitelist
pihole -g

crontab
/35 * * * * /etc/pihole/temp.sh
0
/3 * * * * /etc/pihole/youtube-ads.sh

add http://localhost/youtube.txt blacklist from local

block list:

r5---sn--n4v7sn76.googlevideo.com
r6---sn--n4v7sn76.googlevideo.com
r3---sn--30a7yn76.googlevideo.com
r1---sn--ab5szn76.googlevideo.com

sorry for my English

4 Likes

I noticed wolframalpha was not returning any *.googlevideo.com addresses and checked out whats going on. Turns out this api call:

http://api.wolframalpha.com/v2/query?input=googlevideo.com&appid=${APPID}&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More

returns

timedoutpods="Web statistics for all of googlevideo.com,HTML element hierarchy for googlevideo.com"

To solve this increased podtimeout in call

POD_TIMEOUT="20"
http://api.wolframalpha.com/v2/query?input=googlevideo.com&appid=${APPID}&format=plaintext&podtimeout=${POD_TIMEOUT}&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More

Wolframalpha API documentation is here if someone is having other timeout issues Wolfram|Alpha Full Results API Reference

I noticed that block file created will have format like this:
...---sn--...
and in my log all request made are for domains in this format
...---sn-...
so line:
cat $FILE | sed -i $FILE -re 's/(^r[[:digit:]]+)(.)(sn)/\1---\3-/' >> $FILE
I changed to ->:
cat $FILE | sed -i $FILE -re 's/(^r[[:digit:]]+)(.)/\1---/' >> $FILE

I am using combination of pihole (port#53) & unbound (port#5353) on my raspberry. Pihole upstream DNS is unbound Port#5353

I checked the pihole logs. Youtube URL are in this format

r5---sn-uxa0n-ttze.gvt1.com

r3---sn-uxa0n-ttjse.gvt1.com

In these type of url’s “sn-uxa0n” always there & other contents change every time.

If youtube urls are city location based. Then with unbound I think they come from central youtube server, so this method can help everyone who using unbound as upstream DNS

Is some body help me how this method is implement for this type of url. thanks

try to make an experiment and add a wildcard block:
googlevideo.com

Pihole + Ubound combine user

Please some expert help me, in my home internet connection or from my telephone internet data when I play anything on you tube. In my pihole log something like

“http: //r5---sn-uxa0n-ttze.gvt1. com”

Or

“http: //r3---sn-uxa0n-ttjse.googlevideo. com”

Each time this type of url shown in pi log. In all these address “uxa0n” is always common. But when i run queries like this there is not any address with “uxa0n” in this data . so I am confusing this method not working for me as the domain name with this equation not matching with our filter address. What the expert advice me in this situation

curl 'https: //api.hackertarget.com/hostsearch/?q=googlevideo.com'

curl "http: //api.wolframalpha.com/v2/query?input=googlevideo.com&appid=${APPID}&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More" \

I have Youtube Premium, but my Son who is 12 wants to watch Youtube on his AndroidTV. He can't with his Google-Account cause in Europe, Google denies the Use of Youtube for Children under 13 or 16(not clear).

Soooo I set up a new dummy Google-Account but that isn't in the family plan. (Plan is fully used by family members)

So I am a paying Youtube user that has to block youtube ads.

Alternatively you can just change his birthday on his Google account that is already in your family plan and avoid all of that. If you are worried about the content, you can make sure safe search is enabled, which I think is the default anyway.

No than family Link says: Child has to be under 18 or the Age Barrier for Age-Restrictions valid in your Country.

Yeah, I think you have to enter something like 16, then confirm you entered the wrong date previously and they give you all kinds of warnings, but in the end it should work. I don't think they require a birth certificate or something like that. In any case, you can also create a new Google account, transfer all the data, then add it to Family Link if you really want to control it via Family Link. Alternatively you can just use 18+ and be logged into his account and check what he does via myactivity.google.com

No. Any date which makes him older than 15 affects the confirm button to be passive!

back on topic, I have tried both scripts and although it worked for a couple of days, I started to get black loading screen issues.
The script has started to blacklist some servers that are essential to the streaming.

I was also getting sometimes 2 x 40 seconds ads for a single videos, as some said earlier, a Google punishment.

I think there really is no way to block those ads permanently with the pihole...

Not Yet! There was a time I didn't think something like selfmaintained DNS-Blocking would ever exist! Or Complete PCs under 50€.

Maybe not the Pi-Hole is a solution, but a Plugin Chrome or Kodi ehich allows skipping the Commercials.

Just registered to say this, as it can be helpfull:
I was looking for a pihole solution, but if chrome/firefox plugin/extension is enough for you, there is "Enhancer for YouTube", which I having been using many months now and has always blocked the ads ( amount other usefull features ).

For Android there's NewPipe as well as Vanced to enjoy addfree YouTube.