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 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 channel_url(self): return f"https://www.youtube.com/channel/{self.id}" 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 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: 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) self.double_click_fullscreen(driver) 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 action = ActionChains(driver) action.double_click(video) action.perform() # action.send_keys("f") # video.click();time.sleep(.1);video.click() 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) accept_button.click()