fix: typo
This commit is contained in:
parent
4c5606c409
commit
7b0f9ea857
@ -25,7 +25,7 @@ class Connection:
|
|||||||
accepted_response_codes: Set[int] = None,
|
accepted_response_codes: Set[int] = None,
|
||||||
semantic_not_found: bool = True,
|
semantic_not_found: bool = True,
|
||||||
sleep_after_404: float = 0.0,
|
sleep_after_404: float = 0.0,
|
||||||
hearthbeat_interval = 0,
|
heartbeat_interval = 0,
|
||||||
):
|
):
|
||||||
if proxies is None:
|
if proxies is None:
|
||||||
proxies = main_settings["proxies"]
|
proxies = main_settings["proxies"]
|
||||||
@ -50,39 +50,39 @@ class Connection:
|
|||||||
|
|
||||||
self.session_is_occupied: bool = False
|
self.session_is_occupied: bool = False
|
||||||
|
|
||||||
self.hearthbeat_thread = None
|
self.heartbeat_thread = None
|
||||||
self.hearthbeat_interval = hearthbeat_interval
|
self.heartbeat_interval = heartbeat_interval
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_agent(self) -> str:
|
def user_agent(self) -> str:
|
||||||
return self.session.headers.get("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36")
|
return self.session.headers.get("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36")
|
||||||
|
|
||||||
|
|
||||||
def start_hearthbeat(self):
|
def start_heartbeat(self):
|
||||||
if self.hearthbeat_interval <= 0:
|
if self.heartbeat_interval <= 0:
|
||||||
self.LOGGER.warning(f"Can't start a hearthbeat with {self.hearthbeat_interval}s in between.")
|
self.LOGGER.warning(f"Can't start a heartbeat with {self.heartbeat_interval}s in between.")
|
||||||
|
|
||||||
self.hearthbeat_thread = threading.Thread(target=self._hearthbeat_loop, args=(self.hearthbeat_interval, ), daemon=True)
|
self.heartbeat_thread = threading.Thread(target=self._heartbeat_loop, args=(self.heartbeat_interval, ), daemon=True)
|
||||||
self.hearthbeat_thread.start()
|
self.heartbeat_thread.start()
|
||||||
|
|
||||||
def hearthbeat_failed(self):
|
def heartbeat_failed(self):
|
||||||
self.LOGGER.warning(f"I just died... (The hearthbeat failed)")
|
self.LOGGER.warning(f"I just died... (The heartbeat failed)")
|
||||||
|
|
||||||
|
|
||||||
def hearthbeat(self):
|
def heartbeat(self):
|
||||||
# Your code to send heartbeat requests goes here
|
# Your code to send heartbeat requests goes here
|
||||||
print("the hearth is beating, but it needs to be implemented ;-;\nFuck youuuu for setting hearthbeat in the constructor to true, but not implementing the method Connection.hearbeat()")
|
print("the hearth is beating, but it needs to be implemented ;-;\nFuck youuuu for setting heartbeat in the constructor to true, but not implementing the method Connection.hearbeat()")
|
||||||
|
|
||||||
def _hearthbeat_loop(self, interval: float):
|
def _heartbeat_loop(self, interval: float):
|
||||||
def hearthbeat_wrapper():
|
def heartbeat_wrapper():
|
||||||
self.session_is_occupied = True
|
self.session_is_occupied = True
|
||||||
self.LOGGER.debug(f"I am living. (sending a hearthbeat)")
|
self.LOGGER.debug(f"I am living. (sending a heartbeat)")
|
||||||
self.hearthbeat()
|
self.heartbeat()
|
||||||
self.LOGGER.debug(f"finished the hearthbeat")
|
self.LOGGER.debug(f"finished the heartbeat")
|
||||||
self.session_is_occupied = False
|
self.session_is_occupied = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
hearthbeat_wrapper()
|
heartbeat_wrapper()
|
||||||
time.sleep(interval)
|
time.sleep(interval)
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ class Connection:
|
|||||||
refer_from_origin: bool = True,
|
refer_from_origin: bool = True,
|
||||||
raw_url: bool = False,
|
raw_url: bool = False,
|
||||||
sleep_after_404: float = None,
|
sleep_after_404: float = None,
|
||||||
is_hearthbeat: bool = False,
|
is_heartbeat: bool = False,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> Optional[requests.Response]:
|
) -> Optional[requests.Response]:
|
||||||
if sleep_after_404 is None:
|
if sleep_after_404 is None:
|
||||||
@ -153,9 +153,9 @@ class Connection:
|
|||||||
|
|
||||||
connection_failed = False
|
connection_failed = False
|
||||||
try:
|
try:
|
||||||
if self.session_is_occupied and not is_hearthbeat:
|
if self.session_is_occupied and not is_heartbeat:
|
||||||
self.LOGGER.info(f"Waiting for the hearthbeat to finish.")
|
self.LOGGER.info(f"Waiting for the heartbeat to finish.")
|
||||||
while self.session_is_occupied and not is_hearthbeat:
|
while self.session_is_occupied and not is_heartbeat:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
r: requests.Response = request(request_url, timeout=timeout, headers=headers, **kwargs)
|
r: requests.Response = request(request_url, timeout=timeout, headers=headers, **kwargs)
|
||||||
@ -184,6 +184,9 @@ class Connection:
|
|||||||
|
|
||||||
self.rotate()
|
self.rotate()
|
||||||
|
|
||||||
|
if self.heartbeat_interval > 0 and self.heartbeat_thread is None:
|
||||||
|
self.start_heartbeat()
|
||||||
|
|
||||||
return self._request(
|
return self._request(
|
||||||
request=request,
|
request=request,
|
||||||
try_count=try_count+1,
|
try_count=try_count+1,
|
||||||
@ -192,7 +195,7 @@ class Connection:
|
|||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
sleep_after_404=sleep_after_404,
|
sleep_after_404=sleep_after_404,
|
||||||
is_hearthbeat=is_hearthbeat,
|
is_heartbeat=is_heartbeat,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import re
|
|||||||
|
|
||||||
from ...utils.exception.config import SettingValueError
|
from ...utils.exception.config import SettingValueError
|
||||||
from ...utils.config import main_settings, youtube_settings, logging_settings
|
from ...utils.config import main_settings, youtube_settings, logging_settings
|
||||||
from ...utils.shared import DEBUG, DEBUG_YOUTUBE_INITILIZING
|
from ...utils.shared import DEBUG, DEBUG_YOUTUBE_INITIALIZING
|
||||||
from ...utils.functions import get_current_millis
|
from ...utils.functions import get_current_millis
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
from ...utils.debug_utils import dump_to_file
|
from ...utils.debug_utils import dump_to_file
|
||||||
@ -37,7 +37,7 @@ def get_youtube_url(path: str = "", params: str = "", query: str = "", fragment:
|
|||||||
|
|
||||||
class YoutubeMusicConnection(Connection):
|
class YoutubeMusicConnection(Connection):
|
||||||
"""
|
"""
|
||||||
===Hearthbeat=timings=for=YOUTUBEMUSIC===
|
===heartbeat=timings=for=YOUTUBEMUSIC===
|
||||||
96.27
|
96.27
|
||||||
98.16
|
98.16
|
||||||
100.04
|
100.04
|
||||||
@ -51,7 +51,7 @@ class YoutubeMusicConnection(Connection):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
host="https://music.youtube.com/",
|
host="https://music.youtube.com/",
|
||||||
logger=logger,
|
logger=logger,
|
||||||
hearthbeat_interval=113.25,
|
heartbeat_interval=113.25,
|
||||||
header_values={
|
header_values={
|
||||||
"Accept-Language": accept_language
|
"Accept-Language": accept_language
|
||||||
}
|
}
|
||||||
@ -65,12 +65,12 @@ class YoutubeMusicConnection(Connection):
|
|||||||
value=cookie_value,
|
value=cookie_value,
|
||||||
path='/', domain='.youtube.com'
|
path='/', domain='.youtube.com'
|
||||||
)
|
)
|
||||||
# self.start_hearthbeat()
|
# self.start_heartbeat()
|
||||||
|
|
||||||
def hearthbeat(self):
|
def heartbeat(self):
|
||||||
r = self.get("https://music.youtube.com/verify_session", is_hearthbeat=True)
|
r = self.get("https://music.youtube.com/verify_session", is_heartbeat=True)
|
||||||
if r is None:
|
if r is None:
|
||||||
self.hearthbeat_failed()
|
self.heartbeat_failed()
|
||||||
|
|
||||||
string = r.content.decode("utf-8")
|
string = r.content.decode("utf-8")
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ class YoutubeMusicConnection(Connection):
|
|||||||
success: bool = data["success"]
|
success: bool = data["success"]
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
self.hearthbeat_failed()
|
self.heartbeat_failed()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -108,7 +108,7 @@ class YoutubeMusic(SuperYouTube):
|
|||||||
|
|
||||||
self.start_millis = get_current_millis()
|
self.start_millis = get_current_millis()
|
||||||
|
|
||||||
if self.credentials.api_key == "" or DEBUG_YOUTUBE_INITILIZING:
|
if self.credentials.api_key == "" or DEBUG_YOUTUBE_INITIALIZING:
|
||||||
self._fetch_from_main_page()
|
self._fetch_from_main_page()
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -3,7 +3,7 @@ import random
|
|||||||
from .config import main_settings
|
from .config import main_settings
|
||||||
|
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
DEBUG_YOUTUBE_INITILIZING = DEBUG and False
|
DEBUG_YOUTUBE_INITIALIZING = DEBUG and False
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("DEBUG ACTIVE")
|
print("DEBUG ACTIVE")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user