Youtube stream will be checked for live status now
This commit is contained in:
parent
eb68c52281
commit
6cc774aa7c
@ -1,5 +1,6 @@
|
||||
[main]
|
||||
streaming_method = youtube
|
||||
streaming_method = web
|
||||
streaming_service = youtube
|
||||
|
||||
[kerk]
|
||||
name = immanuel kapel
|
||||
|
29
main.py
29
main.py
@ -10,32 +10,3 @@ if __name__ == "__main__":
|
||||
|
||||
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()
|
9
notlive.html
Normal file
9
notlive.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="nl-NL">
|
||||
<head>
|
||||
<title>Immanuelkapel</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Waiting to go live</h1>
|
||||
</body>
|
||||
</html>
|
25
streamer.py
25
streamer.py
@ -1,15 +1,11 @@
|
||||
import selenium
|
||||
from streaming.kerkomroep import KerkOmroep
|
||||
from streaming.kerkomroep import Web_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
|
||||
from streaming.youtube import Web_Youtube
|
||||
|
||||
class Streamer:
|
||||
def __init__(self, config_path="config.ini") -> None:
|
||||
@ -19,6 +15,7 @@ class Streamer:
|
||||
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')
|
||||
@ -26,11 +23,11 @@ class Streamer:
|
||||
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)
|
||||
if self.streaming_service == "kerkdienstgemist":
|
||||
self.stream_service = Web_KerkOmroep(self.kdg_id)
|
||||
else:
|
||||
#Default to youtube
|
||||
self.stream_service = Youtube(self.youtube_id)
|
||||
self.stream_service = Web_Youtube(self.youtube_id)
|
||||
|
||||
def setup_web_driver(self):
|
||||
self.options = Options()
|
||||
@ -42,5 +39,11 @@ class Streamer:
|
||||
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)
|
||||
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)
|
||||
|
||||
|
@ -4,7 +4,7 @@ from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
import time
|
||||
|
||||
class StreamService:
|
||||
class Web_StreamService:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
@ -20,5 +20,8 @@ class StreamService:
|
||||
def click_video_play(self):
|
||||
raise NotImplemented()
|
||||
|
||||
def pre_load_actions(self):
|
||||
raise NotImplemented()
|
||||
|
||||
def post_load_actions(self, driver):
|
||||
raise NotImplemented()
|
@ -7,7 +7,7 @@ ICHTHUSKERK_URL = "https://kerkdienstgemist.nl/stations/2110-Ichthuskerk-Ridderk
|
||||
LIVESTREAM_URL = "events/live"
|
||||
XPATH= "/html/body/div[5]/div/article/div/div/div[1]/div[1]/div/div[2]"
|
||||
|
||||
class KerkOmroep(StreamService):
|
||||
class Web_KerkOmroep(Web_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
|
||||
@ -33,5 +33,8 @@ class KerkOmroep(StreamService):
|
||||
time.sleep(1)
|
||||
button.click()
|
||||
|
||||
def pre_load_actions(self, driver):
|
||||
pass
|
||||
|
||||
def post_load_actions(self, driver):
|
||||
self.click_video_play(driver)
|
||||
|
@ -1,21 +1,42 @@
|
||||
from fcntl import F_SEAL_SEAL
|
||||
import requests
|
||||
from streaming.base_stream import *
|
||||
import os, time
|
||||
|
||||
ICHTHUSKERK_ID = "UCIh6v7QDfo8FBYAifTMrD3A"
|
||||
IMMANUELKAPEL_ID = "UCud4rRtOf2e146HZWDfj6YA"
|
||||
START_FULL_WINDOW = "?start=68" #Note, this is not full screen, but full window
|
||||
|
||||
class Youtube(StreamService):
|
||||
class Web_Youtube(Web_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 channel_url(self):
|
||||
return f"https://www.youtube.com/channel/{self.id}"
|
||||
|
||||
def post_load_actions(self):
|
||||
return
|
||||
def is_live(self):
|
||||
#https://github.com/bogeta11040/if-youtube-channel-live
|
||||
page = requests.get(f"https://www.youtube.com/channel/{self.id}", cookies={'CONSENT': 'YES+42'})
|
||||
data = page.content.decode()
|
||||
if "hqdefault_live.jpg" in data:
|
||||
return True
|
||||
return False
|
||||
|
||||
def wait_until_live(self):
|
||||
while True:
|
||||
try:
|
||||
if self.is_live():
|
||||
break
|
||||
except:
|
||||
print("Failed to get live status of stream!")
|
||||
time.sleep(10)
|
||||
|
||||
def pre_load_actions(self, driver):
|
||||
driver.get(f"file:{os.getcwd()}/notlive.html")
|
||||
self.wait_until_live()
|
||||
|
||||
def post_load_actions(self, driver):
|
||||
self.bypass_cookies(driver)
|
||||
@ -31,4 +52,3 @@ class Youtube(StreamService):
|
||||
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()
|
@ -1,5 +1,6 @@
|
||||
[main]
|
||||
streaming_method = kerkdienstgemist
|
||||
streaming_method = web
|
||||
streaming_service = kerkdienstgemist
|
||||
|
||||
[kerk]
|
||||
name = immanuel kapel
|
||||
|
@ -1,5 +1,6 @@
|
||||
[main]
|
||||
streaming_method = youtube
|
||||
streaming_method = video
|
||||
streaming_service = youtube
|
||||
|
||||
[kerk]
|
||||
name = immanuel kapel
|
||||
|
Loading…
Reference in New Issue
Block a user