Youtube stream will be checked for live status now
This commit is contained in:
parent
eb68c52281
commit
6cc774aa7c
@ -1,5 +1,6 @@
|
|||||||
[main]
|
[main]
|
||||||
streaming_method = youtube
|
streaming_method = web
|
||||||
|
streaming_service = youtube
|
||||||
|
|
||||||
[kerk]
|
[kerk]
|
||||||
name = immanuel kapel
|
name = immanuel kapel
|
||||||
|
31
main.py
31
main.py
@ -9,33 +9,4 @@ if __name__ == "__main__":
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
streamer = Streamer(args.config)
|
streamer = Streamer(args.config)
|
||||||
streamer.stream()
|
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 Web_KerkOmroep
|
||||||
from streaming.kerkomroep import KerkOmroep
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver import ActionChains
|
|
||||||
from selenium.webdriver.chrome.service import Service
|
from selenium.webdriver.chrome.service import Service
|
||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
from webdriver_manager.chrome import ChromeDriverManager
|
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:
|
class Streamer:
|
||||||
def __init__(self, config_path="config.ini") -> None:
|
def __init__(self, config_path="config.ini") -> None:
|
||||||
@ -19,6 +15,7 @@ class Streamer:
|
|||||||
self.setup_web_driver()
|
self.setup_web_driver()
|
||||||
|
|
||||||
def load_config_values(self):
|
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.streaming_method = self.config.get('main', 'streaming_method').lower()
|
||||||
|
|
||||||
self.kerk_name = self.config.get('kerk', 'name')
|
self.kerk_name = self.config.get('kerk', 'name')
|
||||||
@ -26,11 +23,11 @@ class Streamer:
|
|||||||
self.kdg_id = self.config.get('kerk', 'kerkdienstgemist_id')
|
self.kdg_id = self.config.get('kerk', 'kerkdienstgemist_id')
|
||||||
|
|
||||||
#Setup streamer based on streaming_method
|
#Setup streamer based on streaming_method
|
||||||
if self.streaming_method == "kerkdienstgemist":
|
if self.streaming_service == "kerkdienstgemist":
|
||||||
self.stream_service = KerkOmroep(self.kdg_id)
|
self.stream_service = Web_KerkOmroep(self.kdg_id)
|
||||||
else:
|
else:
|
||||||
#Default to youtube
|
#Default to youtube
|
||||||
self.stream_service = Youtube(self.youtube_id)
|
self.stream_service = Web_Youtube(self.youtube_id)
|
||||||
|
|
||||||
def setup_web_driver(self):
|
def setup_web_driver(self):
|
||||||
self.options = Options()
|
self.options = Options()
|
||||||
@ -42,5 +39,11 @@ class Streamer:
|
|||||||
self.driver.timeouts.implicit_wait = 3
|
self.driver.timeouts.implicit_wait = 3
|
||||||
|
|
||||||
def stream(self):
|
def stream(self):
|
||||||
self.driver.get(self.stream_service.livestream_url())
|
if self.streaming_method == "video":
|
||||||
self.stream_service.post_load_actions(self.driver)
|
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
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class StreamService:
|
class Web_StreamService:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -19,6 +19,9 @@ class StreamService:
|
|||||||
|
|
||||||
def click_video_play(self):
|
def click_video_play(self):
|
||||||
raise NotImplemented()
|
raise NotImplemented()
|
||||||
|
|
||||||
|
def pre_load_actions(self):
|
||||||
|
raise NotImplemented()
|
||||||
|
|
||||||
def post_load_actions(self, driver):
|
def post_load_actions(self, driver):
|
||||||
raise NotImplemented()
|
raise NotImplemented()
|
@ -7,7 +7,7 @@ ICHTHUSKERK_URL = "https://kerkdienstgemist.nl/stations/2110-Ichthuskerk-Ridderk
|
|||||||
LIVESTREAM_URL = "events/live"
|
LIVESTREAM_URL = "events/live"
|
||||||
XPATH= "/html/body/div[5]/div/article/div/div/div[1]/div[1]/div/div[2]"
|
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:
|
def __init__(self, kerk_id=IMMANUELKAPEL_URL) -> None:
|
||||||
self.kerk_id = kerk_id #URL that points to the church inside the kerkomroep environment
|
self.kerk_id = kerk_id #URL that points to the church inside the kerkomroep environment
|
||||||
pass
|
pass
|
||||||
@ -32,6 +32,9 @@ class KerkOmroep(StreamService):
|
|||||||
pass
|
pass
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
button.click()
|
button.click()
|
||||||
|
|
||||||
|
def pre_load_actions(self, driver):
|
||||||
|
pass
|
||||||
|
|
||||||
def post_load_actions(self, driver):
|
def post_load_actions(self, driver):
|
||||||
self.click_video_play(driver)
|
self.click_video_play(driver)
|
||||||
|
@ -1,21 +1,42 @@
|
|||||||
|
from fcntl import F_SEAL_SEAL
|
||||||
|
import requests
|
||||||
from streaming.base_stream import *
|
from streaming.base_stream import *
|
||||||
|
import os, time
|
||||||
|
|
||||||
ICHTHUSKERK_ID = "UCIh6v7QDfo8FBYAifTMrD3A"
|
ICHTHUSKERK_ID = "UCIh6v7QDfo8FBYAifTMrD3A"
|
||||||
IMMANUELKAPEL_ID = "UCud4rRtOf2e146HZWDfj6YA"
|
IMMANUELKAPEL_ID = "UCud4rRtOf2e146HZWDfj6YA"
|
||||||
START_FULL_WINDOW = "?start=68" #Note, this is not full screen, but full window
|
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:
|
def __init__(self, id=IMMANUELKAPEL_ID) -> None:
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
def livestream_url(self):
|
def livestream_url(self):
|
||||||
return f"https://www.youtube.com/channel/{self.id}/live{START_FULL_WINDOW}"
|
return f"https://www.youtube.com/channel/{self.id}/live{START_FULL_WINDOW}"
|
||||||
|
|
||||||
def is_live(self):
|
def channel_url(self):
|
||||||
return True
|
return f"https://www.youtube.com/channel/{self.id}"
|
||||||
|
|
||||||
def post_load_actions(self):
|
def is_live(self):
|
||||||
return
|
#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):
|
def post_load_actions(self, driver):
|
||||||
self.bypass_cookies(driver)
|
self.bypass_cookies(driver)
|
||||||
@ -30,5 +51,4 @@ class Youtube(StreamService):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
accept_button.click()
|
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]
|
[main]
|
||||||
streaming_method = kerkdienstgemist
|
streaming_method = web
|
||||||
|
streaming_service = kerkdienstgemist
|
||||||
|
|
||||||
[kerk]
|
[kerk]
|
||||||
name = immanuel kapel
|
name = immanuel kapel
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
[main]
|
[main]
|
||||||
streaming_method = youtube
|
streaming_method = video
|
||||||
|
streaming_service = youtube
|
||||||
|
|
||||||
[kerk]
|
[kerk]
|
||||||
name = immanuel kapel
|
name = immanuel kapel
|
||||||
|
Loading…
Reference in New Issue
Block a user