File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,23 +30,29 @@ def getVideoId(videoLink: str) -> str:
3030 try :
3131 parsed = urlparse (videoLink )
3232 host = (parsed .netloc or "" ).lower ()
33+
3334 if "youtu.be" in host :
34- path = parsed .path .rstrip ("/" )
35+ path = parsed .path .strip ("/" )
3536 if path :
36- return path .split ("/" )[- 1 ]
37+ return path .split ("?" )[0 ]
38+
3739 if "youtube" in host or "youtube-nocookie" in host :
3840 qs = parse_qs (parsed .query )
3941 if "v" in qs and qs ["v" ]:
4042 return qs ["v" ][0 ]
43+
4144 parts = [p for p in parsed .path .split ("/" ) if p ]
4245 for i , p in enumerate (parts ):
4346 if p in ("embed" , "v" ) and i + 1 < len (parts ):
4447 return parts [i + 1 ]
48+
4549 if parts :
4650 return parts [- 1 ]
51+
4752 core = videoLink .split ("?" )[0 ].split ("#" )[0 ].rstrip ("/" )
4853 if "/" in core :
4954 return core .split ("/" )[- 1 ]
55+
5056 return core
5157 except Exception :
5258 return videoLink
You can’t perform that action at this time.
0 commit comments