Jump to content
nuhll

Finally a way to block youtube ads via PiHole (WORK IN PROGRES)

14 posts in this topic Last Reply

Recommended Posts

So hi there guys,

im proud to present you a way to block ALL (more or less) ADs in youtube (like on your mobile youtube app - or TV app) with pihole docker.

 

I think it works by extracting ad urls out of the log files of pihole and then blocking it, while allowing normal videos to play. This means, you need to watch every (or visit) ad one time, and then after 15 minutes it should be automatic added to blocklist so you dont need to see it another time.

 

This is neccessary because youtube changes his URLs so often. This is all NOT my WORK (!!!), i just scratched it (and repaired it) from https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/117 many many thanks to Joshua_joezoef_B_ZzO and all other in this thread who helped.

 

BUT i need some help to finish it. See the end of my text.

 

You can skip 1.) if your pihole docker is already set up (you might need to change locations tho if you dont use the same official pihole docker then I!)

 

 

 

1.) Install Pihole docker

i recommend using the pihole:latest (https://github.com/pi-hole/docker-pi-hole)

I use the following "extra arguments": 

-e WEBPASSWORD= -v /mnt/user/appdata/pihole:/etc/pihole --cap-add=NET_ADMIN --dns=127.0.0.1 --dns=8.8.8.8 --env DNS1=192.168.0.1 --env DNS2="no" --restart=unless-stopped

 

"-e WEBPASSWORD=" mean no password, you can add your own password if you like.

 

"v /mnt/user/appdata/pihole:/etc/pihole" this allows you to access the inside of the docker from outside (e.g. via SMB)

 

"--cap-add=NET_ADMIN" recommended (dont know)

 

"--dns=127.0.0.1 --dns=8.8.8.8" this is the DNS Server for the pihole docker (!) first should always be 127.0.0.1 !

 

"--env DNS1=192.168.0.1 --env DNS2="no"" optional, thats the upstream DNS. I want pihole to query my router when he cant find a IP to a domain name (like local DNS name resolution) If not set, will default to googles DNS Service. 

 

"--restart=unless-stopped" recommended (restarts if something fails)

 

 

 

2.) download youtube-adblock-install.sh

and put it in your pihole directory (should be reachable via SMB from outside now)

 

 

 

3.) make it executable

chmod +x /your/path/may/another/youtube-adblock-install.sh

 

 

 

4.) run youtube-adblock-install.sh

from inside the container (i used docker exec pihole sh /etc/pihole/youtube-adblock-install.sh within the unraid terminal)

 

 

 


