Skip to content

Commit

Permalink
12.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nichind committed Dec 16, 2024
1 parent 28cf6c2 commit 5acadd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
35 changes: 32 additions & 3 deletions pybalt/cobalt.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ async def get_instance(self):
instances = await resp.json()
good_instances = []
for instance in instances:
if int(instance["version"].split(".")[0]) < 10:
if (
"version" not in instance
or int(instance["version"].split(".")[0]) < 10
):
continue
dead_services = sum(
1
Expand Down Expand Up @@ -317,7 +320,11 @@ async def get(
}
if audio_format:
json["audioFormat"] = audio_format
async with cs.post(self.api_instance, json=json) as resp:
async with cs.post(
("https://" if "http" not in self.api_instance else "")
+ self.api_instance,
json=json, timeout=12,
) as resp:
json = await resp.json()
if "error" in json:
match json["error"]["code"].split(".")[2]:
Expand Down Expand Up @@ -384,6 +391,7 @@ async def get(
)
case "fetch":
self.skipped_instances.append(self.api_instance)
print(json)
print(
tl("FETCH_ERROR").format(
url=url if len(url) < 40 else url[:40] + "...",
Expand Down Expand Up @@ -509,9 +517,9 @@ def shorten(s: str, additional_len: int = 0) -> str:
last_update = 0
last_speed_update = 0
downloaded_since_last = 0
print(f"\033[97m{filename}\033[0m", flush=True)
max_print_length, _ = get_terminal_size()
async with session.get(file.tunnel) as response:
print(f"\033[97m{filename}\033[0m", flush=True)
result_path = path.join(path_folder, f'"{filename}"')
while True:
chunk = await response.content.read(1024 * 1024)
Expand Down Expand Up @@ -559,6 +567,27 @@ def shorten(s: str, additional_len: int = 0) -> str:
elapsed_time = time() - start_time
info = f"[{round(total_size / 1024 / 1024, 2)}Mb \u2015 {round(elapsed_time, 2)}s] \u2713"
print_line = shorten(result_path, additional_len=len(info))
if total_size < 1024:
instance = await self.get_instance()
self.skipped_instances += [instance]
print(tl("ZERO_BYTE_FILE").format(instance=instance))
if len(self.skipped_instances) > 1 and self.skipped_instances[-1] == self.skipped_instances[-2]:
print(tl("ZERO_BYTE_ALL"))
return
return await download(
url,
quality,
filename,
path_folder,
download_mode,
filename_style,
audio_format,
youtube_video_codec,
playlist,
file,
show,
play,
)
print(
"\r",
print_line
Expand Down
2 changes: 2 additions & 0 deletions pybalt/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ UPDATE_ARGUMENT=Check for updates
VERSION=pybalt {}
NO_URL_PROVIDED=No URLs provided\nExpected media url, path to file with list of URLs or youtube playlist link\nExample: cobalt 'https://youtube.com/watch?...' -s
SUCCESS=\033[92mEverything Done!\033[0m Thanks for using pybalt! Leave a star on GitHub: https://github.com/nichind/pybalt
ZERO_BYTE_FILE={instance} returned 0 bytes, skipping and trying next instance
ZERO_BYTE_ALL=All instances returned 0 bytes, aborting. Please try again later, that's an issue with cobalt, not pybalt.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():

setup(
name="pybalt",
version="2024.12.6",
version="2024.12.7",
author="nichind",
author_email="[email protected]",
description="Download mediafiles from YouTube, Twitter (X), Instagram, Reddit & more. CLI & python module for @imputnet's cobalt processing instance api.",
Expand Down

0 comments on commit 5acadd8

Please sign in to comment.