2022-07-27 16:18:18 +00:00
|
|
|
from streaming.kerkomroep import Web_KerkOmroep
|
2022-05-29 10:29:31 +00:00
|
|
|
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
|
|
|
|
|
2022-07-27 16:18:18 +00:00
|
|
|
from streaming.youtube import Web_Youtube
|
2022-05-29 10:29:31 +00:00
|
|
|
|
|
|
|
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):
|
2022-07-27 16:18:18 +00:00
|
|
|
self.streaming_service = self.config.get('main', 'streaming_service').lower()
|
2022-05-29 10:29:31 +00:00
|
|
|
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
|
2022-07-27 16:18:18 +00:00
|
|
|
if self.streaming_service == "kerkdienstgemist":
|
|
|
|
self.stream_service = Web_KerkOmroep(self.kdg_id)
|
2022-05-29 10:29:31 +00:00
|
|
|
else:
|
|
|
|
#Default to youtube
|
2022-07-27 16:18:18 +00:00
|
|
|
self.stream_service = Web_Youtube(self.youtube_id)
|
2022-05-29 10:29:31 +00:00
|
|
|
|
|
|
|
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):
|
2022-07-27 16:18:18 +00:00
|
|
|
if self.streaming_method == "video":
|
|
|
|
self.stream_service.pre_load_actions(self.driver)
|
|
|
|
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)
|
|
|
|
|