-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
100 lines (85 loc) · 4.37 KB
/
client.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
MIT License
Copyright (c) 2023 cubicibo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from scenaristream import EsMuiStream, TSClock
from scenaristream.__metadata__ import __author__, __version__
import os
import sys
from pathlib import Path
from argparse import ArgumentParser
from typing import NoReturn
#%% Main code
if __name__ == '__main__':
def exit_msg(msg: str, is_error: bool = True) -> NoReturn:
if msg != '':
print(msg)
sys.exit(is_error)
####exit_msg
parser = ArgumentParser()
group = parser.add_mutually_exclusive_group()
group.add_argument("-s", "--stream", type=str, help="Input (sup, mnu, textst) to convert to xES+MUI.", default='')
group.add_argument("-x", "--xes", type=str, help="Input xES to convert.", default='')
parser.add_argument("-m", "--mui", type=str, help="Input MUI associated to xES to convert.", default='')
parser.add_argument("-t", "--textst", help="Use if TextST.", action='store_true')
parser.add_argument("-l", "--late-ts", help="Flag if first PTS is after 13.5 hours when converting to xES+MUI.", action='store_true')
parser.add_argument('-v', '--version', action='version', version=f"(c) {__author__}, v{__version__}")
parser.add_argument("-o", "--output", type=str, required=True)
args = parser.parse_args()
if args.stream == '' and args.xes == '' and args.mui == '':
exit_msg("No input provided, exiting.")
elif (args.mui != '' or args.xes != '') and args.stream != '':
exit_msg("Using conflicting args --mui and --stream, exiting.")
if args.xes != '' and args.mui == '':
if os.path.exists(args.xes + '.mui'):
args.mui = args.xes + '.mui'
elif os.path.exists(args.xes + '.MUI'):
args.mui = args.xes + '.MUI'
else:
exit_msg("xES provided but no MUI, exiting.")
elif args.mui != '' and args.xes == '':
if os.path.exists('.'.join(args.mui.split('.')[:-1])):
args.xes = '.'.join(args.mui.split('.')[:-1])
else:
exit_msg("MUI provided but no xES, exiting.")
if not Path(args.output).parent.exists():
exit_msg("Parent directory of output file does not exist, exiting.")
if args.stream:
if not os.path.exists(args.stream):
exit_msg("Input file does not exist, exiting.")
if not args.output.strip().lower().endswith('es'):
exit_msg("Desired output format is not xES? Exiting.")
print("Converting to xES+MUI...")
if (args.stream.lower().endswith('textst') or args.xes.lower().endswith('tes')) and not args.textst:
exit_msg("Is the conversion for TextST? Flag it as such if so. Exiting...")
elif args.textst:
EsMuiStream.convert_to_tesmui(args.stream, args.output, args.output + '.mui')
else:
first_dts = ((1<<32)/TSClock.PTS) if args.late_ts else (-1.0)
EsMuiStream.convert_to_pesmui(args.stream, args.output, args.output + '.mui', first_dts=first_dts)
exit_msg("", is_error=False)
elif args.mui:
print("Converting from xES+MUI...")
assert args.textst is False and args.xes.lower().endswith('tes') is False, "Cannot convert TES to TextST at this time."
emf = EsMuiStream(args.mui, args.xes)
emf.convert_to_stream(args.output)
exit_msg("", is_error=False)
exit_msg("Failed parsing args.")
####if