|
@@ -24,11 +24,23 @@ import requests
|
|
|
from pytimeparse.timeparse import timeparse
|
|
|
|
|
|
|
|
|
+def DurationType(arg):
|
|
|
+ if arg.isdecimal():
|
|
|
+ secs = int(arg)
|
|
|
+ else:
|
|
|
+ secs = timeparse(arg)
|
|
|
+ if secs is None:
|
|
|
+ raise ArgumentTypeError('%r is not a valid duration' % arg)
|
|
|
+ return secs
|
|
|
+
|
|
|
def TimeDeltaType(arg):
|
|
|
- secs = timeparse(arg)
|
|
|
- if secs is None:
|
|
|
- raise ArgumentTypeError('%r is not a valid time range' % arg)
|
|
|
- return datetime.timedelta(seconds=timeparse(arg))
|
|
|
+ if arg.isdecimal():
|
|
|
+ secs = int(arg)
|
|
|
+ else:
|
|
|
+ secs = timeparse(arg)
|
|
|
+ if secs is None:
|
|
|
+ raise ArgumentTypeError('%r is not a valid time range' % arg)
|
|
|
+ return datetime.timedelta(seconds=secs)
|
|
|
|
|
|
|
|
|
def weighted_choice(values, weights):
|
|
@@ -229,14 +241,14 @@ def get_parser():
|
|
|
|
|
|
filters = p.add_argument_group('filters', 'Select only items that match '
|
|
|
'these conditions')
|
|
|
- filters.add_argument('--max-len', default=0, type=int,
|
|
|
+ filters.add_argument('--max-len', default=0, type=DurationType,
|
|
|
help='Exclude any audio that is longer '
|
|
|
'than MAX_LEN seconds')
|
|
|
filters.add_argument('--sort-by', default='no', type=str,
|
|
|
choices=('random', 'date'))
|
|
|
filters.add_argument('--reverse', default=False,
|
|
|
action='store_true', help='Reverse list order')
|
|
|
- filters.add_argument('--min-len', default=0, type=int,
|
|
|
+ filters.add_argument('--min-len', default=0, type=DurationType,
|
|
|
help='Exclude any audio that is shorter '
|
|
|
'than MIN_LEN seconds')
|
|
|
|