Commit 53f5c7b0 authored by Matteo's avatar Matteo
Browse files

update config file management

parent ab643b9b
# Working path
WORKING_PATH: "/Users/nadir/Documents/MPAI-CAE/Workflow"
WORKING_PATH: "/data"
# Name of the Preservation Audio File (without extension)
FILES_NAME: "sample12_W7N_R15C"
# PRESERVATION_FILE_NAME: "BornToDie"
......
title: Tape Audio Restoration
description: |
[![MPAI CAE-ARP](https://img.shields.io/badge/MPAI%20CAE--ARP-gray?style=for-the-badge&logo=AppleMusic&logoColor=cyan&link=https://mpai.community/standards/mpai-cae/about-mpai-cae/)](https://mpai.community/standards/mpai-cae/about-mpai-cae/)
Implements the Technical Specification of [MPAI CAE-ARP](https://mpai.community/standards/mpai-cae/about-mpai-cae/#Figure2) *Tape Audio Restoration* AIM, providing:
* Restored Audio Files;
* Editing List.
version: "1.0.1"
contact:
name: Nadir Dalla Pozza
email: nadir.dallapozza@unipd.it
license_info:
name: GNU General Public License v3.0
url: https://www.gnu.org/licenses/gpl-3.0.en.html
\ No newline at end of file
......@@ -27,7 +27,7 @@ librosa==0.10.0.post2
llvmlite==0.39.1
MarkupSafe==2.1.2
matplotlib==3.7.1
mpai-cae-arp==0.1.0
mpai-cae-arp==0.2.0
msgpack==1.0.5
numba==0.56.4
numpy==1.23.3
......
import subprocess
import json
from fastapi import FastAPI, Response, status
from fastapi import FastAPI, Response, status, Query
from typing import Annotated
from mpai_cae_arp.types.schema import Info
from mpai_cae_arp.files import get_file_content
from mpai_cae_arp.files import FileType, File
from src.tapeAudioRestoration import __author__, __version__, __license__, __email__, __maintainer__
info = File("config/server.yaml", FileType.YAML).get_content()
info = Info(
title="Tape Audio Restoration",
description="""
[![MPAI CAE-ARP](https://img.shields.io/badge/MPAI%20CAE--ARP-gray?style=for-the-badge&logo=AppleMusic&logoColor=cyan&link=https://mpai.community/standards/mpai-cae/about-mpai-cae/)](https://mpai.community/standards/mpai-cae/about-mpai-cae/)
Implements the Technical Specification of [MPAI CAE-ARP](https://mpai.community/standards/mpai-cae/about-mpai-cae/#Figure2) *Tape Audio Restoration* AIM, providing:
* Restored Audio Files;
* Editing List.
""",
version=__version__,
contact={
"name": __maintainer__,
"email": __email__
},
license_info={"name": __license__, "url": "https://www.gnu.org/licenses/gpl-3.0.html"}
)
app = FastAPI(**(json.loads(info.json())))
app = FastAPI(**info)
@app.get("/")
def list_all_entrypoints() -> list[str]:
async def list_all_entrypoints() -> list[str]:
"""
Get the list of available main routes.
"""
return ["restore", "description", "docs"]
@app.get("/description")
async def get_server_info() -> Info:
"""
Retrieve all the informations about the software running on the server.
"""
return info
@app.get("/restore", status_code=200)
async def restore(files_name: str, equalization_w: str, equalization_r: str, speed_w: str, speed_r: str, response: Response, working_path: str | None = None):
async def restore(
response: Response,
equalization_w: Annotated[str, Query(
description="Actual equalization of the audio tape applied during the recording.",
example="CCIR"
)],
equalization_r: Annotated[str, Query(
description="Actual equalization of the audio tape applied during the playback.",
example="NAB"
)],
speed_w: Annotated[str, Query(
description="Actual speed of the audio tape applied during the recording.",
example="7.5"
)],
speed_r: Annotated[str, Query(
description="Actual speed of the audio tape applied during the playback.",
example="15"
)],
files_name: Annotated[str, Query(
description="Name of the audio/video file to be analyzed without the extension.",
example="filename"
)],
working_path: Annotated[str, Query(
description="Path to the directory containing the preservation files.",
examples={
"Absolute path": {"value": "/home/user/preservation"},
"Relative path": {"value": "preservation"}
}
)] = None
) -> dict:
process = [
"python",
......@@ -54,7 +72,7 @@ async def restore(files_name: str, equalization_w: str, equalization_r: str, spe
if working_path is not None:
process.extend(["--working_path", working_path])
else:
config = get_file_content("config/args.yaml", "yaml")
config = File("config/args.yaml", FileType.YAML).get_content()
process.extend(["--working_path", config["WORKING_PATH"]])
......@@ -62,7 +80,7 @@ async def restore(files_name: str, equalization_w: str, equalization_r: str, spe
if cprocess.returncode == 0:
editing_list = get_file_content("EditingList.json", "json")
editing_list = File("EditingList.json", FileType.JSON).get_content()
return editing_list
else:
......
......@@ -50,8 +50,8 @@ class CC:
def get_arguments() -> tuple[str, str, str, float, str, float]:
"""
Method to obtain arguments from config.yaml file or command line.
Default config.yaml, ignored if a command line argument is passed.
Method to obtain arguments from config/args.yaml file or command line.
Default config/args.yaml, ignored if a command line argument is passed.
:return: tuple consisting of nine variables:
1) str specifying the working path;
2) str specifying the name of the Preservation files, which is key element to retrieve necessary files;
......@@ -67,7 +67,7 @@ def get_arguments() -> tuple[str, str, str, float, str, float]:
prog="python3 tapeAudioRestoration.py",
formatter_class=RawTextHelpFormatter,
description="A tool that implements MPAI CAE-ARP Tape Audio Restoration Technical Specification.\n"
"By default, the configuration parameters are loaded from ./config.yaml file,\n"
"By default, the configuration parameters are loaded from ./config/args.yaml file,\n"
"but, alternately, you can pass command line arguments to replace them."
)
parser.add_argument(
......@@ -122,19 +122,19 @@ def get_arguments() -> tuple[str, str, str, float, str, float]:
print(prettify('WORKING_PATH key not found in config/args.yaml!', color=Color.RED))
quit(os.EX_CONFIG)
if 'FILES_NAME' not in config:
print(CC.RED + 'FILES_NAME key not found in config.yaml!' + CC.END)
print(CC.RED + 'FILES_NAME key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
if 'STANDARD_W' not in config:
print(CC.RED + 'STANDARD_W key not found in config.yaml!' + CC.END)
print(CC.RED + 'STANDARD_W key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
if 'SPEED_W' not in config:
print(CC.RED + 'SPEED_W key not found in config.yaml!' + CC.END)
print(CC.RED + 'SPEED_W key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
if 'STANDARD_R' not in config:
print(CC.RED + 'STANDARD_R key not found in config.yaml!' + CC.END)
print(CC.RED + 'STANDARD_R key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
if 'SPEED_R' not in config:
print(CC.RED + 'SPEED_R key not found in config.yaml!' + CC.END)
print(CC.RED + 'SPEED_R key not found in config/args.yaml!' + CC.END)
quit(os.EX_CONFIG)
except FileNotFoundError:
print(CC.RED + 'config/args.yaml file not found!' + CC.END)
......@@ -767,7 +767,7 @@ def main():
print(CC.BOLD + "\nWelcome to ARP Tape Audio Restoration!" + CC.END)
print("You are using Python version: " + sys.version)
# Get the input from config.yaml or command line
# Get the input from config/args.yaml or command line
working_path, files_name, standard_w, speed_w, standard_r, speed_r = get_arguments()
# Check if input is correct
paf_path, temp_path, standard_w, standard_r = check_input(working_path, files_name, standard_w, speed_w, standard_r, speed_r)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment