Skip to content

Commit a46db68

Browse files
committed
Better mp4 bar
1 parent 8ccb178 commit a46db68

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

StreamingCommunity/Api/Site/animeunity/site.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Internal utilities
1111
from StreamingCommunity.Util.headers import get_userAgent
12-
from StreamingCommunity.Util.http_client import create_client, create_client_curl
12+
from StreamingCommunity.Util.http_client import create_client_curl
1313
from StreamingCommunity.Util.table import TVShowManager
1414
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance
1515

@@ -77,7 +77,7 @@ def title_search(query: str) -> int:
7777

7878
# First call: /livesearch
7979
try:
80-
response1 = create_client(headers=headers).post(f'{site_constant.FULL_URL}/livesearch', cookies=cookies, json={'title': query})
80+
response1 = create_client_curl(headers=headers).post(f'{site_constant.FULL_URL}/livesearch', cookies=cookies, data={'title': query})
8181
response1.raise_for_status()
8282
process_results(response1.json().get('records', []), seen_titles, media_search_manager, choices)
8383

@@ -98,7 +98,7 @@ def title_search(query: str) -> int:
9898
'dubbed': False,
9999
'season': False
100100
}
101-
response2 = create_client(headers=headers).post(f'{site_constant.FULL_URL}/archivio/get-animes', cookies=cookies, json=json_data)
101+
response2 = create_client_curl(headers=headers).post(f'{site_constant.FULL_URL}/archivio/get-animes', cookies=cookies, data=json_data)
102102
response2.raise_for_status()
103103
process_results(response2.json().get('records', []), seen_titles, media_search_manager, choices)
104104

StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Internal utilities
77
from StreamingCommunity.Util.headers import get_headers
8-
from StreamingCommunity.Util.http_client import create_client
8+
from StreamingCommunity.Util.http_client import create_client_curl
99
from StreamingCommunity.Api.Player.Helper.Vixcloud.util import EpisodeManager, Episode
1010

1111

@@ -52,7 +52,7 @@ def _fetch_all_episodes(self):
5252
"""
5353
try:
5454
# Get initial episode count
55-
response = create_client(headers=self.headers).get(f"{self.url}/info_api/{self.media_id}/")
55+
response = create_client_curl(headers=self.headers).get(f"{self.url}/info_api/{self.media_id}/")
5656
response.raise_for_status()
5757
initial_count = response.json()["episodes_count"]
5858

@@ -68,7 +68,7 @@ def _fetch_all_episodes(self):
6868
"end_range": end_range
6969
}
7070

71-
response = create_client(headers=self.headers).get(f"{self.url}/info_api/{self.media_id}/1", params=params)
71+
response = create_client_curl(headers=self.headers).get(f"{self.url}/info_api/{self.media_id}/1", params=params)
7272
response.raise_for_status()
7373

7474
chunk_episodes = response.json().get("episodes", [])

StreamingCommunity/Lib/Downloader/MP4/downloader.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def MP4_downloader(url: str, path: str, referer: str = None, headers_: dict = No
7676
- Single Ctrl+C: Completes download gracefully
7777
- Triple Ctrl+C: Saves partial download and exits
7878
"""
79+
url = url.strip()
7980
if TELEGRAM_BOT:
8081
bot = get_bot_instance()
8182
console.log("####")
@@ -134,20 +135,23 @@ def MP4_downloader(url: str, path: str, referer: str = None, headers_: dict = No
134135

135136
# Create progress bar with percentage instead of n_fmt/total_fmt
136137
console.print("[cyan]You can safely stop the download with [bold]Ctrl+c[bold] [cyan]")
138+
137139
progress_bar = tqdm(
138140
total=total,
139141
ascii='░▒█',
140142
bar_format=f"{Colors.YELLOW}MP4{Colors.CYAN} Downloading{Colors.WHITE}: "
141-
f"{Colors.RED}{{percentage:.1f}}% {Colors.MAGENTA}{{bar:40}} {Colors.WHITE}"
142-
f"{Colors.DARK_GRAY}[{Colors.YELLOW}{{elapsed}}{Colors.WHITE} < {Colors.CYAN}{{remaining}}{Colors.DARK_GRAY}] "
143-
f"{Colors.LIGHT_CYAN}{{rate_fmt}}",
143+
f"{Colors.MAGENTA}{{bar:40}} "
144+
f"{Colors.LIGHT_GREEN}{{n_fmt}}{Colors.WHITE}/{Colors.CYAN}{{total_fmt}}"
145+
f" {Colors.DARK_GRAY}[{Colors.YELLOW}{{elapsed}}{Colors.WHITE} < {Colors.CYAN}{{remaining}}{Colors.DARK_GRAY}]"
146+
f"{Colors.WHITE}{{postfix}} ",
144147
unit='B',
145148
unit_scale=True,
146149
unit_divisor=1024,
147150
mininterval=0.05,
148151
file=sys.stdout
149152
)
150-
153+
154+
start_time = time.time()
151155
downloaded = 0
152156
with open(temp_path, 'wb') as file, progress_bar as bar:
153157
try:
@@ -160,6 +164,14 @@ def MP4_downloader(url: str, path: str, referer: str = None, headers_: dict = No
160164
size = file.write(chunk)
161165
downloaded += size
162166
bar.update(size)
167+
168+
# Update postfix with speed and final size
169+
elapsed = time.time() - start_time
170+
if elapsed > 0:
171+
speed = downloaded / elapsed
172+
speed_str = internet_manager.format_transfer_speed(speed)
173+
postfix_str = f"{Colors.LIGHT_MAGENTA}@ {Colors.LIGHT_CYAN}{speed_str}"
174+
bar.set_postfix_str(postfix_str)
163175

164176
except KeyboardInterrupt:
165177
if not interrupt_handler.force_quit:

0 commit comments

Comments
 (0)