From 07a933c6259228cd1e1ff6fb629d60654c7e1553 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 25 Apr 2024 14:50:19 +0200 Subject: [PATCH] fix: started relying on own error handling instead of none --- python_sponsorblock/__init__.py | 8 ++------ tests/test_video_id.py | 3 --- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/python_sponsorblock/__init__.py b/python_sponsorblock/__init__.py index e6bd7eb..32e02f7 100644 --- a/python_sponsorblock/__init__.py +++ b/python_sponsorblock/__init__.py @@ -43,7 +43,7 @@ class SponsorBlock: self.logger: logging.Logger = logging.Logger("SponsorBlock") - def _get_video_id(self, video: str) -> Optional[str]: + def _get_video_id(self, video: str) -> str: if re.match(r"^[a-zA-Z0-9_-]{11}$", video): return video.strip() @@ -56,9 +56,7 @@ class SponsorBlock: query_stuff = parse_qs(url.query) if "v" not in query_stuff: - if not self.silent: - raise SponsorBlockIdNotFoundError("No video id found in the url") - return None + raise SponsorBlockIdNotFoundError("No video id found in the url") else: return query_stuff["v"][0] @@ -91,8 +89,6 @@ class SponsorBlock: @error_handling(default=[]) def get_segments(self, video: str) -> List[Segment]: video_id = self._get_video_id(video) - if video_id is None: - return [] # build query parameters query = { diff --git a/tests/test_video_id.py b/tests/test_video_id.py index d03285b..64feef0 100644 --- a/tests/test_video_id.py +++ b/tests/test_video_id.py @@ -16,9 +16,6 @@ class TestVideoIdParsing(unittest.TestCase): with self.assertRaises(exceptions.SponsorBlockIdNotFoundError): s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") - s = SponsorBlock(silent=True) - self.assertEqual(s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), None) - def test_youtu_dot_be(self): s = SponsorBlock() self.assertEqual(s._get_video_id("https://youtu.be/" + MAGIC_ID), MAGIC_ID)