2022-07-27 16:18:18 +00:00
|
|
|
import requests
|
2022-05-29 10:29:31 +00:00
|
|
|
from streaming.base_stream import *
|
2022-07-27 16:18:18 +00:00
|
|
|
import os, time
|
2022-05-29 10:29:31 +00:00
|
|
|
|
|
|
|
ICHTHUSKERK_ID = "UCIh6v7QDfo8FBYAifTMrD3A"
|
|
|
|
IMMANUELKAPEL_ID = "UCud4rRtOf2e146HZWDfj6YA"
|
|
|
|
START_FULL_WINDOW = "?start=68" #Note, this is not full screen, but full window
|
|
|
|
|
2022-07-27 16:18:18 +00:00
|
|
|
class Web_Youtube(Web_StreamService):
|
2022-05-29 10:29:31 +00:00
|
|
|
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}"
|
|
|
|
|
2022-07-27 16:18:18 +00:00
|
|
|
def channel_url(self):
|
|
|
|
return f"https://www.youtube.com/channel/{self.id}"
|
|
|
|
|
2022-05-29 10:29:31 +00:00
|
|
|
def is_live(self):
|
2022-07-27 16:18:18 +00:00
|
|
|
#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
|
|
|
|
|
2022-07-27 20:00:43 +00:00
|
|
|
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]
|
|
|
|
|
2022-07-27 16:18:18 +00:00
|
|
|
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)
|
2022-05-29 10:29:31 +00:00
|
|
|
|
2022-07-27 16:18:18 +00:00
|
|
|
def pre_load_actions(self, driver):
|
|
|
|
driver.get(f"file:{os.getcwd()}/notlive.html")
|
|
|
|
self.wait_until_live()
|
2022-05-29 10:29:31 +00:00
|
|
|
|
|
|
|
def post_load_actions(self, driver):
|
|
|
|
self.bypass_cookies(driver)
|
2022-07-27 20:40:21 +00:00
|
|
|
self.double_click_fullscreen(driver)
|
2022-07-27 20:31:16 +00:00
|
|
|
|
|
|
|
def double_click_fullscreen(self, driver):
|
|
|
|
while True:
|
|
|
|
if len(driver.find_elements(by=By.XPATH, value='//*[@id="movie_player"]/div[1]/video')) > 0:
|
|
|
|
video = driver.find_elements(by=By.XPATH, value='//*[@id="movie_player"]/div[1]/video')[0]
|
|
|
|
break
|
2022-07-27 20:40:21 +00:00
|
|
|
action = ActionChains(driver)
|
2022-07-27 20:31:16 +00:00
|
|
|
action.double_click(video)
|
2022-07-27 20:40:21 +00:00
|
|
|
action.perform()
|
|
|
|
# action.send_keys("f")
|
2022-07-27 20:31:16 +00:00
|
|
|
# video.click();time.sleep(.1);video.click()
|
2022-05-29 10:29:31 +00:00
|
|
|
|
|
|
|
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)
|
2022-07-27 16:18:18 +00:00
|
|
|
accept_button.click()
|