Now comes my problem. The script itself seems to work. The problem is that some characters from the install script dont get correct written to the youtube-ads.sh (thats the script that the cron entry runs every 15min. Thats why i have uploaded the youtube-ads.sh also, compare it to my version if it doenst work.

 

Next problem is, every update to the pihole docker will probably (?) remove these modifications, i need help out of the community to rewrite this script so that it can be run outside of the docker and just inserted... into pihole?

 

You can check if it works when you go to http://pihole/youtube-ads-list.txt

Thats my steady growing list at the moment:

 



r8.sn-4g5ednzz.googlevideo.com r8---sn-4g5ednzz.googlevideo.com r6.sn-4g5ednll.googlevideo.com r6.sn-4g5edney.googlevideo.com r6.sn-4g5ednek.googlevideo.com r6.sn-4g5ednee.googlevideo.com r6.sn-4g5edn7e.googlevideo.com r6.sn-4g5e6nez.googlevideo.com r6---sn-4g5ednll.googlevideo.com r6---sn-4g5edney.googlevideo.com r6---sn-4g5ednek.googlevideo.com r6---sn-4g5ednee.googlevideo.com r6---sn-4g5edn7e.googlevideo.com r6---sn-4g5e6nez.googlevideo.com r5.sn-h0jeenek.googlevideo.com r5.sn-4g5ednzz.googlevideo.com r5.sn-4g5ednsz.googlevideo.com r5.sn-4g5ednsy.googlevideo.com r5.sn-4g5ednsr.googlevideo.com r5.sn-4g5ednsl.googlevideo.com r5.sn-4g5ednsd.googlevideo.com r5.sn-4g5edns6.googlevideo.com r5.sn-4g5ednly.googlevideo.com r5.sn-4g5edn7s.googlevideo.com r5.sn-4g5e6nzl.googlevideo.com r5.sn-4g5e6nze.googlevideo.com r5.sn-4g5e6nz7.googlevideo.com r5.sn-4g5e6nsz.googlevideo.com r5.sn-4g5e6nsy.googlevideo.com r5.sn-4g5e6nss.googlevideo.com r5.sn-4g5e6nsk.googlevideo.com r5.sn-4g5e6ns7.googlevideo.com r5.sn-4g5e6ns6.googlevideo.com r5.sn-4g5e6nls.googlevideo.com r5.sn-4g5e6ney.googlevideo.com r5.sn-4g5e6n7r.googlevideo.com r5.sn-4g5e6n7k.googlevideo.com r5---sn-h0jeenek.googlevideo.com r5---sn-4g5ednzz.googlevideo.com r5---sn-4g5ednsz.googlevideo.com r5---sn-4g5ednsy.googlevideo.com r5---sn-4g5ednsr.googlevideo.com r5---sn-4g5ednsl.googlevideo.com r5---sn-4g5ednsd.googlevideo.com r5---sn-4g5edns6.googlevideo.com r5---sn-4g5ednly.googlevideo.com r5---sn-4g5edn7s.googlevideo.com r5---sn-4g5e6nzl.googlevideo.com r5---sn-4g5e6nze.googlevideo.com r5---sn-4g5e6nz7.googlevideo.com r5---sn-4g5e6nsz.googlevideo.com r5---sn-4g5e6nsy.googlevideo.com r5---sn-4g5e6nss.googlevideo.com r5---sn-4g5e6nsk.googlevideo.com r5---sn-4g5e6ns7.googlevideo.com r5---sn-4g5e6ns6.googlevideo.com r5---sn-4g5e6nls.googlevideo.com r5---sn-4g5e6ney.googlevideo.com r5---sn-4g5e6n7r.googlevideo.com r5---sn-4g5e6n7k.googlevideo.com r4.sn-4g5ednz7.googlevideo.com r4.sn-4g5ednsy.googlevideo.com r4.sn-4g5ednsk.googlevideo.com r4.sn-4g5ednsd.googlevideo.com r4---sn-4g5ednz7.googlevideo.com r4---sn-4g5ednsy.googlevideo.com r4---sn-4g5ednsk.googlevideo.com r4---sn-4g5ednsd.googlevideo.com r3.sn-4g5ednz7.googlevideo.com r3.sn-4g5ednss.googlevideo.com r3.sn-4g5ednsd.googlevideo.com r3.sn-4g5ednls.googlevideo.com r3.sn-4g5ednll.googlevideo.com r3.sn-4g5ednee.googlevideo.com r3.sn-4g5edned.googlevideo.com r3.sn-4g5edne7.googlevideo.com r3.sn-4g5edne6.googlevideo.com r3.sn-4g5e6nzz.googlevideo.com r3.sn-4g5e6nzs.googlevideo.com r3.sn-4g5e6nsz.googlevideo.com r3.sn-4g5e6nsy.googlevideo.com r3.sn-4g5e6nsk.googlevideo.com r3.sn-4g5e6nle.googlevideo.com r3.sn-4g5e6nld.googlevideo.com r3---sn-4g5ednz7.googlevideo.com r3---sn-4g5ednss.googlevideo.com r3---sn-4g5ednsd.googlevideo.com r3---sn-4g5ednls.googlevideo.com r3---sn-4g5ednll.googlevideo.com r3---sn-4g5ednee.googlevideo.com r3---sn-4g5edned.googlevideo.com r3---sn-4g5edne7.googlevideo.com r3---sn-4g5edne6.googlevideo.com r3---sn-4g5e6nzz.googlevideo.com r3---sn-4g5e6nzs.googlevideo.com r3---sn-4g5e6nsz.googlevideo.com r3---sn-4g5e6nsy.googlevideo.com r3---sn-4g5e6nsk.googlevideo.com r3---sn-4g5e6nle.googlevideo.com r3---sn-4g5e6nld.googlevideo.com r2.sn-hp57kn6e.googlevideo.com r2.sn-h0jeln7e.googlevideo.com r2.sn-h0jeener.googlevideo.com r2.sn-h0jeen76.googlevideo.com r2.sn-4g5ednzz.googlevideo.com r2.sn-4g5ednly.googlevideo.com r2.sn-4g5ednls.googlevideo.com r2.sn-4g5ednle.googlevideo.com r2.sn-4g5ednee.googlevideo.com r2.sn-4g5edned.googlevideo.com r2.sn-4g5edn7y.googlevideo.com r2.sn-4g5e6nsz.googlevideo.com r2.sn-4g5e6nsy.googlevideo.com r2.sn-4g5e6nsk.googlevideo.com r2.sn-4g5e6ns6.googlevideo.com r2.sn-4g5e6nl7.googlevideo.com r2.sn-4g5e6ney.googlevideo.com r2---sn-hp57kn6e.googlevideo.com r2---sn-h0jeln7e.googlevideo.com r2---sn-h0jeener.googlevideo.com r2---sn-h0jeen76.googlevideo.com r2---sn-4g5ednzz.googlevideo.com r2---sn-4g5ednse.googlevideo.com r2---sn-4g5ednly.googlevideo.com r2---sn-4g5ednls.googlevideo.com r2---sn-4g5ednle.googlevideo.com r2---sn-4g5ednee.googlevideo.com r2---sn-4g5edned.googlevideo.com r2---sn-4g5edn7y.googlevideo.com r2---sn-4g5e6nsz.googlevideo.com r2---sn-4g5e6nsy.googlevideo.com r2---sn-4g5e6nsk.googlevideo.com r2---sn-4g5e6ns6.googlevideo.com r2---sn-4g5e6nl7.googlevideo.com r2---sn-4g5e6ney.googlevideo.com r15.sn-4g5ednzz.googlevideo.com r15---sn-4g5ednzz.googlevideo.com r11.sn-4g5ednzz.googlevideo.com r11---sn-4g5ednzz.googlevideo.com r10.sn-4g5ednzz.googlevideo.com r10---sn-4g5ednzz.googlevideo.com r1.sn-h0jeln7e.googlevideo.com r1.sn-h0jeened.googlevideo.com r1.sn-h0jeen76.googlevideo.com r1.sn-4g5ednsd.googlevideo.com r1.sn-4g5ednly.googlevideo.com r1.sn-4g5ednll.googlevideo.com r1.sn-4g5edne6.googlevideo.com r1.sn-4g5e6nzz.googlevideo.com r1.sn-4g5e6nz7.googlevideo.com r1.sn-4g5e6nsy.googlevideo.com r1.sn-4g5e6nez.googlevideo.com r1---sn-h0jeln7e.googlevideo.com r1---sn-h0jeened.googlevideo.com r1---sn-h0jeen76.googlevideo.com r1---sn-4g5ednsd.googlevideo.com r1---sn-4g5ednly.googlevideo.com r1---sn-4g5ednll.googlevideo.com r1---sn-4g5edne6.googlevideo.com r1---sn-4g5e6nzz.googlevideo.com r1---sn-4g5e6nz7.googlevideo.com r1---sn-4g5e6nsy.googlevideo.com r1---sn-4g5e6ns7.googlevideo.com r1---sn-4g5e6nez.googlevideo.com manifest.googlevideo.com r8.sn-n02xgoxufvg3-2gbs.googlevideo.com r8---sn-n02xgoxufvg3-2gbs.googlevideo.com r6.sn-4g5edne7.googlevideo.com r6---sn-4g5edne7.googlevideo.com r5.sn-hp57yn7y.googlevideo.com r5---sn-hp57yn7y.googlevideo.com r4.sn-h0jeln7l.googlevideo.com r4.sn-h0jeln7e.googlevideo.com r4.sn-h0jeened.googlevideo.com r4.sn-4g5ednzz.googlevideo.com r4.sn-4g5edns7.googlevideo.com r4.sn-4g5ednly.googlevideo.com r4.sn-4g5ednld.googlevideo.com r4.sn-4g5edney.googlevideo.com r4.sn-4g5e6nzs.googlevideo.com r4.sn-4g5e6ns6.googlevideo.com r4.sn-4g5e6nez.googlevideo.com r4---sn-h0jeln7l.googlevideo.com r4---sn-h0jeln7e.googlevideo.com r4---sn-h0jeened.googlevideo.com r4---sn-4g5ednzz.googlevideo.com r4---sn-4g5edns7.googlevideo.com r4---sn-4g5ednly.googlevideo.com r4---sn-4g5ednld.googlevideo.com r4---sn-4g5edney.googlevideo.com r4---sn-4g5e6nzs.googlevideo.com r4---sn-4g5e6ns6.googlevideo.com r4---sn-4g5e6nez.googlevideo.com r3.sn-4g5ednzz.googlevideo.com r3.sn-4g5ednsz.googlevideo.com r3.sn-4g5edns6.googlevideo.com r3.sn-4g5ednld.googlevideo.com r3.sn-4g5e6nsr.googlevideo.com r3.sn-4g5e6nl7.googlevideo.com r3---sn-4g5ednzz.googlevideo.com r3---sn-4g5ednsz.googlevideo.com r3---sn-4g5edns6.googlevideo.com r3---sn-4g5ednld.googlevideo.com r3---sn-4g5e6nsr.googlevideo.com r3---sn-4g5e6nl7.googlevideo.com r2.sn-4g5ednse.googlevideo.com r2.sn-4g5ednld.googlevideo.com r2.sn-4g5e6nzl.googlevideo.com r2.sn-4g5e6nez.googlevideo.com r2---sn-4g5ednld.googlevideo.com r2---sn-4g5e6nzl.googlevideo.com r2---sn-4g5e6nez.googlevideo.com r1.sn-4g5ednsr.googlevideo.com r1.sn-4g5ednsl.googlevideo.com r1.sn-4g5ednse.googlevideo.com r1.sn-4g5edned.googlevideo.com r1.sn-4g5e6ns7.googlevideo.com r1.sn-4g5e6ns6.googlevideo.com r1.sn-4g5e6nl6.googlevideo.com r1.sn-4g5e6ne6.googlevideo.com r1---sn-4g5ednsr.googlevideo.com r1---sn-4g5ednsl.googlevideo.com r1---sn-4g5ednse.googlevideo.com r1---sn-4g5edned.googlevideo.com r1---sn-4g5e6ns6.googlevideo.com r1---sn-4g5e6nl6.googlevideo.com r1---sn-4g5e6ne6.googlevideo.com

 

 

If you have any questions i try to help as much as i can. But im no programer.

youtube-adblock-install.sh youtube-ads.sh

Edited by nuhll

Share this post


Link to post
6 hours ago, nuhll said:

So hi there guys,

im proud to present you a way to block ALL (more or less) ADs in youtube (like on your mobile youtube app - or TV app) with pihole docker.

 

I think it works by extracting ad urls out of the log files of pihole and then blocking it, while allowing normal videos to play. This means, you need to watch every (or visit) ad one time, and then after 15 minutes it should be automatic added to blocklist so you dont need to see it another time.

 

This is neccessary because youtube changes his URLs so often. This is all NOT my WORK (!!!), i just scratched it (and repaired it) from https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/117 many many thanks to Joshua_joezoef_B_ZzO and all other in this thread who helped.

 

BUT i need some help to finish it. See the end of my text.

 

You can skip 1.) if your pihole docker is already set up (you might need to change locations tho if you dont use the same official pihole docker then I!)

 

 

 

