ignore
Browse files- download_audio.py +10 -16
download_audio.py
CHANGED
@@ -20,28 +20,18 @@ cache_dir_root = "download"
|
|
20 |
cache_dir_audio = p_join(cache_dir_root, "audio")
|
21 |
cache_dir_metadata = p_join(cache_dir_root, "meta")
|
22 |
n_pool = int(os.getenv("N_POOL", 8))
|
23 |
-
|
|
|
|
|
24 |
|
25 |
|
26 |
def wget(url: str, cache_dir: str, filename: Optional[str] = None):
|
27 |
os.makedirs(cache_dir, exist_ok=True)
|
28 |
filename = os.path.basename(url) if not filename else filename
|
29 |
output_file = p_join(cache_dir, filename)
|
30 |
-
subprocess.run(["wget", url, "-O", output_file, "--tries",
|
31 |
if not os.path.exists(output_file):
|
32 |
return False
|
33 |
-
# try:
|
34 |
-
# urllib.request.urlretrieve(url, output_file)
|
35 |
-
# except (ConnectionError, HTTPError):
|
36 |
-
# traceback.print_exc()
|
37 |
-
# if os.path.exists(output_file):
|
38 |
-
# os.remove(output_file)
|
39 |
-
# return False
|
40 |
-
# except KeyboardInterrupt:
|
41 |
-
# if os.path.exists(output_file):
|
42 |
-
# os.remove(output_file)
|
43 |
-
# exit()
|
44 |
-
|
45 |
if output_file.endswith('.tar.gz') or output_file.endswith('.tgz') or output_file.endswith('.tar'):
|
46 |
if output_file.endswith('.tar'):
|
47 |
tar = tarfile.open(output_file)
|
@@ -96,6 +86,10 @@ def process_dataset(url_metadata):
|
|
96 |
|
97 |
|
98 |
if __name__ == '__main__':
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
101 |
|
|
|
20 |
cache_dir_audio = p_join(cache_dir_root, "audio")
|
21 |
cache_dir_metadata = p_join(cache_dir_root, "meta")
|
22 |
n_pool = int(os.getenv("N_POOL", 8))
|
23 |
+
wget_max_retry = os.getenv("MAX_RETRY", "1")
|
24 |
+
wget_timeout = os.getenv("TIMEOUT", "20")
|
25 |
+
data = os.getenv("DATA", "s2s")
|
26 |
|
27 |
|
28 |
def wget(url: str, cache_dir: str, filename: Optional[str] = None):
|
29 |
os.makedirs(cache_dir, exist_ok=True)
|
30 |
filename = os.path.basename(url) if not filename else filename
|
31 |
output_file = p_join(cache_dir, filename)
|
32 |
+
subprocess.run(["wget", url, "-O", output_file, "--tries", wget_max_retry, "--timeout", wget_timeout])
|
33 |
if not os.path.exists(output_file):
|
34 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
if output_file.endswith('.tar.gz') or output_file.endswith('.tgz') or output_file.endswith('.tar'):
|
36 |
if output_file.endswith('.tar'):
|
37 |
tar = tarfile.open(output_file)
|
|
|
86 |
|
87 |
|
88 |
if __name__ == '__main__':
|
89 |
+
if data == "s2s":
|
90 |
+
process_dataset(url_metadata_s2s)
|
91 |
+
elif data == "s2t":
|
92 |
+
process_dataset(url_metadata_s2t)
|
93 |
+
else:
|
94 |
+
raise ValueError(f"unknown data type {data}")
|
95 |
|