-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
51 lines (43 loc) · 1.62 KB
/
index.py
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
import time
from Converter import Converter
from ConversionStatusChecker import ConversionStatusChecker
from ConverterFileDownloader import ConverterFileDownloader
from ConverterDeletePid import ConverterDeletePid
try:
auth_token = "your_auth_token"
# Start conversion
print("Uploading file..")
converter = Converter(auth_token)
conversion_response = converter.audio("flac-to-wav", "/path/to/file/1.flac")
pid = conversion_response['pid']
print(f"Conversion started. PID: {pid}")
# Check status
status_checker = ConversionStatusChecker(auth_token)
while True:
status_response = status_checker.check_status(pid)
status = status_response['status']
print(f"Status: {status}")
if status == ConversionStatusChecker.STATUS_COMPLETED:
break
elif status in [
ConversionStatusChecker.STATUS_UPLOAD_ERROR,
ConversionStatusChecker.STATUS_PROCESS_ERROR,
ConversionStatusChecker.STATUS_CONVERT_ERROR
]:
raise Exception(f"Error occurred: {status}")
time.sleep(2)
# Download file
download_url = status_response['data']
downloader = ConverterFileDownloader(auth_token)
output_path = "/path/to/file/downloaded_file.wav"
downloader.download_file(download_url, output_path)
print(f"File downloaded to: {output_path}")
# Delete PID
delete_pid = ConverterDeletePid(auth_token)
r = delete_pid.delete(pid)
if r['success']:
print("PID deleted successfully.")
else:
print(f"Error deleting PID: {r['message']}")
except Exception as e:
print(f"Error: {e}")