Initial commit. Services for Kdg and Youtube implemented
This commit is contained in:
commit
ef4be04d6e
8
config.ini
Normal file
8
config.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[main]
|
||||||
|
streaming_method = youtube
|
||||||
|
|
||||||
|
[kerk]
|
||||||
|
name = immanuel kapel
|
||||||
|
youtube_channel_id = UCud4rRtOf2e146HZWDfj6YA
|
||||||
|
kerkdienstgemist_id = 2112-Immanuelkapel
|
||||||
|
|
41
main.py
Executable file
41
main.py
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#! /usr/bin/python3
|
||||||
|
from streamer import Streamer
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("config", help="Path to config.ini file", default="config.ini")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
streamer = Streamer(args.config)
|
||||||
|
streamer.stream()
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
omr = Youtube("UCIh6v7QDfo8FBYAifTMrD3A")
|
||||||
|
|
||||||
|
#Update driver
|
||||||
|
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
|
||||||
|
|
||||||
|
#Start kerkomroep
|
||||||
|
options = Options()
|
||||||
|
options.add_argument("start-maximized")
|
||||||
|
options.add_experimental_option("detach", True)
|
||||||
|
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
|
||||||
|
|
||||||
|
#Open livestream url
|
||||||
|
driver.get(omr.livestream_url())
|
||||||
|
|
||||||
|
driver.timeouts.implicit_wait = 3
|
||||||
|
|
||||||
|
# while True:
|
||||||
|
# try:
|
||||||
|
# button = driver.find_element(by=By.XPATH, value=omr.get_xpath())
|
||||||
|
# if button != None:
|
||||||
|
# break
|
||||||
|
# except:
|
||||||
|
# pass
|
||||||
|
# time.sleep(1)
|
||||||
|
|
||||||
|
# actionChains = ActionChains(driver)
|
||||||
|
# actionChains.move_to_element(button).click().perform()
|
46
streamer.py
Normal file
46
streamer.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
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)
|
24
streaming/base_stream.py
Normal file
24
streaming/base_stream.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.common.by import By
|
||||||
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
import time
|
||||||
|
|
||||||
|
class StreamService:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def livestream_url(self):
|
||||||
|
raise NotImplemented()
|
||||||
|
|
||||||
|
def is_live(self):
|
||||||
|
raise NotImplemented()
|
||||||
|
|
||||||
|
def get_xpath(self):
|
||||||
|
raise NotImplemented()
|
||||||
|
|
||||||
|
def click_video_play(self):
|
||||||
|
raise NotImplemented()
|
||||||
|
|
||||||
|
def post_load_actions(self, driver):
|
||||||
|
raise NotImplemented()
|
37
streaming/kerkomroep.py
Normal file
37
streaming/kerkomroep.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import urllib.request
|
||||||
|
|
||||||
|
from streaming.base_stream import *
|
||||||
|
|
||||||
|
IMMANUELKAPEL_URL = "https://kerkdienstgemist.nl/stations/2112-Immanuelkapel/"
|
||||||
|
ICHTHUSKERK_URL = "https://kerkdienstgemist.nl/stations/2110-Ichthuskerk-Ridderkerk/"
|
||||||
|
LIVESTREAM_URL = "events/live"
|
||||||
|
XPATH= "/html/body/div[5]/div/article/div/div/div[1]/div[1]/div/div[2]"
|
||||||
|
|
||||||
|
class KerkOmroep(StreamService):
|
||||||
|
def __init__(self, kerk_id=IMMANUELKAPEL_URL) -> None:
|
||||||
|
self.kerk_id = kerk_id #URL that points to the church inside the kerkomroep environment
|
||||||
|
pass
|
||||||
|
|
||||||
|
def livestream_url(self):
|
||||||
|
return f"https://kerkdienstgemist.nl/stations/{self.kerk_id}/{LIVESTREAM_URL}"
|
||||||
|
|
||||||
|
def is_live(self):
|
||||||
|
# TODO add check to see when the livestream goes up
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_xpath(self):
|
||||||
|
return XPATH
|
||||||
|
|
||||||
|
def click_video_play(self, driver):
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
button = driver.find_element(by=By.XPATH, value=self.get_xpath())
|
||||||
|
if button != None:
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
time.sleep(1)
|
||||||
|
button.click()
|
||||||
|
|
||||||
|
def post_load_actions(self, driver):
|
||||||
|
self.click_video_play(driver)
|
34
streaming/youtube.py
Normal file
34
streaming/youtube.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from streaming.base_stream import *
|
||||||
|
|
||||||
|
ICHTHUSKERK_ID = "UCIh6v7QDfo8FBYAifTMrD3A"
|
||||||
|
IMMANUELKAPEL_ID = "UCud4rRtOf2e146HZWDfj6YA"
|
||||||
|
START_FULL_WINDOW = "?start=68" #Note, this is not full screen, but full window
|
||||||
|
|
||||||
|
class Youtube(StreamService):
|
||||||
|
def __init__(self, id=IMMANUELKAPEL_ID) -> None:
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
def livestream_url(self):
|
||||||
|
return f"https://www.youtube.com/channel/{self.id}/live{START_FULL_WINDOW}"
|
||||||
|
|
||||||
|
def is_live(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def post_load_actions(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
def post_load_actions(self, driver):
|
||||||
|
self.bypass_cookies(driver)
|
||||||
|
|
||||||
|
def bypass_cookies(self, driver):
|
||||||
|
if 'consent.youtube.com' in driver.current_url:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
accept_button = driver.find_elements(by=By.XPATH, value='//*[contains(text(),"Accept all")]')[1]
|
||||||
|
if accept_button != None:
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
time.sleep(1)
|
||||||
|
accept_button.click()
|
||||||
|
#driver.find_element_by_xpath('//button[@aria-label="Agree to the use of cookies and other data for the purposes described"]').click()
|
8
tests/kerkdienstgemist.ini
Normal file
8
tests/kerkdienstgemist.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[main]
|
||||||
|
streaming_method = kerkdienstgemist
|
||||||
|
|
||||||
|
[kerk]
|
||||||
|
name = immanuel kapel
|
||||||
|
youtube_channel_id = UCud4rRtOf2e146HZWDfj6YA
|
||||||
|
kerkdienstgemist_id = 2112-Immanuelkapel
|
||||||
|
|
8
tests/youtube.ini
Normal file
8
tests/youtube.ini
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[main]
|
||||||
|
streaming_method = youtube
|
||||||
|
|
||||||
|
[kerk]
|
||||||
|
name = immanuel kapel
|
||||||
|
youtube_channel_id = UCud4rRtOf2e146HZWDfj6YA
|
||||||
|
kerkdienstgemist_id = 2112-Immanuelkapel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user