1.) Install Pihole docker

i recommend using the pihole:latest (https://github.com/pi-hole/docker-pi-hole)

I use the following "extra arguments": 

-e WEBPASSWORD= -v /mnt/user/appdata/pihole:/etc/pihole --cap-add=NET_ADMIN --dns=127.0.0.1 --dns=8.8.8.8 --env DNS1=192.168.0.1 --env DNS2="no" --restart=unless-stopped

 

"-e WEBPASSWORD=" mean no password, you can add your own password if you like.

 

"v /mnt/user/appdata/pihole:/etc/pihole" this allows you to access the inside of the docker from outside (e.g. via SMB)

 

"--cap-add=NET_ADMIN" recommended (dont know)

 

"--dns=127.0.0.1 --dns=8.8.8.8" this is the DNS Server for the pihole docker (!) first should always be 127.0.0.1 !

 

"--env DNS1=192.168.0.1 --env DNS2="no"" optional, thats the upstream DNS. I want pihole to query my router when he cant find a IP to a domain name (like local DNS name resolution) If not set, will default to googles DNS Service. 

 

"--restart=unless-stopped" recommended (restarts if something fails)

 

 

 

2.) download youtube-adblock-install.sh

and put it in your pihole directory (should be reachable via SMB from outside now)

 

 

 

