feat: added testing of video id parsing
This commit is contained in:
		| @@ -1,7 +1,29 @@ | ||||
| import requests | ||||
| from urllib.parse import urlparse, urlunparse, parse_qs | ||||
| import re | ||||
|  | ||||
| class SponsorBlockError(Exception): | ||||
|     pass | ||||
| from .exceptions import SponsorBlockError, SponsorBlockIdNotFoundError | ||||
|  | ||||
|  | ||||
| def _get_video_id(i: str, silent: bool = False) -> None: | ||||
|     # check with regex if i is already an id like r1Fa1iWJVEA | ||||
|     if re.match(r"^[a-zA-Z0-9_-]{11}$", i): | ||||
|         return i.strip() | ||||
|  | ||||
|     url = urlparse(url=i) | ||||
|  | ||||
|     if url.netloc == "youtu.be": | ||||
|         return url.path[1:] | ||||
|  | ||||
|     type_frag_list = url.path.split("/") | ||||
|              | ||||
|     query_stuff = parse_qs(url.query) | ||||
|     if "v" not in query_stuff: | ||||
|         if not silent: | ||||
|             raise SponsorBlockIdNotFoundError("No video id found in the url") | ||||
|         return None | ||||
|     else: | ||||
|         return query_stuff["v"][0] | ||||
|  | ||||
|  | ||||
| class SponsorBlock: | ||||
|   | ||||
							
								
								
									
										6
									
								
								python_sponsorblock/exceptions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								python_sponsorblock/exceptions.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| class SponsorBlockError(Exception): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| class SponsorBlockIdNotFoundError(SponsorBlockError): | ||||
|     pass | ||||
		Reference in New Issue
	
	Block a user