download_file_with_aria2c
Browse files
App/Generate/database/DescriptAPI.py
CHANGED
|
@@ -134,7 +134,7 @@ class Speak:
|
|
| 134 |
if "status" in status_data:
|
| 135 |
if status_data["status"] == "done":
|
| 136 |
audio_url = status_data["url"]
|
| 137 |
-
temp = await self.
|
| 138 |
return audio_url, temp
|
| 139 |
else:
|
| 140 |
pass
|
|
@@ -157,6 +157,20 @@ class Speak:
|
|
| 157 |
|
| 158 |
return save_path
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
async def process_narrations(narrations):
|
| 162 |
speak = Speak()
|
|
|
|
| 134 |
if "status" in status_data:
|
| 135 |
if status_data["status"] == "done":
|
| 136 |
audio_url = status_data["url"]
|
| 137 |
+
temp = await self.download_file_with_aria2c(audio_url)
|
| 138 |
return audio_url, temp
|
| 139 |
else:
|
| 140 |
pass
|
|
|
|
| 157 |
|
| 158 |
return save_path
|
| 159 |
|
| 160 |
+
async def download_file_with_aria2c(url, filepath):
|
| 161 |
+
command = f"aria2c {url} -o {filepath}"
|
| 162 |
+
process = await asyncio.create_subprocess_shell(
|
| 163 |
+
command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
stdout, stderr = await process.communicate()
|
| 167 |
+
|
| 168 |
+
if process.returncode == 0:
|
| 169 |
+
print(f"File downloaded successfully to {filepath}")
|
| 170 |
+
else:
|
| 171 |
+
print(f"Failed to download file. Error: {stderr.decode()}")
|
| 172 |
+
return filepath
|
| 173 |
+
|
| 174 |
|
| 175 |
async def process_narrations(narrations):
|
| 176 |
speak = Speak()
|