Skip to content

Commit

Permalink
fix: not use async in both uploading and downloading (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tohrusky authored Dec 22, 2024
1 parent fd83da1 commit 7304846
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
30 changes: 21 additions & 9 deletions animepipeline/encode/finalrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,24 @@ async def download_completed_task(self, video_key: str, save_path: Union[str, Pa

get_task_progress_response = await self._get_task_progress(GetTaskProgressRequest(video_key=video_key))

response = await self.client.get(
url=get_task_progress_response.data.encode_url, # type: ignore
timeout=60 * 60,
)
if response.status_code != 200:
raise IOError(f"Error downloading file: {response.text}")

with open(save_path, mode="wb") as v:
v.write(response.content)
try:
logger.info(f"Downloading completed task: {save_path} ...")
t0 = time.time()

def _download_file() -> None:
with open(save_path, mode="wb") as v:
response = httpx.get(
url=get_task_progress_response.data.encode_url, # type: ignore
timeout=60 * 60,
)
if response.status_code != 200:
raise IOError(f"Error downloading file: {response.text}")
v.write(response.content)

_download_file()
del _download_file
gc.collect()
logger.info(f"Download completed task Successfully! path: {save_path}, time: {time.time() - t0:.2f}s")
except Exception as e:
logger.error(f"Error in downloading completed task: {save_path}: {e}")
raise e
6 changes: 2 additions & 4 deletions animepipeline/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,12 @@ async def pipeline_finalrip(self, task_info: TaskInfo) -> None:
)
logger.info(f'FinalRip Task Started for "{task_info.name}" EP {task_info.episode}')
except Exception as e:
logger.error(f"Failed to start finalrip task: {e}")

# wait video cut done
await asyncio.sleep(30)
logger.error(f"Failed to start FinalRip task: {e}")

# check task progress
while not await self.finalrip_client.check_task_completed(bt_downloaded_path.name):
await asyncio.sleep(30)
logger.info(f'FinalRip encode task completed for "{task_info.name}" EP {task_info.episode}')

# download temp file to bt_downloaded_path's parent directory
temp_saved_path: Path = bt_downloaded_path.parent / (bt_downloaded_path.name + "-encoded.mkv")
Expand Down

0 comments on commit 7304846

Please sign in to comment.