fix: started relying on own error handling instead of none

This commit is contained in:
Hazel 2024-04-25 14:50:19 +02:00
parent 85139d98a4
commit 07a933c625
2 changed files with 2 additions and 9 deletions

View File

@ -43,7 +43,7 @@ class SponsorBlock:
self.logger: logging.Logger = logging.Logger("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): if re.match(r"^[a-zA-Z0-9_-]{11}$", video):
return video.strip() return video.strip()
@ -56,9 +56,7 @@ class SponsorBlock:
query_stuff = parse_qs(url.query) query_stuff = parse_qs(url.query)
if "v" not in query_stuff: if "v" not in query_stuff:
if not self.silent:
raise SponsorBlockIdNotFoundError("No video id found in the url") raise SponsorBlockIdNotFoundError("No video id found in the url")
return None
else: else:
return query_stuff["v"][0] return query_stuff["v"][0]
@ -91,8 +89,6 @@ class SponsorBlock:
@error_handling(default=[]) @error_handling(default=[])
def get_segments(self, video: str) -> List[Segment]: def get_segments(self, video: str) -> List[Segment]:
video_id = self._get_video_id(video) video_id = self._get_video_id(video)
if video_id is None:
return []
# build query parameters # build query parameters
query = { query = {

View File

@ -16,9 +16,6 @@ class TestVideoIdParsing(unittest.TestCase):
with self.assertRaises(exceptions.SponsorBlockIdNotFoundError): with self.assertRaises(exceptions.SponsorBlockIdNotFoundError):
s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
s = SponsorBlock(silent=True)
self.assertEqual(s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), None)
def test_youtu_dot_be(self): def test_youtu_dot_be(self):
s = SponsorBlock() s = SponsorBlock()
self.assertEqual(s._get_video_id("https://youtu.be/" + MAGIC_ID), MAGIC_ID) self.assertEqual(s._get_video_id("https://youtu.be/" + MAGIC_ID), MAGIC_ID)