Skip to content

Commit

Permalink
1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanBindez committed Oct 9, 2023
1 parent 4f1a71b commit 8ca98de
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
19 changes: 19 additions & 0 deletions pytubefix/colors.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 10 additions & 9 deletions pytubefix/exceptions.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,7 +12,6 @@ class PytubeFixError(Exception):
implementers code.
"""


class MaxRetriesExceeded(PytubeFixError):
"""Maximum number of retries exceeded."""

Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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
2 changes: 1 addition & 1 deletion pytubefix/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.4.1"
__version__ = "1.5.0"

if __name__ == "__main__":
print(__version__)
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
@@ -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)
ys = yt.streams.get_highest_resolution()
ys.download()

0 comments on commit 8ca98de

Please sign in to comment.