3.) make it executable

chmod +x /your/path/may/another/youtube-adblock-install.sh

 

 

 

4.) run youtube-adblock-install.sh

from inside the container (i used docker exec pihole sh /etc/pihole/youtube-adblock-install.sh within the unraid terminal)

 

 

 


Now comes my problem. The script itself seems to work. The problem is that some characters from the install script dont get correct written to the youtube-ads.sh (thats the script that the cron entry runs every 15min. Thats why i have uploaded the youtube-ads.sh also, compare it to my version if it doenst work.

 

Next problem is, every update to the pihole docker will probably (?) remove these modifications, i need help out of the community to rewrite this script so that it can be run outside of the docker and just inserted... into pihole?

 

You can check if it works when you go to http://pihole/youtube-ads-list.txt

Thats my steady growing list at the moment:

 

 

 

 

 

If you have any questions i try to help as much as i can. But im no programer.

youtube-adblock-install.sh 3.91 kB · 0 downloads youtube-ads.sh 1.19 kB · 0 downloads

See my (old, outdated, don't use it anymore plex has been updated) Plex wrapper script here:
https://github.com/Xaero252/unraid-plex-nvdec

This script can be added to CA User Scripts to run after your automatic docker updates to reinstall the modifications after the docker has updated.
Similarly, you could do this with the pihole docker.

I would also suggest pinging the pihole docker maintainer and see if they might be willing to add a layer for your modification. Since its a direct extension of pihole rather than a hack like my plex script, it is more reasonable to include it in the actual docker image as an optional flag.

Share this post


Link to post

Hi,

 I would love this... can you please clarify 

 

Quote

Now comes my problem. The script itself seems to work. The problem is that some characters from the install script dont get correct written to the youtube-ads.sh (thats the script that the cron entry runs every 15min. Thats why i have uploaded the youtube-ads.sh also, compare it to my version if it doenst work.

 

‘Thanks,

 

H.

Share this post


Link to post

Just let the install script run and then look at youtube-ads.sh, it should look like mine. If not, change it (or download mine).

 

Anyway i removed it after some testing, it seems to block some ads, but not all, but more of a problem is that "auto run next video" doesnt work anymore... also some videos only start after F5...

Edited by nuhll

Share this post


Link to post

tried it some weeks ago and also blocks lots of normal videos and lots of videos that would play ads now get stuck and just wait (likely for a signal that the add is finished , which it wont get).

Also the rate at which new urls for add get generated makes it useless and more an annoiance unfortunately.

Removed it. The method is not the way to go unfortunately.

 

 

Share this post


Link to post

yea, its the right direction, but not 100%... :/

 

does anyone know if a pfsense router could block ads, thru packet insepction or something like that? I look for a way to block ads on devices where i cant use ublock (mobile, TV)

Edited by nuhll

Share this post


Link to post

not sure what you mean. my pihole works across all devices as dns based. Just make the dns for all your devices the pihole and you are good to go.

Share this post


Link to post
On 11/3/2019 at 10:29 PM, nuhll said:

yea, its the right direction, but not 100%... :/

 

does anyone know if a pfsense router could block ads, thru packet insepction or something like that? I look for a way to block ads on devices where i cant use ublock (mobile, TV)

Im second to that. Sick of seeing my wife with ads on her iPhone, where I never see any on my Android special little apk. 🙂 

 

Surely there is a way with pfBlockerNG.

 

Research continues.....

Share this post


Link to post

I have multiple Pi-hole containers running, one for each dedicated network I have at home.

One such dedicated network is for mobile devices.

 

Share this post


Link to post

Gents,

 

After about 3 or even 4 months of experimenting with different solutions and workarounds, digging deep into countless forums, i must say that there's no ideal solution to the above. The specific problem of filtering Youtube ads on devices that won't support browser based ad-blockers (e.g. smart TVs) can't be solved on the network/ router level. Since Google is serving their content and the ads from the same host, DNS filtering won't cut it. You can resolve IPs, reverse lookup DNSes and automate/ recursively add them to filter tables, and in the end you'll block the whole CDN including the content. No matter how intelligent your regex rule is, it will face the same problem. I have tried to triage packets with DPI. Fired up virtual machines running Sophos, PRTG and ntop/nDPI just to catch the streams and analyse them. Wiresharked into the soul of my TV. Hell, i even MITM attacked myself just for fun! I have followed the same logic as @nuhll You know what worked? Streaming to the TV from mobile with Youtube Vanced. Probably there's a thingy around the headers used by Vanced to forward the request. I really did not investigate much. I still see the "starting" ad, from time to time, but that's it.

 

Have not tried VPNs, proxies or even upstream DNS providers, for the reasons mentioned above.

 

 

 

Edited by lizardkink

Share this post


Link to post

had vanced on my smartphone but from one day to the other it stopped working (like doesnt load images and videos) so i throw it away... :(

 

if ublock and co can filter it out, a firewall can do the same.

Edited by nuhll

Share this post


Link to post

Let me be clear - I wish this would work, but alas, this will *not* work.

 

Why? Well, due to TLS and the fact that YouTube holds all the cards. They are serving the ads from the very same servers that serve you content. So ... if you block via DNS, you will also be blocking the same servers trying to serve the content to you. YT is smart enough to know how to close loopholes that undermine their business model (an ad-free experience is available if you pay for YT premium; previously YT Red). And a paid sub brings up privacy concerns of course.

 

uOrigin and similar blockers inspect content *on the endpoint* since they have a MiTM position where TLS is already decrypted. The only way to do the same at the network layer would be to add your own trusted cert on every device and break the TLS, determine the difference between real content vs. ad and scrub from there. This certainly alters the experience where content may/may not work and could very well be spotty as providers change how they operate. Add to this, that it's not even possible to add certs to some IoT type devices (think smart TVs). For iDevices you can manually install certs via MDM or Apple Configurator. Android is fairly straight forward, but that is also why other options are quite abundant on that platform.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.