How do I block ads on YouTube?

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.

I got the script as posted by Marcio_Xavier to work after modifying the timeout in the wolfram URL thanks to instructions from Nurffe and most videos load just fine. What I've noticed is that any videos with music identified by content ID don't load now. Any other videos play fine, but even switching to another video and switching back which has helped when other videos don't load can't help this. Videos with copyrighted music just don't load. If anyone has any hint for this please let me know.

Hi, I tried your script today. It seems there is an error.
Can you please update it.

pi@raspberrypi:/scripts $ ./temp.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 23077  100 23077    0     0  43459      0 --:--:-- --:--:-- --:--:-- 43541
<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='false'
    error='true'
    numpods='0'
    datatypes=''
    timedout=''
    timedoutpods=''
    timing='0.004'
    parsetiming='0.'
    parsetimedout='false'
    recalculate=''
    id=''
    parseidserver='44'
    host='https://www4d.wolframalpha.com'
    server='44'
    related=''
    version='2.6'>
 <error>
  <code>-1</code>
  <msg>Bad value for input parameter</msg>
 </error>
</queryresult>./temp.sh: 24: ./temp.sh: Syntax error: "|" unexpected

Thanks in advance.

Can you post your script here? My version doesn't work :frowning:

Marcio_Xavier script works just fine. I'm running it now. What I suspect people aren't doing is creating a Wolfram Alpha account and entering in their ID (email used to register) in:

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

For example, my ID is:

APPID= "foo@bar.com"

Apart from that, and ensuring your files have the correct local permissions, you're good to go! You may also have to modify the regex portion of the script depending on how the Google servers truncate the hyphens.

cat $FILE | sed -i $FILE -re ‘s/(^r[[:digit:]]+)(.)(sn)/\1—\3-/’ >> $FILE

Becomes

 cat $FILE | sed -i $FILE -re ‘s/(^r[[:digit:]]+)(.)/\1—/’ >> $FILE

rapi3 very kindly suggested this change. Regex is a pain, so I didn't want to spend 15-20mins figuring it out.

1 Like

For me I need to first create an API ID and then input that ID into the APPID field, it doesn't work with your email. You can test it by opening the URL manually in your browser, for me it said "invalid app id".
Please note that it will take a few minutes before your API APP ID becomes active.

PS: If you're using DietPi or any kind of ramlog system, make sure you write the logs to file periodically if you want to take full advantage of the script, since it scans your pihole.log also and adds the youtube domains that slip through!

Lysergic, how did you create an app ID? Do you mind sharing your code? When I put in my email, I was able to make API calls successfully to Wolfram Alpha.

Perhaps I made some mistake then and it didn't work at first then, not sure.
In any case, what I did was I went into my profile (top right corner of the screen, press and there's a dropdown) -> My Apps (API) and from there you click a button, enter some info about your app and it gives you an API code, which I used into the script.
Again, not sure if it's really needed or not, but since at first it didn't work for me I did this and it fixed the problem, hope that helps.