diff options
| author | tassaron | 2022-05-07 22:27:55 -0400 |
|---|---|---|
| committer | tassaron | 2022-05-07 22:27:55 -0400 |
| commit | eb74e932d8ee9ecd2221629ea84a07b8e317d89f (patch) | |
| tree | 36dd19fb044bfd5a1a74c34e2e12d2c295418fe1 | |
| parent | 116baf124a5f8de87f7852263b043b23d6fca1cc (diff) | |
--export-project uses -i and -o if provided
Also remove unneeded instance variables `parser` and `args`, and quit if input/output can't be determined.
Also, --debug and --test are now mutually exclusive
| -rw-r--r-- | src/command.py | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/src/command.py b/src/command.py index 68282e5..b46498f 100644 --- a/src/command.py +++ b/src/command.py | |||
| @@ -37,62 +37,68 @@ class Command(QtCore.QObject): | |||
| 37 | signal.signal(signal.SIGINT, self.stopVideo) | 37 | signal.signal(signal.SIGINT, self.stopVideo) |
| 38 | 38 | ||
| 39 | def parseArgs(self): | 39 | def parseArgs(self): |
| 40 | self.parser = argparse.ArgumentParser( | 40 | parser = argparse.ArgumentParser( |
| 41 | prog='avp' if os.path.basename(sys.argv[0]) == "__main__.py" else None, | 41 | prog='avp' if os.path.basename(sys.argv[0]) == "__main__.py" else None, |
| 42 | description='Create a visualization for an audio file', | 42 | description='Create a visualization for an audio file', |
| 43 | epilog='EXAMPLE COMMAND: main.py myvideotemplate.avp ' | 43 | epilog='EXAMPLE COMMAND: avp myvideotemplate ' |
| 44 | '-i ~/Music/song.mp3 -o ~/video.mp4 ' | 44 | '-i ~/Music/song.mp3 -o ~/video.mp4 ' |
| 45 | '-c 0 image path=~/Pictures/thisWeeksPicture.jpg ' | 45 | '-c 0 image path=~/Pictures/thisWeeksPicture.jpg ' |
| 46 | '-c 1 video "preset=My Logo" -c 2 vis layout=classic' | 46 | '-c 1 video "preset=My Logo" -c 2 vis layout=classic' |
| 47 | ) | 47 | ) |
| 48 | self.parser.add_argument( | 48 | |
| 49 | |||
| 50 | # input/output automatic-export commands | ||
| 51 | parser.add_argument( | ||
| 49 | '-i', '--input', metavar='SOUND', | 52 | '-i', '--input', metavar='SOUND', |
| 50 | help='input audio file' | 53 | help='input audio file' |
| 51 | ) | 54 | ) |
| 52 | self.parser.add_argument( | 55 | parser.add_argument( |
| 53 | '-o', '--output', metavar='OUTPUT', | 56 | '-o', '--output', metavar='OUTPUT', |
| 54 | help='output video file' | 57 | help='output video file' |
| 55 | ) | 58 | ) |
| 56 | self.parser.add_argument( | 59 | parser.add_argument( |
| 57 | '--export-project', action='store_true', | 60 | '--export-project', action='store_true', |
| 58 | help='ignore -i and -o, use input and output from project file' | 61 | help='use input and output files from project file if -i or -o is missing' |
| 59 | ) | 62 | ) |
| 60 | self.parser.add_argument( | 63 | |
| 64 | # mutually exclusive debug options | ||
| 65 | debugCommands = parser.add_mutually_exclusive_group() | ||
| 66 | debugCommands.add_argument( | ||
| 61 | '--test', action='store_true', | 67 | '--test', action='store_true', |
| 62 | help='run tests and create a report full of debugging info' | 68 | help='run tests and create a report full of debugging info' |
| 63 | ) | 69 | ) |
| 64 | self.parser.add_argument( | 70 | debugCommands.add_argument( |
| 65 | '--debug', action='store_true', | 71 | '--debug', action='store_true', |
| 66 | help='create bigger logfiles while program is running' | 72 | help='create bigger logfiles while program is running' |
| 67 | ) | 73 | ) |
| 68 | self.parser.add_argument( | ||
| 69 | '--no-preview', action='store_true', | ||
| 70 | help='disable live preview during export in GUI mode' | ||
| 71 | ) | ||
| 72 | 74 | ||
| 73 | # optional arguments | 75 | # project/GUI options |
| 74 | self.parser.add_argument( | 76 | parser.add_argument( |
| 75 | 'projpath', metavar='path-to-project', | 77 | 'projpath', metavar='path-to-project', |
| 76 | help='open a project file (.avp)', nargs='?') | 78 | help='open a project file (.avp)', nargs='?') |
| 77 | self.parser.add_argument( | 79 | parser.add_argument( |
| 78 | '-c', '--comp', metavar=('LAYER', 'ARG'), | 80 | '-c', '--comp', metavar=('LAYER', 'ARG'), |
| 79 | help='first arg must be component NAME to insert at LAYER.' | 81 | help='first arg must be component NAME to insert at LAYER.' |
| 80 | '"help" for information about possible args for a component.', | 82 | '"help" for information about possible args for a component.', |
| 81 | nargs='*', action='append') | 83 | nargs='*', action='append') |
| 84 | parser.add_argument( | ||
| 85 | '--no-preview', action='store_true', | ||
| 86 | help='disable live preview during export' | ||
| 87 | ) | ||
| 82 | 88 | ||
| 83 | self.args = self.parser.parse_args() | 89 | args = parser.parse_args() |
| 84 | 90 | ||
| 85 | if self.args.debug: | 91 | if args.debug: |
| 86 | core.FILE_LOGLVL = logging.DEBUG | 92 | core.FILE_LOGLVL = logging.DEBUG |
| 87 | core.STDOUT_LOGLVL = logging.DEBUG | 93 | core.STDOUT_LOGLVL = logging.DEBUG |
| 88 | core.Core.makeLogger() | 94 | core.Core.makeLogger() |
| 89 | 95 | ||
| 90 | if self.args.test: | 96 | if args.test: |
| 91 | self.runTests() | 97 | self.runTests() |
| 92 | quit(0) | 98 | quit(0) |
| 93 | 99 | ||
| 94 | if self.args.projpath: | 100 | if args.projpath: |
| 95 | projPath = self.args.projpath | 101 | projPath = args.projpath |
| 96 | if not os.path.dirname(projPath): | 102 | if not os.path.dirname(projPath): |
| 97 | projPath = os.path.join( | 103 | projPath = os.path.join( |
| 98 | self.settings.value("projectDir"), | 104 | self.settings.value("projectDir"), |
| @@ -107,11 +113,11 @@ class Command(QtCore.QObject): | |||
| 107 | reversed(self.core.selectedComponents)) | 113 | reversed(self.core.selectedComponents)) |
| 108 | self.core.componentListChanged() | 114 | self.core.componentListChanged() |
| 109 | 115 | ||
| 110 | if self.args.comp: | 116 | if args.comp: |
| 111 | for comp in self.args.comp: | 117 | for comp in args.comp: |
| 112 | pos = comp[0] | 118 | pos = comp[0] |
| 113 | name = comp[1] | 119 | name = comp[1] |
| 114 | args = comp[2:] | 120 | compargs = comp[2:] |
| 115 | try: | 121 | try: |
| 116 | pos = int(pos) | 122 | pos = int(pos) |
| 117 | except ValueError: | 123 | except ValueError: |
| @@ -123,11 +129,13 @@ class Command(QtCore.QObject): | |||
| 123 | quit(1) | 129 | quit(1) |
| 124 | modI = self.core.moduleIndexFor(realName) | 130 | modI = self.core.moduleIndexFor(realName) |
| 125 | i = self.core.insertComponent(pos, modI, self) | 131 | i = self.core.insertComponent(pos, modI, self) |
| 126 | for arg in args: | 132 | for arg in compargs: |
| 127 | self.core.selectedComponents[i].command(arg) | 133 | self.core.selectedComponents[i].command(arg) |
| 128 | 134 | ||
| 129 | if self.args.export_project and self.args.projpath: | 135 | if args.export_project and args.projpath: |
| 130 | errcode, data = self.core.parseAvFile(projPath) | 136 | errcode, data = self.core.parseAvFile(projPath) |
| 137 | input_ = None | ||
| 138 | output = None | ||
| 131 | for key, value in data['WindowFields']: | 139 | for key, value in data['WindowFields']: |
| 132 | if 'outputFile' in key: | 140 | if 'outputFile' in key: |
| 133 | output = value | 141 | output = value |
| @@ -137,19 +145,28 @@ class Command(QtCore.QObject): | |||
| 137 | output | 145 | output |
| 138 | ) | 146 | ) |
| 139 | if 'audioFile' in key: | 147 | if 'audioFile' in key: |
| 140 | input = value | 148 | input_ = value |
| 141 | self.createAudioVisualisation(input, output) | 149 | |
| 150 | # use input/output from project file, overwritten by -i and -o | ||
| 151 | if (not input_ and not args.input) or (not output and not args.output): | ||
| 152 | parser.print_help() | ||
| 153 | quit(1) | ||
| 154 | |||
| 155 | self.createAudioVisualisation( | ||
| 156 | input_ if not args.input else args.input, | ||
| 157 | output if not args.output else args.output | ||
| 158 | ) | ||
| 142 | return "commandline" | 159 | return "commandline" |
| 143 | 160 | ||
| 144 | elif self.args.input and self.args.output: | 161 | elif args.input and args.output: |
| 145 | self.createAudioVisualisation(self.args.input, self.args.output) | 162 | self.createAudioVisualisation(args.input, args.output) |
| 146 | return "commandline" | 163 | return "commandline" |
| 147 | 164 | ||
| 148 | elif self.args.no_preview: | 165 | elif args.no_preview: |
| 149 | core.Core.previewEnabled = False | 166 | core.Core.previewEnabled = False |
| 150 | 167 | ||
| 151 | elif 'help' not in sys.argv and self.args.projpath is None and '--debug' not in sys.argv: | 168 | elif 'help' not in sys.argv and args.projpath is None and '--debug' not in sys.argv: |
| 152 | self.parser.print_help() | 169 | parser.print_help() |
| 153 | quit(1) | 170 | quit(1) |
| 154 | 171 | ||
| 155 | return "GUI" | 172 | return "GUI" |
