From 004d913520baff316ea51cab63a4effd589c1432 Mon Sep 17 00:00:00 2001 From: Eljakim Herrewijnen Date: Wed, 27 Jul 2022 22:00:43 +0200 Subject: [PATCH] Added support for streamlink and a waiting page when using the browser --- README.md | 3 +- live.html | 71 -------------------------------------------- notlive.html | 13 +++++++- streamer.py | 9 ++++-- streaming/youtube.py | 12 ++++++++ tests/teststream.ini | 8 +++++ 6 files changed, 40 insertions(+), 76 deletions(-) delete mode 100644 live.html create mode 100644 tests/teststream.ini diff --git a/README.md b/README.md index 5455a5a..e9f68ee 100644 --- a/README.md +++ b/README.md @@ -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. - +## 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 * Add fallback option for the streamer. For example: If youtube does not work, fall back to KDG \ No newline at end of file diff --git a/live.html b/live.html deleted file mode 100644 index c77aab6..0000000 --- a/live.html +++ /dev/null @@ -1,71 +0,0 @@ - - - Immanuelkapel - - - - - - - - - - - - - - - - - Kerkdienstgemist.nl - - - - - - - - - - - - - - - - -
-
- -
-
-
-
-
-
- - - -
-

De website werkt mogelijk niet goed

-

Uw browser is verouderd. Gebruik een andere browser voor een betere ervaring en beveiliging

- Kies andere browser - -

Website may not work properly

-

This browser is out of date. Use a different browser for a better experience and security

- Choose other browser - -
- - - - -
- - - - - diff --git a/notlive.html b/notlive.html index ade6c53..07ca1a4 100644 --- a/notlive.html +++ b/notlive.html @@ -3,7 +3,18 @@ Immanuelkapel + + -

Waiting to go live

+
+

Wachten totdat de stream live is

+
diff --git a/streamer.py b/streamer.py index 4570891..7dfb943 100644 --- a/streamer.py +++ b/streamer.py @@ -4,7 +4,7 @@ from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager - +import os from streaming.youtube import Web_Youtube class Streamer: @@ -12,7 +12,8 @@ class Streamer: self.config = ConfigParser() self.config.read(config_path) self.load_config_values() - self.setup_web_driver() + if self.streaming_method == "web": + self.setup_web_driver() def load_config_values(self): self.streaming_service = self.config.get('main', 'streaming_service').lower() @@ -40,7 +41,9 @@ class Streamer: def stream(self): 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: #Default to web self.stream_service.pre_load_actions(self.driver) diff --git a/streaming/youtube.py b/streaming/youtube.py index 5f90c06..2d3a3bd 100644 --- a/streaming/youtube.py +++ b/streaming/youtube.py @@ -25,6 +25,18 @@ class Web_Youtube(Web_StreamService): return True return False + def get_stream_url(self): + page = requests.get(self.livestream_url(), cookies={'CONSENT': 'YES+42'}) + data = page.content.decode() + offset = data.find('" in line: + break + line += data[offset] + offset += 1 + return line.split("href=")[-1][:-1] + def wait_until_live(self): while True: try: diff --git a/tests/teststream.ini b/tests/teststream.ini new file mode 100644 index 0000000..e163d63 --- /dev/null +++ b/tests/teststream.ini @@ -0,0 +1,8 @@ +[main] +streaming_method = video +streaming_service = youtube + +[kerk] +name = test stream +youtube_channel_id = UC9X6gGKDv2yhMoofoeS7-Gg +kerkdienstgemist_id = 2112-Immanuelkapel \ No newline at end of file