Added support for streamlink and a waiting page when using the browser

This commit is contained in:
Eljakim Herrewijnen 2022-07-27 22:00:43 +02:00
parent 6cc774aa7c
commit 004d913520
6 changed files with 40 additions and 76 deletions

View File

@ -30,7 +30,8 @@ Next you will need to tell the streamer to use this service when specified in th
``` ```
You will also need to specify this service your **config** file. You will also need to specify this service your **config** file.
## Streamlink
The stream for youtube can also be started using streamlink. This is less resource intensive but currently there is no way of showing that no stream is active and it might be less stable then the browser.
## Todo ## Todo
* Add fallback option for the streamer. For example: If youtube does not work, fall back to KDG * Add fallback option for the streamer. For example: If youtube does not work, fall back to KDG

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,18 @@
<head> <head>
<title>Immanuelkapel</title> <title>Immanuelkapel</title>
</head> </head>
<style>
.text_container {
margin: auto;
width: 60%;
padding: 10px;
text-align: center;
}
</style>
<body> <body>
<h1>Waiting to go live</h1> <div class="text_container">
<h1>Wachten totdat de stream live is</h1>
</div>
</body> </body>
</html> </html>

View File

@ -4,7 +4,7 @@ from selenium import webdriver
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
import os
from streaming.youtube import Web_Youtube from streaming.youtube import Web_Youtube
class Streamer: class Streamer:
@ -12,7 +12,8 @@ class Streamer:
self.config = ConfigParser() self.config = ConfigParser()
self.config.read(config_path) self.config.read(config_path)
self.load_config_values() self.load_config_values()
self.setup_web_driver() if self.streaming_method == "web":
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_service = self.config.get('main', 'streaming_service').lower()
@ -40,7 +41,9 @@ class Streamer:
def stream(self): def stream(self):
if self.streaming_method == "video": if self.streaming_method == "video":
self.stream_service.pre_load_actions(self.driver) if self.streaming_service != "youtube":
raise NotImplementedError()
os.system(f"streamlink {self.stream_service.get_stream_url()} best")
else: else:
#Default to web #Default to web
self.stream_service.pre_load_actions(self.driver) self.stream_service.pre_load_actions(self.driver)

View File

@ -25,6 +25,18 @@ class Web_Youtube(Web_StreamService):
return True return True
return False return False
def get_stream_url(self):
page = requests.get(self.livestream_url(), cookies={'CONSENT': 'YES+42'})
data = page.content.decode()
offset = data.find('<link rel="canonical" href="https://www.youtube.com/')
line = ""
while True:
if ">" in line:
break
line += data[offset]
offset += 1
return line.split("href=")[-1][:-1]
def wait_until_live(self): def wait_until_live(self):
while True: while True:
try: try:

8
tests/teststream.ini Normal file
View File

@ -0,0 +1,8 @@
[main]
streaming_method = video
streaming_service = youtube
[kerk]
name = test stream
youtube_channel_id = UC9X6gGKDv2yhMoofoeS7-Gg
kerkdienstgemist_id = 2112-Immanuelkapel