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,30 @@ def getVideoId(videoLink: str) -> str:
3030 try :
3131 parsed = urlparse (videoLink )
3232 host = (parsed .netloc or "" ).lower ()
33+
3334 if "youtu.be" in host :
3435 path = parsed .path .rstrip ("/" )
3536 if path :
3637 return path .split ("/" )[- 1 ]
38+
3739 if "youtube" in host or "youtube-nocookie" in host :
3840 qs = parse_qs (parsed .query )
41+
3942 if "v" in qs and qs ["v" ]:
4043 return qs ["v" ][0 ]
44+
4145 parts = [p for p in parsed .path .split ("/" ) if p ]
46+
4247 for i , p in enumerate (parts ):
43- if p in ("embed" , "v" ) and i + 1 < len (parts ):
48+ if p in ("embed" , "v" , "live" ) and i + 1 < len (parts ):
4449 return parts [i + 1 ]
50+
4551 if parts :
4652 return parts [- 1 ]
4753 core = videoLink .split ("?" )[0 ].split ("#" )[0 ].rstrip ("/" )
4854 if "/" in core :
4955 return core .split ("/" )[- 1 ]
5056 return core
57+
5158 except Exception :
5259 return videoLink
You can’t perform that action at this time.
0 commit comments