11from typing import Union , List
2+ from urllib .parse import urlparse , parse_qs
3+
24
35def getValue (source : dict , path : List [Union [str , int ]]) -> Union [str , int , dict , None ]:
46 value = source
@@ -8,7 +10,10 @@ def getValue(source: dict, path: List[Union[str, int]]) -> Union[str, int, dict,
810 if isinstance (key , str ):
911 if not isinstance (value , dict ):
1012 return None
11- value = value .get (key )
13+ if key in value :
14+ value = value [key ]
15+ else :
16+ return None
1217 elif isinstance (key , int ):
1318 if not isinstance (value , (list , tuple )):
1419 return None
@@ -25,29 +30,23 @@ def getVideoId(videoLink: str) -> str:
2530 try :
2631 parsed = urlparse (videoLink )
2732 host = (parsed .netloc or "" ).lower ()
28-
2933 if "youtu.be" in host :
30- path = parsed .path .strip ("/" )
34+ path = parsed .path .rstrip ("/" )
3135 if path :
32- return path .split ("?" )[0 ]
33-
36+ return path .split ("/" )[- 1 ]
3437 if "youtube" in host or "youtube-nocookie" in host :
3538 qs = parse_qs (parsed .query )
3639 if "v" in qs and qs ["v" ]:
3740 return qs ["v" ][0 ]
38-
3941 parts = [p for p in parsed .path .split ("/" ) if p ]
4042 for i , p in enumerate (parts ):
4143 if p in ("embed" , "v" ) and i + 1 < len (parts ):
4244 return parts [i + 1 ]
43-
4445 if parts :
4546 return parts [- 1 ]
46-
4747 core = videoLink .split ("?" )[0 ].split ("#" )[0 ].rstrip ("/" )
4848 if "/" in core :
4949 return core .split ("/" )[- 1 ]
50-
5150 return core
5251 except Exception :
5352 return videoLink
0 commit comments