47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
import selenium
|
|
from streaming.kerkomroep import KerkOmroep
|
|
from configparser import ConfigParser
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver import ActionChains
|
|
from selenium.webdriver.chrome.service import Service
|
|
from selenium.webdriver.chrome.options import Options
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
|
from selenium.webdriver.common.by import By
|
|
|
|
from streaming.youtube import Youtube
|
|
|
|
class Streamer:
|
|
def __init__(self, config_path="config.ini") -> None:
|
|
self.config = ConfigParser()
|
|
self.config.read(config_path)
|
|
self.load_config_values()
|
|
self.setup_web_driver()
|
|
|
|
def load_config_values(self):
|
|
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_method == "kerkdienstgemist":
|
|
self.stream_service = KerkOmroep(self.kdg_id)
|
|
else:
|
|
#Default to youtube
|
|
self.stream_service = 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.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):
|
|
self.driver.get(self.stream_service.livestream_url())
|
|
self.stream_service.post_load_actions(self.driver)
|