Spaces:
Running
Running
File size: 1,226 Bytes
8bea69a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
from urllib.parse import urlparse
from pathlib import Path
import requests
import pandas as pd
from project_settings import project_path
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--audio_file",
default="audio.xlsx",
type=str,
)
parser.add_argument(
"--output_dir",
default=(project_path / "temp/audio_trim/origin").as_posix(),
type=str,
)
args = parser.parse_args()
return args
def main():
args = get_args()
output_dir = Path(args.output_dir)
output_dir.mkdir(parents=True, exist_ok=True)
df = pd.read_excel(args.audio_file)
for i, row in df.iterrows():
name = row["name"]
scene_id = row["scene_id"]
audio_id = row["audio_id"]
audio_url = row["audio_url"]
schema = urlparse(audio_url)
path = schema.path
filename = output_dir / path[1:]
filename.parent.mkdir(parents=True, exist_ok=True)
resp = requests.get(audio_url)
with open(filename.as_posix(), "wb") as f:
f.write(resp.content)
return
if __name__ == "__main__":
main()
|