python-sponsorblock/tests/test_video_id.py

41 lines
1.2 KiB
Python
Raw Normal View History

import unittest
2024-04-24 10:35:22 +00:00
from python_sponsorblock import SponsorBlock, exceptions
MAGIC_ID = "dQw4w9WgXcQ"
class TestVideoIdParsing(unittest.TestCase):
def test_already_parsed_id(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
self.assertEqual(s._get_video_id(MAGIC_ID), MAGIC_ID)
def test_non_existing_id(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
with self.assertRaises(exceptions.SponsorBlockIdNotFoundError):
2024-04-24 10:35:22 +00:00
s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
2024-04-24 10:35:22 +00:00
s = SponsorBlock(silent=True)
self.assertEqual(s._get_video_id("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), None)
def test_youtu_dot_be(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
self.assertEqual(s._get_video_id("https://youtu.be/" + MAGIC_ID), MAGIC_ID)
def test_youtube_dot_com(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
self.assertEqual(s._get_video_id("https://www.youtube.com/watch?v=" + MAGIC_ID), MAGIC_ID)
def test_invidious(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
self.assertEqual(s._get_video_id("https://invidio.us/watch?v=" + MAGIC_ID), MAGIC_ID)
def test_piped(self):
2024-04-24 10:35:22 +00:00
s = SponsorBlock()
self.assertEqual(s._get_video_id("https://piped.video/watch?v=" + MAGIC_ID), MAGIC_ID)
if __name__ == "__main__":
unittest.main()