Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e911d4

Browse files
committed
Change a selected few option names
This gets rid of a few unnecessary abbreviations and generally confusing names (e.g. out_file for the path specified with --write-list), which would look odd as options in a configuration file.
1 parent cb54ee6 commit 5e911d4

3 files changed

Lines changed: 73 additions & 73 deletions

File tree

coub-gui.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ class GuiDefaultOptions(coub.DefaultOptions):
2828
AAC_LABEL = ["Only MP3", "No Bias", "Prefer AAC", "Only AAC"]
2929
RECOUB_LABEL = ["No Recoubs", "With Recoubs", "Only Recoubs"]
3030
SPECIAL_LABEL = {
31+
(False, False, False): "None",
3132
(True, False, False): "Share",
3233
(False, True, False): "Video only",
3334
(False, False, True): "Audio only",
34-
(False, False, False): None,
3535
}
3636

3737

@@ -42,10 +42,10 @@ def translate_to_cli(options):
4242
AAC_LABEL = {"Only MP3": 0, "No Bias": 1, "Prefer AAC": 2, "Only AAC": 3}
4343
RECOUB_LABEL = {"No Recoubs": 0, "With Recoubs": 1, "Only Recoubs": 2}
4444
SPECIAL_LABEL = {
45+
"None": (False, False, False),
4546
"Share": (True, False, False),
4647
"Video only": (False, True, False),
4748
"Audio only": (False, False, True),
48-
None: (False, False, False),
4949
}
5050

