Skip to content

Commit e04baaf

Browse files
committed
Code test bugfixes
1 parent 685afb4 commit e04baaf

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

src/rumchat_actor/__init__.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def __init__(self, init_message = "Hello, Rumble!", ignore_users = ["TheRumbleBo
146146

147147
first_time = False
148148

149+
self.chat.clear_mailbox()
150+
149151
#Ignore these users when processing messages
150152
self.ignore_users = ignore_users
151153

@@ -161,25 +163,21 @@ def __init__(self, init_message = "Hello, Rumble!", ignore_users = ["TheRumbleBo
161163
#Action to be taken when raids occur
162164
self.__raid_action = print
163165

164-
#Time that the last message we sent was sent
165-
self.last_message_send_time = 0
166166

167167
#Loop condition of the mainloop() and sender_loop() methods
168168
self.keep_running = True
169169

170-
#thread to send messages at timed intervals
171-
self.sender_thread = threading.Thread(target = self._sender_loop, daemon = True)
172-
self.sender_thread.start()
173-
174170
#Send an initialization message to get wether we are moderator or not
175-
self.send_message(init_message)
171+
_, user = self.__send_message(static.Message.bot_prefix + init_message)
172+
assert utils.is_staff(user), \
173+
"Actor cannot function without being channel staff"
176174

177-
#Wait until we get that message
178-
while (m := self.chat.get_message()).user.username != self.username:
179-
pass
175+
#Time that the last message we sent was sent
176+
self.last_message_send_time = time.time()
180177

181-
assert utils.is_staff(m.user), \
182-
"Actor cannot function without being channel staff"
178+
#thread to send messages at timed intervals
179+
self.sender_thread = threading.Thread(target = self._sender_loop, daemon = True)
180+
self.sender_thread.start()
183181

184182
#Functions that are to be called on each message,
185183
#must return False if the message was deleted
@@ -292,7 +290,7 @@ def __send_message(self, text):
292290

293291
self.sent_messages.append(text)
294292
self.last_message_send_time = time.time()
295-
self.chat.send_message(text, channel_id = None) #TODO send as other channels
293+
return self.chat.send_message(text, channel_id = None) #TODO send as other channels
296294

297295
@property
298296
def delete_message(self):

src/rumchat_actor/commands.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import time
1414
import threading
1515
from tkinter import filedialog, Tk
16-
from cocorum.static.Delays import request_timeout as DEFAULT_TIMEOUT
1716
from moviepy.editor import VideoFileClip, concatenate_videoclips
1817
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
1918
import pyautogui
@@ -306,7 +305,7 @@ def get_ts_list(self, quality):
306305
assert self.ts_url_start and self.m3u8_filename, \
307306
"Must have the TS URL start and the m3u8 filename before this runs"
308307
m3u8 = requests.get(self.ts_url_start.format(quality = quality) + \
309-
self.m3u8_filename, timeout = DEFAULT_TIMEOUT).text
308+
self.m3u8_filename, timeout = static.REQUEST_TIMEOUT).text
310309
return [line for line in m3u8.splitlines() if not line.startswith("#")]
311310

312311
def record_loop(self):
@@ -315,7 +314,7 @@ def record_loop(self):
315314
#Get the base URL for the wualities listing
316315
m3u8_qualities_url = static.URI.m3u8_qualities_list.format(stream_id_b36 = self.actor.stream_id_b36)
317316

318-
m3u8_qualities_raw = requests.get(m3u8_qualities_url, timeout = DEFAULT_TIMEOUT).text
317+
m3u8_qualities_raw = requests.get(m3u8_qualities_url, timeout = static.REQUEST_TIMEOUT).text
319318

320319
m3u8_quality_urls_all = [line for line in m3u8_qualities_raw.splitlines() if not line.startswith("#")]
321320
ts_url_default = m3u8_quality_urls_all[-1]
@@ -366,7 +365,7 @@ def record_loop(self):
366365
#Save the unsaved TS chunks to temporary files
367366
for ts_name in new_ts_list:
368367
try:
369-
data = requests.get(self.ts_url_start.format(quality = self.use_quality) + ts_name, timeout = DEFAULT_TIMEOUT).content
368+
data = requests.get(self.ts_url_start.format(quality = self.use_quality) + ts_name, timeout = static.REQUEST_TIMEOUT).content
370369
except (AttributeError, requests.exceptions.ReadTimeout): #The request failed or has no content
371370
print("Failed to save ", ts_name)
372371
continue
@@ -395,10 +394,10 @@ def get_quality_info(self):
395394
for _ in range(static.Clip.Download.speed_test_iter):
396395
r1 = None
397396
try:
398-
r1 = requests.get(self.ts_url_start.format(quality = quality) + self.m3u8_filename, timeout = DEFAULT_TIMEOUT)
397+
r1 = requests.get(self.ts_url_start.format(quality = quality) + self.m3u8_filename, timeout = static.REQUEST_TIMEOUT)
399398
except requests.exceptions.ReadTimeout:
400399
print("Timeout for m3u8 playlist download")
401-
download_times.append(DEFAULT_TIMEOUT + 1)
400+
download_times.append(static.REQUEST_TIMEOUT + 1)
402401
continue
403402

404403
if r1.status_code == 404:
@@ -411,10 +410,10 @@ def get_quality_info(self):
411410
start_time = time.time()
412411
r2 = None
413412
try:
414-
r2 = requests.get(self.ts_url_start.format(quality = quality) + ts_chunk_names[-1], timeout = DEFAULT_TIMEOUT)
413+
r2 = requests.get(self.ts_url_start.format(quality = quality) + ts_chunk_names[-1], timeout = static.REQUEST_TIMEOUT)
415414
except requests.exceptions.ReadTimeout:
416415
print("Timeout for TS chunk download")
417-
download_times.append(DEFAULT_TIMEOUT + 1)
416+
download_times.append(static.REQUEST_TIMEOUT + 1)
418417
continue
419418
if r2.status_code != 200 or not r2.content:
420419
print("TS chunk download unsuccessful:", r2.status_code)
@@ -511,7 +510,7 @@ def form_ts_into_clip(self, filename, use_ts):
511510
tempfiles = []
512511
for ts_name in use_ts:
513512
try:
514-
data = requests.get(self.ts_url_start.format(quality = self.use_quality) + ts_name, timeout = DEFAULT_TIMEOUT).content
513+
data = requests.get(self.ts_url_start.format(quality = self.use_quality) + ts_name, timeout = static.REQUEST_TIMEOUT).content
515514
if not data:
516515
raise ValueError
517516
except (ValueError, requests.exceptions.ReadTimeout): #The request failed or has no content

src/rumchat_actor/static.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
S.D.G.
66
"""
77

8-
from cocorum.localvars import RUMBLE_BASE_URL
8+
from cocorum import static as cstatic
9+
10+
REQUEST_TIMEOUT = cstatic.Delays.request_timeout
911

1012
class Driver:
1113
"""For the Selenium WebDriver"""
@@ -52,19 +54,20 @@ class Message:
5254
class URI:
5355
"""Uniform Resource Identifiers"""
5456

55-
rumble_base = RUMBLE_BASE_URL
57+
#Rumble base URL
58+
rumble_base = cstatic.URI.rumble_base
5659

5760
#Popout chat url. Format with stream_id_b10
58-
chat_popout = RUMBLE_BASE_URL + "/chat/popup/{stream_id_b10}"
61+
chat_popout = rumble_base + "/chat/popup/{stream_id_b10}"
5962

6063
#Rumble user URL. Format with username
61-
user_page = RUMBLE_BASE_URL + "/user/{username}"
64+
user_page = rumble_base + "/user/{username}"
6265

6366
#Rumble channel URL. Format with channel_name
64-
channel_page = RUMBLE_BASE_URL + "/c/{channel_name}"
67+
channel_page = rumble_base + "/c/{channel_name}"
6568

6669
#URL of upload page at Rumble
67-
upload_page = RUMBLE_BASE_URL + "/upload.php"
70+
upload_page = rumble_base + "/upload.php"
6871

6972
#M3U8 qualities list URL. Format with base 36 stream ID
7073
m3u8_qualities_list = "https://rumble.com/live-hls-dvr/{stream_id_b36}/playlist.m3u8"

src/rumchat_actor/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import os
88
from cocorum.utils import *
9+
import selenium
10+
from selenium.webdriver.common.by import By
911
from . import static
1012

1113
def is_staff(user):
@@ -20,3 +22,29 @@ def get_safe_filename(clip_save_path, filename, extension = static.Clip.save_ext
2022
increment += 1
2123
safe_filename = filename + f"({increment})"
2224
return safe_filename
25+
26+
def close_premium_banner(driver):
27+
"""If the premium banner is visible in a driver, close it"""
28+
print("Looking to close Premium banner")
29+
try:
30+
close_button = driver.find_element(
31+
By.CSS_SELECTOR,
32+
"[data-js='premium-popup__close-button'][aria-label='Close']",
33+
)
34+
print("Close button found.")
35+
36+
except selenium.common.exceptions.NoSuchElementException:
37+
print("Close button not present, premium banner presumed already closed.")
38+
return
39+
40+
print("Egg timer for premium banner to display")
41+
time.sleep(static.Driver.premium_banner_delay)
42+
43+
try:
44+
close_button.click()
45+
print("Clicked close button. Egg timer for banner to hide")
46+
time.sleep(static.Driver.premium_banner_delay)
47+
print("Premium banner closed.")
48+
except selenium.common.exceptions.WebDriverException as e:
49+
print(e)
50+
print("Close button not clickable after wait, premium banner presumed already closed.")

0 commit comments

Comments
 (0)