from streaming.kerkomroep import Web_KerkOmroep from configparser import ConfigParser from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager import os from streaming.youtube import Web_Youtube class Streamer: def __init__(self, config_path="config.ini") -> None: self.config = ConfigParser() self.config.read(config_path) self.load_config_values() if self.streaming_method == "web": self.setup_web_driver() def load_config_values(self): self.streaming_service = self.config.get('main', 'streaming_service').lower() self.streaming_method = self.config.get('main', 'streaming_method').lower() self.kerk_name = self.config.get('kerk', 'name') self.youtube_id = self.config.get('kerk', 'youtube_channel_id') self.kdg_id = self.config.get('kerk', 'kerkdienstgemist_id') #Setup streamer based on streaming_method if self.streaming_service == "kerkdienstgemist": self.stream_service = Web_KerkOmroep(self.kdg_id) else: #Default to youtube self.stream_service = Web_Youtube(self.youtube_id) def setup_web_driver(self): self.options = Options() self.options.add_argument("start-maximized") self.options.add_experimental_option("detach", True) self.options.add_experimental_option("useAutomationExtension", False) self.options.add_experimental_option("excludeSwitches",["enable-automation"]) self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=self.options) #implicit wait TODO add as config self.driver.timeouts.implicit_wait = 3 def stream(self): if self.streaming_method == "video": if self.streaming_service != "youtube": raise NotImplementedError() os.system(f"streamlink {self.stream_service.get_stream_url()} best") else: #Default to web self.stream_service.pre_load_actions(self.driver) self.driver.get(self.stream_service.livestream_url()) self.stream_service.post_load_actions(self.driver)