From 1e1e3c70629ff4d4cb47c7414fa8d1ae528c055f Mon Sep 17 00:00:00 2001 From: nathom Date: Wed, 16 Jun 2021 14:20:16 -0700 Subject: [PATCH] Add version parser Signed-off-by: nathom --- streamrip/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/streamrip/utils.py b/streamrip/utils.py index 1d27a76..a5016c5 100644 --- a/streamrip/utils.py +++ b/streamrip/utils.py @@ -361,3 +361,24 @@ def get_container(quality: int, source: str) -> str: return "AAC" return "MP3" + + +class Version: + def __init__(self, version: str): + self.value = tuple(map(int, version.split("."))) + + def __gt__(self, other) -> bool: + assert isinstance(other, Version) + for v1, v2 in zip(self.value, other.value): + if v1 > v2: + return True + elif v1 < v2: + return False + return False + + def __lt__(self, other) -> bool: + return not self.__gt__(other) and not self.__eq__(other) + + def __eq__(self, other) -> bool: + assert isinstance(other, Version) + return all(v1 == v2 for v1, v2 in zip(self.value, other.value))