import undetected_chromedriver
options = undetected_chromedriver.ChromeOptions()
options.add_argument('--start-maximized')
driver = undetected_chromedriver.Chrome(options=options)
options = uc.ChromeOptions()
options.add_argument("--start-maximized")
import tempfile
import shutil
import undetected_chromedriver
config = {'chrome_driver_executable_path': '/usr/bin/chromedriver'}
class UndetectedWebBrowser:
def __init__(self):
self.temp_dir = None
self.driver_kwargs = {}
if driver_executable_stock := config.get('chrome_driver_executable_path'):
# Copy chromedriver to a temporary file with write permissions to patch it
self.temp_dir = tempfile.mkdtemp()
driver_executable = shutil.copy(driver_executable_stock, self.temp_dir)
self.driver_kwargs.update(driver_executable_path=driver_executable)
def __enter__(self):
self.browser = undetected_chromedriver.Chrome(**self.driver_kwargs)
return self.browser
def __exit__(self, exc_type, exc_val, exc_tb):
self.browser.quit()
if self.temp_dir is not None:
shutil.rmtree(self.temp_dir)
with UndetectedWebBrowser() as driver:
...
from io import BytesIO
from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=FZ1mj9IaczQ')
audio_stream = yt.streams.filter(only_audio=True)[0]
buffer = BytesIO()
audio_stream.stream_to_buffer(buffer)
buffer.seek(0)