Skip to content

Commit

Permalink
argparse: remove streamlink import
Browse files Browse the repository at this point in the history
  • Loading branch information
back-to committed Dec 23, 2020
1 parent 3c03a3a commit a20281c
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions liveproxy/argparser.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
# -*- coding: utf-8 -*-
import re
import argparse
from textwrap import dedent

from streamlink_cli.argparser import (
ArgumentParser,
HelpFormatter,
num,
)

from liveproxy import __version__ as liveproxy_version

_ip_address_re = re.compile(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$')


def ip_address(value):
match = _ip_address_re.match(value)
if not match:
raise ValueError

return match.group(0)
FILE_OUTPUT_LIST = ['.m3u', '.m3u8', '.new', '.txt']


Expand All @@ -29,9 +13,29 @@ def file_output_list(value):
return value


parser = ArgumentParser(
def num(type, min=None, max=None):
def func(value):
value = type(value)
if min is not None and not (value > min):
raise argparse.ArgumentTypeError(
'{0} value must be more than {1} but is {2}'.format(
type.__name__, min, value
)
)
if max is not None and not (value <= max):
raise argparse.ArgumentTypeError(
'{0} value must be at most {1} but is {2}'.format(
type.__name__, max, value
)
)
return value

func.__name__ = type.__name__
return func


parser = argparse.ArgumentParser(
fromfile_prefix_chars='@',
formatter_class=HelpFormatter,
add_help=False,
usage='%(prog)s --host [HOST] --port [PORT]',
description=dedent('''
Expand Down Expand Up @@ -64,14 +68,14 @@ def file_output_list(value):
server.add_argument(
'--host',
metavar='HOST',
type=ip_address,
type=str,
default='127.0.0.1',
help='''
A fixed IP to use as a HOST.
Can also be used for `--file`
Default is 127.0.0.1.
Default is 127.0.0.1
'''
)
server.add_argument(
Expand All @@ -84,7 +88,7 @@ def file_output_list(value):
Can also be used for `--file`
Default is 53422.
Default is 53422
'''
)

Expand Down

0 comments on commit a20281c

Please sign in to comment.