From 8ca98deddf3f41bdece16ac4eabbf97f358e3375 Mon Sep 17 00:00:00 2001 From: JuanBindez Date: Mon, 9 Oct 2023 10:05:33 -0300 Subject: [PATCH] 1.5.0 --- pytubefix/colors.py | 19 +++++++++++++++++++ pytubefix/exceptions.py | 19 ++++++++++--------- pytubefix/version.py | 2 +- test.py | 6 +++--- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pytubefix/colors.py b/pytubefix/colors.py index 27c932e..c9a8bd0 100644 --- a/pytubefix/colors.py +++ b/pytubefix/colors.py @@ -1,5 +1,24 @@ """Colors to be used in cli""" + +class Color: + GREEN = '\033[92m' + LIGTH_GREEN = '\033[1;92m' + RED = '\033[91m' + YELLOW = '\033[93m' + BLUE = '\033[1;34m' + MAGENTA = '\033[1;35m' + BOLD = '\033[;1m' + CYAN = '\033[1;36m' + LIGHT_CYAN = '\033[1;96m' + LIGTH_GREY = '\033[1;37m' + DARK_GREY = '\033[1;90m' + BLACK = '\033[1;30m' + WHITE = '\033[1;97m' + INVERTE = '\033[;7m' + RESET = '\033[0m' + + GREEN = '\033[92m' LIGTH_GREEN = '\033[1;92m' RED = '\033[91m' diff --git a/pytubefix/exceptions.py b/pytubefix/exceptions.py index 15d8f34..df997d9 100644 --- a/pytubefix/exceptions.py +++ b/pytubefix/exceptions.py @@ -1,6 +1,8 @@ """Library specific exception definitions.""" from typing import Pattern, Union +from .colors import Color +c = Color() class PytubeFixError(Exception): """Base pytube exception that all others inherit. @@ -10,7 +12,6 @@ class PytubeFixError(Exception): implementers code. """ - class MaxRetriesExceeded(PytubeFixError): """Maximum number of retries exceeded.""" @@ -33,7 +34,7 @@ def __init__(self, caller: str, pattern: Union[str, Pattern]): :param str pattern: Pattern that failed to match """ - super().__init__(f"{caller}: could not find match for {pattern}") + super().__init__(c.RED + f"{caller}: could not find match for {pattern}" + c.RESET) self.caller = caller self.pattern = pattern @@ -50,7 +51,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} is unavailable' + return c.RED + f'{self.video_id} is unavailable' + c.RESET class AgeRestrictedError(VideoUnavailable): @@ -65,7 +66,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f"{self.video_id} is age restricted, and can't be accessed without logging in." + return c.RED + f"Video ID = {self.video_id}: is age restricted, and can't be accessed without logging in." + c.RESET class LiveStreamError(VideoUnavailable): @@ -80,7 +81,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} is streaming live and cannot be loaded' + return c.RED + f'{self.video_id} is streaming live and cannot be loaded' + c.RESET class VideoPrivate(VideoUnavailable): @@ -94,7 +95,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} is a private video' + return c.RED + f'{self.video_id} is a private video' + c.RESET class RecordingUnavailable(VideoUnavailable): @@ -108,7 +109,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} does not have a live stream recording available' + return c.RED + f'{self.video_id} does not have a live stream recording available' + c.RESET class MembersOnly(VideoUnavailable): @@ -128,7 +129,7 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} is a members-only video' + return c.RED + f'{self.video_id} is a members-only video' + c.RESET class VideoRegionBlocked(VideoUnavailable): @@ -142,4 +143,4 @@ def __init__(self, video_id: str): @property def error_string(self): - return f'{self.video_id} is not available in your region' + return c.RED + f'{self.video_id} is not available in your region' + c.RESET diff --git a/pytubefix/version.py b/pytubefix/version.py index 38a30c8..f3f26e2 100644 --- a/pytubefix/version.py +++ b/pytubefix/version.py @@ -1,4 +1,4 @@ -__version__ = "1.4.1" +__version__ = "1.5.0" if __name__ == "__main__": print(__version__) diff --git a/test.py b/test.py index 5988040..84d8d6e 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,10 @@ from pytubefix import YouTube from pytubefix.cli import on_progress -url = input("URL >") +url = input("url >") yt = YouTube(url, on_progress_callback = on_progress) print(yt.title) -ys = yt.streams.get_audio_only() -ys.download(mp3=True) \ No newline at end of file +ys = yt.streams.get_highest_resolution() +ys.download() \ No newline at end of file