1234567891011121314151617181920212223242526272829303132333435363738 |
- import argparse
- from urllib3.util import parse_url
- desc = '''Starting program with parameters'''
- class ValidateUrl(argparse.Action):
- def __call__(self, parser, namespace, values, option_string=None):
- if not self.__validate(values):
- parser.error(f"Please enter a valid URL. Got: {values}")
- setattr(namespace, self.dest, values)
- def __validate(self, url) -> bool:
- try:
- result = parse_url(url)
- return all([result.scheme, result.netloc])
- except:
- return False
- class ArgParser:
- def __init__(self) -> None:
- self.parser = argparse.ArgumentParser(description=desc)
- self.parser.add_argument(
- "--link", default=None,
- help="Insert youtube video URL",
- action=ValidateUrl,
- type=str
- )
- self.parser.add_argument(
- "--download", default=False,
- help="Only downloading and tagging mp3",
- action="store_true"
- )
- self.args = self.parser.parse_args()
- print(self.args)
-
|