5151
# Convert GUI labels to valid options for the main script
@@ -130,13 +130,13 @@ def parse_cli():
130130
metavar="Prompt Behavior", help="How to answer user prompts")
131131
common.add_argument("--repeat", type=coub.positive_int, default=defs.REPEAT,
132132
metavar="Loop Count", help="How often to loop the video stream")
133-
common.add_argument("--dur", type=coub.valid_time, default=defs.DUR,
133+
common.add_argument("--duration", type=coub.valid_time, default=defs.DURATION,
134134
metavar="Limit duration",
135135
help="Max. duration of the output (FFmpeg syntax)")
136136
common.add_argument("--preview", default=defs.PREVIEW, metavar="Preview Command",
137137
help="Command to invoke to preview each finished coub")
138-
common.add_argument("--archive-path", type=coub.valid_archive,
139-
default=defs.ARCHIVE_PATH, widget="FileSaver",
138+
common.add_argument("--archive", type=coub.valid_archive,
139+
default=defs.ARCHIVE, widget="FileSaver",
140140
metavar="Archive", gooey_options={'message': "Choose archive file"},
141141
help="Use an archive file to keep track of already downloaded coubs")
142142
common.add_argument("--keep", action=f"store_{'false' if defs.KEEP else 'true'}",
@@ -145,8 +145,8 @@ def parse_cli():
145145

146146
# Download Options
147147
download = parser.add_argument_group("Download", gooey_options={'columns': 1})
148-
download.add_argument("--connect", type=coub.positive_int,
149-
default=defs.CONNECT, metavar="Number of connections",
148+
download.add_argument("--connections", type=coub.positive_int,
149+
default=defs.CONNECTIONS, metavar="Number of connections",
150150
help="How many connections to use (>100 not recommended)")
151151
download.add_argument("--retries", type=int, default=defs.RETRIES,
152152
metavar="Retry Attempts",
@@ -173,14 +173,14 @@ def parse_cli():
173173
formats.add_argument("--aac", default=defs.AAC_LABEL[defs.AAC],
174174
choices=["Only MP3", "No Bias", "Prefer AAC", "Only AAC"],
175175
metavar="Audio Format", help="How much to prefer AAC over MP3")
176-
formats.add_argument("--special", choices=["Share", "Video only", "Audio only"],
176+
formats.add_argument("--special", choices=["None", "Share", "Video only", "Audio only"],
177177
default=defs.SPECIAL_LABEL[(defs.SHARE, defs.V_ONLY, defs.A_ONLY)],
178178
metavar="Special Formats", help="Use a special format selection")
179179

180180
# Output
181181
output = parser.add_argument_group("Output", gooey_options={'columns': 1})
182-
output.add_argument("--out-file", type=os.path.abspath, widget="FileSaver",
183-
default=defs.OUT_FILE, metavar="Output to List",
182+
output.add_argument("--output-list", type=os.path.abspath, widget="FileSaver",
183+
default=defs.OUTPUT_LIST, metavar="Output to List",
184184
gooey_options={'message': "Save link list"},
185185
help="Save all parsed links in a list (no download)")
186186
output.add_argument("--path", type=os.path.abspath, default=defs.PATH,
@@ -195,7 +195,7 @@ def parse_cli():
195195
choices=["mkv", "mp4", "asf", "avi", "flv", "f4v", "mov"],
196196
help="What extension to use for merged output files "
197197
"(has no effect if no merge is required)")
198-
output.add_argument("--out-format", default=defs.OUT_FORMAT,
198+
output.add_argument("--name-template", default=defs.NAME_TEMPLATE,
199199
metavar="Name Template",
200200
help=dedent(f"""\
201201
Change the naming convention of output files
@@ -237,15 +237,15 @@ def parse_cli():
237237
args.input.append(coub.RandomCategory())
238238

239239
# Read archive content
240-
if args.archive_path and os.path.exists(args.archive_path):
241-
with open(args.archive_path, "r") as f:
242-
args.archive = [l.strip() for l in f]
240+
if args.archive and os.path.exists(args.archive):
241+
with open(args.archive, "r") as f:
242+
args.archive_content = [l.strip() for l in f]
243243
else:
244-
args.archive = None
244+
args.archive_content = None
245245
# The default naming scheme is the same as using %id%
246246
# but internally the default value is None
247-
if args.out_format == "%id%":
248-
args.out_format = None
247+
if args.name_template == "%id%":
248+
args.name_template = None
249249

250250
return translate_to_cli(args)
251251

coub.py

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class DefaultOptions:
9494
PATH = "."
9595
KEEP = False
9696
REPEAT = 1000
97-
DUR = None
97+
DURATION = None
9898
# Download defaults
99-
CONNECT = 25
99+
CONNECTIONS = 25
100100
RETRIES = 5
101101
MAX_COUBS = None
102102
# Format defaults
@@ -113,11 +113,11 @@ class DefaultOptions:
113113
# Misc. defaults
114114
A_ONLY = False
115115
V_ONLY = False
116-
OUT_FILE = None
117-
ARCHIVE_PATH = None
116+
OUTPUT_LIST = None
117+
ARCHIVE = None
118118
# Output defaults
119119
MERGE_EXT = "mkv"
120-
OUT_FORMAT = "%id%"
120+
NAME_TEMPLATE = "%id%"
121121
# Advanced defaults
122122
COUBS_PER_PAGE = 25
123123
TAG_SEP = "_"
@@ -161,8 +161,8 @@ def check_values(self):
161161
"PATH": (lambda x: isinstance(x, str)),
162162
"KEEP": (lambda x: isinstance(x, bool)),
163163
"REPEAT": (lambda x: isinstance(x, int) and x > 0),
164-
"DUR": (lambda x: isinstance(x, str) or x is None),
165-
"CONNECT": (lambda x: isinstance(x, int) and x > 0),
164+
"DURATION": (lambda x: isinstance(x, str) or x is None),
165+
"CONNECTIONS": (lambda x: isinstance(x, int) and x > 0),
166166
"RETRIES": (lambda x: isinstance(x, int)),
167167
"MAX_COUBS": (lambda x: isinstance(x, int) and x > 0 or x is None),
168168
"V_QUALITY": (lambda x: x in [0, -1]),
@@ -175,10 +175,10 @@ def check_values(self):
175175
"PREVIEW": (lambda x: isinstance(x, str) or x is None),
176176
"A_ONLY": (lambda x: isinstance(x, bool)),
177177
"V_ONLY": (lambda x: isinstance(x, bool)),
178-
"OUT_FILE": (lambda x: isinstance(x, str) or x is None),
179-
"ARCHIVE_PATH": (lambda x: isinstance(x, str) or x is None),
178+
"OUTPUT_LIST": (lambda x: isinstance(x, str) or x is None),
179+
"ARCHIVE": (lambda x: isinstance(x, str) or x is None),
180180
"MERGE_EXT": (lambda x: x in ["mkv", "mp4", "asf", "avi", "flv", "f4v", "mov"]),
181-
"OUT_FORMAT": (lambda x: isinstance(x, str) or x is None),
181+
"NAME_TEMPLATE": (lambda x: isinstance(x, str) or x is None),
182182
"COUBS_PER_PAGE": (lambda x: x in range(1, 26)),
183183
"TAG_SEP": (lambda x: isinstance(x, str)),
184184
"WRITE_METHOD": (lambda x: x in ["w", "a"]),
@@ -207,11 +207,11 @@ def guess_string_type(option, string):
207207
# Usually options which are supposed to ONLY take strings
208208
exceptions = [
209209
"PATH",
210-
"DUR",
210+
"DURATION",
211211
"PREVIEW",
212-
"OUT_FILE",
213-
"ARCHIVE_PATH",
214-
"OUT_FORMAT",
212+
"OUTPUT_LIST",
213+
"ARCHIVE",
214+
"NAME_TEMPLATE",
215215
"TAG_SEP",
216216
]
217217

@@ -280,7 +280,7 @@ def format_help(self):
280280
-d, --duration TIME specify max. coub duration (FFmpeg syntax)
281281
282282
Download options:
283-
--connections N max. number of connections (def: {self.get_default("connect")})
283+
--connections N max. number of connections (def: {self.get_default("connections")})
284284
--retries N number of retries when connection is lost (def: {self.get_default("retries")})
285285
0 to disable, <0 to retry indefinitely
286286
--limit-num LIMIT limit max. number of downloaded coubs
@@ -316,7 +316,7 @@ def format_help(self):
316316
Output:
317317
--ext EXTENSION merge output with the given extension (def: {self.get_default("merge_ext")})
318318
ignored if no merge is required
319-
-o, --output FORMAT save output with the given template (def: {self.get_default("out_format")})
319+
-o, --output FORMAT save output with the given template (def: {self.get_default("name_template")})
320320
321321
Special strings:
322322
%id% - coub ID (identifier in the URL)
@@ -551,7 +551,7 @@ async def process(self, quantity=None):
551551
msg(f" {pages} out of {self.pages} pages")
552552

553553
tout = aiohttp.ClientTimeout(total=None)
554-
conn = aiohttp.TCPConnector(limit=opts.connect)
554+
conn = aiohttp.TCPConnector(limit=opts.connections)
555555
async with aiohttp.ClientSession(timeout=tout, connector=conn) as session:
556556
tasks = [parse_page(req, session) for req in requests]
557557
links = await asyncio.gather(*tasks)
@@ -889,14 +889,14 @@ def check_existence(self):
889889
if self.erroneous():
890890
return
891891

892-
if opts.archive and self.id in opts.archive:
892+
if opts.archive_content and self.id in opts.archive_content:
893893
self.exists = True
894894
return
895895

896896
old_file = None
897897
# Existence of self.name indicates whether API request was already
898898
# made (i.e. if 1st or 2nd check)
899-
if not opts.out_format:
899+
if not opts.name_template:
900900
if not self.name:
901901
old_file = exists(self.id)
902902
else:
@@ -1013,8 +1013,8 @@ def merge(self):
10131013
"-f", "concat", "-safe", "0",
10141014
"-i", f"file:{t_name}", "-i", f"file:{self.a_name}",
10151015
]
1016-
if opts.dur:
1017-
command.extend(["-t", opts.dur])
1016+
if opts.duration:
1017+
command.extend(["-t", opts.duration])
10181018
command.extend(["-c", "copy", "-shortest", f"file:temp_{m_name}"])
10191019

10201020
subprocess.run(command)
@@ -1037,7 +1037,7 @@ def archive(self):
10371037
if self.erroneous():
10381038
return
10391039

1040-
with open(opts.archive_path, "a") as f:
1040+
with open(opts.archive, "a") as f:
10411041
print(self.id, file=f)
10421042

10431043
def preview(self):
@@ -1073,7 +1073,7 @@ async def process(self, session=None):
10731073

10741074
# 2nd existence check
10751075
# Handles custom names exclusively (slower since API request necessary)
1076-
if opts.out_format:
1076+
if opts.name_template:
10771077
self.check_existence()
10781078

10791079
# Download
@@ -1088,7 +1088,7 @@ async def process(self, session=None):
10881088
# of valid streams with special format options (e.g. --video-only)
10891089
self.done = True
10901090

1091-
if opts.archive_path:
1091+
if opts.archive:
10921092
self.archive()
10931093
if opts.preview:
10941094
self.preview()
@@ -1419,11 +1419,11 @@ def parse_cli():
14191419
repeat.add_argument("-r", "--repeat", type=positive_int, default=defaults.REPEAT)
14201420
parser.add_argument("-p", "--path", type=os.path.abspath, default=defaults.PATH)
14211421
parser.add_argument("-k", "--keep", action="store_true", default=defaults.KEEP)
1422-
parser.add_argument("-d", "--duration", dest="dur", type=valid_time,
1423-
default=defaults.DUR)
1422+
parser.add_argument("-d", "--duration", type=valid_time,
1423+
default=defaults.DURATION)
14241424
# Download Options
1425-
parser.add_argument("--connections", dest="connect", type=positive_int,
1426-
default=defaults.CONNECT)
1425+
parser.add_argument("--connections", type=positive_int,
1426+
default=defaults.CONNECTIONS)
14271427
parser.add_argument("--retries", type=int, default=defaults.RETRIES)
14281428
parser.add_argument("--limit-num", dest="max_coubs", type=positive_int,
14291429
default=defaults.MAX_COUBS)
@@ -1466,15 +1466,15 @@ def parse_cli():
14661466
stream.add_argument("--video-only", dest="v_only", action="store_true",
14671467
default=defaults.V_ONLY)
14681468
stream.add_argument("--share", action="store_true", default=defaults.SHARE)
1469-
parser.add_argument("--write-list", dest="out_file", type=os.path.abspath,
1470-
default=defaults.OUT_FILE)
1471-
parser.add_argument("--use-archive", dest="archive_path", type=valid_archive,
1472-
default=defaults.ARCHIVE_PATH)
1469+
parser.add_argument("--write-list", dest="output_list", type=os.path.abspath,
1470+
default=defaults.OUTPUT_LIST)
1471+
parser.add_argument("--use-archive", dest="archive", type=valid_archive,
1472+
default=defaults.ARCHIVE)
14731473
# Output
14741474
parser.add_argument("--ext", dest="merge_ext", default=defaults.MERGE_EXT,
14751475
choices=["mkv", "mp4", "asf", "avi", "flv", "f4v", "mov"])
1476-
parser.add_argument("-o", "--output", dest="out_format",
1477-
default=defaults.OUT_FORMAT)
1476+
parser.add_argument("-o", "--output", dest="name_template",
1477+
default=defaults.NAME_TEMPLATE)
14781478

14791479
# Advanced Options
14801480
parser.set_defaults(
@@ -1496,15 +1496,15 @@ def parse_cli():
14961496
else:
14971497
args.input = args.raw_input
14981498
# Read archive content
1499-
if args.archive_path and os.path.exists(args.archive_path):
1500-
with open(args.archive_path, "r") as f:
1501-
args.archive = [l.strip() for l in f]
1499+
if args.archive and os.path.exists(args.archive):
1500+
with open(args.archive, "r") as f:
1501+
args.archive_content = [l.strip() for l in f]
15021502
else:
1503-
args.archive = None
1503+
args.archive_content = None
15041504
# The default naming scheme is the same as using %id%
15051505
# but internally the default value is None
1506-
if args.out_format == "%id%":
1507-
args.out_format = None
1506+
if args.name_template == "%id%":
1507+
args.name_template = None
15081508

15091509
return args
15101510

@@ -1611,19 +1611,19 @@ def parse_input(sources):
16111611

16121612
def write_list(links):
16131613
"""Output parsed links to a list and exit."""
1614-
with open(opts.out_file, opts.write_method) as f:
1614+
with open(opts.output_list, opts.write_method) as f:
16151615
for l in links:
16161616
print(l, file=f)
1617-
msg(f"\nParsed coubs written to '{opts.out_file}'!",
1617+
msg(f"\nParsed coubs written to '{opts.output_list}'!",
16181618
color=fgcolors.SUCCESS)
16191619

16201620

16211621
def get_name(req_json, c_id):
16221622
"""Assemble final output name of a given coub."""
1623-
if not opts.out_format:
1623+
if not opts.name_template:
16241624
return c_id
16251625

1626-
name = opts.out_format
1626+
name = opts.name_template
16271627

16281628
name = name.replace("%id%", c_id)
16291629
name = name.replace("%title%", req_json['title'])
@@ -1879,7 +1879,7 @@ async def process(coubs):
18791879
"""Call the process function of all parsed coubs."""
18801880
if aio:
18811881
tout = aiohttp.ClientTimeout(total=None)
1882-
conn = aiohttp.TCPConnector(limit=opts.connect)
1882+
conn = aiohttp.TCPConnector(limit=opts.connections)
18831883
try:
18841884
async with aiohttp.ClientSession(timeout=tout, connector=conn) as session:
18851885
tasks = [c.process(session) for c in coubs]
@@ -1938,7 +1938,7 @@ def main():
19381938

19391939
msg("\n### Parse Input ###")
19401940
links = parse_input(opts.input)
1941-
if opts.out_file:
1941+
if opts.output_list:
19421942
write_list(links)
19431943
sys.exit(0)
19441944
total = len(links)

0 commit comments

Comments
 (0)