{"id":2201,"date":"2022-07-07T14:40:14","date_gmt":"2022-07-07T09:40:14","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=2201"},"modified":"2022-07-07T15:02:15","modified_gmt":"2022-07-07T10:02:15","slug":"skip-youtube-ads-using-opencv-pyautogui-python3-adblocker","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/","title":{"rendered":"Skip Youtube Ads Using OpenCV, PyAutoGUI &#038; Python 3 AdBlocker"},"content":{"rendered":"\n<p>The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I&#8217;ve also used <code>OpenCV<\/code> and <code>PyAutoGUI<\/code> libraries to implement this project.<\/p>\n\n\n\n<p>At first, you must install <code>PyAutoGUI<\/code> and <code>OpenCV Python<\/code> libraries. To do so, simply execute the below commands in the command line.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">pip install pyautogui<\/pre><\/div>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">pip install opencv-python<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">code.py<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\">import cv2\nimport numpy as np\nimport pyautogui\nimport time\n# faster version\n# lopping over the template matching\n\n# reading the templates\ntemplate3 = cv2.imread('template3.png', 0)\ntemplate4 = cv2.imread('template4.png', 0)\ntemplate5 = cv2.imread('template5.png', 0)\ntemplate6 = cv2.imread('template6.png', 0)\n\n# setting the threshold for confidence in template matching\nthreshold = 0.7\n\n# alert box for stopping criteria\npyautogui.alert(text = 'Keep the mouse pointer on the top left corner of screen to stop the program', title= 'Stopping Criteria')\n\n# continuous loop to check for youtube ad\nwhile True:\n    time.sleep(1)\n    im1 = pyautogui.screenshot()\n    im1 = np.asarray(im1.convert(mode = 'L'))\n#     im1.save('im1.png')\n#     im1 = cv2.imread('im1.png', 0)\n        \n# checking for template3   \n    res = cv2.matchTemplate(im1, template3, cv2.TM_CCOEFF_NORMED)\n    loc = np.where(res &gt;= threshold)\n    \n# checking if template is matched\n    if loc[0].size != 0:\n# clicking on the first match\n        pyautogui.click(list(zip(*loc[::-1]))[0])\n        continue # continue loop from start without further execution of the loop\n        \n# checking for template4      \n    res = cv2.matchTemplate(im1, template4, cv2.TM_CCOEFF_NORMED)\n    loc = np.where(res &gt;= threshold)\n    \n# checking if template is matched\n    if loc[0].size != 0:\n# clicking on the first match\n        pyautogui.click(list(zip(*loc[::-1]))[0])\n        continue # continue loop from start without further execution of the loop\n        \n# checking for template5        \n    res = cv2.matchTemplate(im1, template5, cv2.TM_CCOEFF_NORMED)\n    loc = np.where(res &gt;= threshold)\n    \n# checking if template is matched\n    if loc[0].size != 0:\n# clicking on the first match\n        pyautogui.click(list(zip(*loc[::-1]))[0])\n        continue # continue loop from start without further execution of the loop    \n    \n# checking for template6        \n    res = cv2.matchTemplate(im1, template6, cv2.TM_CCOEFF_NORMED)\n    loc = np.where(res &gt;= threshold)\n    \n# checking if template is matched\n    if loc[0].size != 0:\n# clicking on the first match\n        pyautogui.click(list(zip(*loc[::-1]))[0])\n    \n#     Stopping criteria\n    if pyautogui.position() == (0,0):\n    \tpyautogui.alert(text = 'Adskipper is Closed', title = 'Adskipper Closed')\n    \tbreak<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I&#8217;ve also used OpenCV and PyAutoGUI libraries to implement this project. At first, you must install PyAutoGUI and OpenCV Python libraries. To do so, simply execute the below commands in the command line. code.py<\/p>\n","protected":false},"author":1,"featured_media":1762,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-2201","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Skip Youtube Ads Using OpenCV, PyAutoGUI &amp; Python 3 AdBlocker<\/title>\n<meta name=\"description\" content=\"The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I&#039;ve also used OpenCV and PyAutoGUI libraries to implement this project.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Skip Youtube Ads Using OpenCV, PyAutoGUI &amp; Python 3 AdBlocker\" \/>\n<meta property=\"og:description\" content=\"The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I&#039;ve also used OpenCV and PyAutoGUI libraries to implement this project.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-07T09:40:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-07T10:02:15+00:00\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Skip Youtube Ads Using OpenCV, PyAutoGUI & Python 3 AdBlocker","description":"The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I've also used OpenCV and PyAutoGUI libraries to implement this project.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/","og_locale":"en_US","og_type":"article","og_title":"Skip Youtube Ads Using OpenCV, PyAutoGUI & Python 3 AdBlocker","og_description":"The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I've also used OpenCV and PyAutoGUI libraries to implement this project.","og_url":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-07-07T09:40:14+00:00","article_modified_time":"2022-07-07T10:02:15+00:00","author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Skip Youtube Ads Using OpenCV, PyAutoGUI &#038; Python 3 AdBlocker","datePublished":"2022-07-07T09:40:14+00:00","dateModified":"2022-07-07T10:02:15+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/"},"wordCount":49,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/","url":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/","name":"Skip Youtube Ads Using OpenCV, PyAutoGUI & Python 3 AdBlocker","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","datePublished":"2022-07-07T09:40:14+00:00","dateModified":"2022-07-07T10:02:15+00:00","description":"The below-mentioned Python 3 code-snippet allows you to skip\/block Youtube ads. I've also used OpenCV and PyAutoGUI libraries to implement this project.","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/02\/default_featured_image.jpg","width":880,"height":495,"caption":"Default Featured Image"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/skip-youtube-ads-using-opencv-pyautogui-python3-adblocker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Skip Youtube Ads Using OpenCV, PyAutoGUI &#038; Python 3 AdBlocker"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=2201"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/2201\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/1762"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=2201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=2201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=2201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}