123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import argparse
- from urllib3.util import parse_url
- desc = "Get video from youtube, extract audio and save as mp3 with tags and \
- cover. Then it sends mp3 to telegram channel with descrption of tags"
- class ValidateUrl(argparse.Action):
- def __call__(self, parser, namespace, values, option_string=None):
- if not self.__validate(values):
- parser.error(f"Invalid URL. Please provide a link to youtube \
- video.\nGot: {values}")
- setattr(namespace, self.dest, values)
- def __validate(self, url) -> bool:
- try:
- result = parse_url(url)
- return all([result.scheme, result.netloc])
- except Exception:
- return False
- class ArgParser:
- def __init__(self) -> None:
- self.parser = argparse.ArgumentParser(description=desc)
- self.parser.add_argument(
- "-l", "--link", default=None,
- help="Insert youtube video URL",
- action=ValidateUrl,
- type=str
- )
- self.parser.add_argument(
- "-s", "--shift", default=0,
- help="Insert number to shift list of videos for x positions",
- type=int
- )
- self.parser.add_argument(
- "-d", "--download", default=False,
- help="Only downloading and tagging mp3",
- action="store_true"
- )
- self.args = self.parser.parse_args()
|