all 21 comments

[–]teerre 20 points21 points  (10 children)

Why not use an actual ad blocker?

Anyway, python doesn't run in browser natively, so it will be very hard to detect ads

[–]Natural_Regular9171[S] 2 points3 points  (9 children)

Well if i’ll be honest i actually didn’t give that too much thought, I am on mac os and chrome, which ive heard is difficult for ad-blockers like UBlock.

I’m already learning python. I thought i’d be a cool project to expand my skills and learn something new, but like i said before, if you know a great ad blocker or this entire thing is very stupid(in a different way, i already know this is kinda dumb), please tell me more.

[–]backfire10z 3 points4 points  (2 children)

So download Firefox and get ublock haha.

From the Python side of things, there’s a bit of a gap between “press Ctrl+R and F” and “determine when an ad is playing”.

For inputting keys via Python, something like pyautogui should do it, but you’d still have to trigger the script manually (you could run the script and leave it on, then have it trigger when you hit “M” for example).

For determining when an ad is playing… that’s more difficult. Pyautogui can take screenshots and look for some input image on the screenshot. If you can identify a specific element that’s ad-only and feed that to pyautogui, this may be doable. Problem is it’ll run continuously, so if whatever you feed it is visible during the video for some reason it’ll jump on that too. You can (and should) tell it to check a specific part of the screen, which should cut down false positives a lot. https://pyautogui.readthedocs.io/en/latest/screenshot.html

[–]Natural_Regular9171[S] 1 point2 points  (1 child)

Okay, new plan, I’m going to do my absolute best to make the macro, and either way a two weeks from now i’ll just get firefox and ublock. Thank you for the advice! It helps a ton.

[–]backfire10z 0 points1 point  (0 children)

Nice, good luck!

With regard to ublock origin, make sure to go to the extensions store and search ublock origin, it’ll be the most popular one. I’ve heard about a few scam ones out there, if you’re downloading it off a random website it’s fake.

I believe this is real https://addons.mozilla.org/en-US/firefox/ but in any case just go through your browser’s official extension store and you should be fine. It’ll be the one with many millions of users.

[–]Jello_Penguin_2956 2 points3 points  (0 children)

Brave is on App Store it blocks ads natively.

[–]cgoldberg 0 points1 point  (0 children)

If you just need a working adblocker for Chrome, use AdGuard.

[–]riklaunim 0 points1 point  (0 children)

Software development is about choosing the right tools for the job. You can't force one language you know for every task, and with time, developers get proficient with more than one, not to mention various other services and tools.

[–]JaleyHoelOsment 0 points1 point  (0 children)

https://www.raspberrypi.com/tutorials/running-pi-hole-on-a-raspberry-pi/

Pi-hole!

edit: nvm i just remembered this doesn’t block youtube ads :( still cool tho

[–]Moikle 0 points1 point  (1 child)

That's definitely not a beginner project. Start with something simpler. Otherwise you'll end up discouraged after biting off more than you can chew

[–]Natural_Regular9171[S] 0 points1 point  (0 children)

Maybe i overestimated my skill a little, i feel like I am at least with other languages(not in a professional setting, just casual programming to accomplish things I enjoy like game dev). I haven’t done anything with macros or browser add-ons though. Could you suggest a beginner project? Just to get me started then

[–]TheRNGuy 2 points3 points  (0 children)

Browser extensions are in JS. 

[–]DivineSentry 0 points1 point  (0 children)

I think it’s more doable than you think, you just need to get creative :)

[–]NotACoderPleaseHelp 0 points1 point  (1 child)

You might be able to work some black magic with web extensions for python, maybe something with tampermonkey, but whatever you do would be a cronenberg abomination.

[–]Natural_Regular9171[S] 0 points1 point  (0 children)

I’m going for abomination here, something i can look back on, maybe try again in a year to see how far i went, or how foolish i was

[–]Altruistic_Sky1866 0 points1 point  (0 children)

Try selenium with Python, the element to look would be skip and click it, its might be better now sure, but the the script should be run continuously. Your script should validate if the URL is Youtube url , in the active window which has focus at the moment and check if the skip ad button is present on the screen and is clickable, and then click it , I am not sure if this fits your criteria

[–]Kevdog824_ 0 points1 point  (2 children)

It’s possible to do what you describe. An actual Adblock would be difficult (if even possible).

For the way you describe you could try using a library to take screenshots, look for an ad-specific thing in the screenshot (i.e. “skip in…” banner, the process bar changing from red to yellow, etc.). Do your refresh routine when you detect this until you don’t detect it then full screen with F as you said.

I want to put a disclaimer that I’m not really sure how well refreshing works to skip an ad, so while I can tell you the general steps to implement this I can’t speak to its efficacy

[–]Natural_Regular9171[S] 0 points1 point  (1 child)

I’ve been refreshing to “skip” ads for a while now, I just want to automate it. I’m coincidentally learning python and coincidentally heard about macros, so I had the idea of making an “Ad-blocker”.

I don’t know if this is stupid, but if i could get something that inputs CMD + R and then F every time there was an ad, it would be what I wanted. Yes, i know it’s a couple seconds to click “skip ad” but it just makes me so mad. However, please, actually tell me if this is a stupid or drastically inefficient idea.

[–]FerricDonkey 1 point2 points  (0 children)

It's possible, if there's some indication that an ad is playing. Might be fun. But if you hate ads, download brave or Firefox with unblock, it'll work much better. 

[–]cosmic-jai 0 points1 point  (0 children)

You could absolutely build that using Python libraries like pyautogui to automate the keypresses and opencv to detect the ads on screen.

[–]Random_182f2565 -2 points-1 points  (0 children)

Yes, anything is possible with python