Created
July 3, 2020 03:01
-
-
Save XWilliamY/b8edf30eb8cf42858a3828e2735aeaa2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlparse, parse_qs | |
# adopted from: | |
# https://stackoverflow.com/questions/45579306/get-youtube-video-url-or-youtube-video-id-from-a-string-using-regex | |
def get_id(url): | |
u_pars = urlparse(url) | |
quer_v = parse_qs(u_pars.query).get('v') | |
if quer_v: | |
return quer_v[0] | |
pth = u_pars.path.split('/') | |
if pth: | |
return pth[-1] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment