Skip to content

Commit 50af46f

Browse files
Add files via upload
Differents Approachs of URL SHORTERNERS For Youtube URLS
1 parent f37310b commit 50af46f

3 files changed

+68
-0
lines changed

youtubePDF_Regex_Shorterner.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import re
2+
3+
def extract_youtube_video_id(url):
4+
"""Extracts the YouTube video ID from a given URL.
5+
6+
Args:
7+
url: A string containing the URL to a YouTube video.
8+
9+
Returns:
10+
A string containing the extracted YouTube video ID, or None if the URL is not
11+
a valid YouTube video URL.
12+
"""
13+
14+
regex = r'(?P<id>[a-zA-Z0-9-_]{11})'
15+
match = re.search(regex, url)
16+
if match:
17+
return match.group('id')
18+
else:
19+
return None
20+
21+
22+
link = input()
23+
24+
print(extract_youtube_video_id(link))

youtubeURL_Shorterner.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
3+
def extract_youtube_video_id(url):
4+
"""Extracts the YouTube video ID from a given URL.
5+
6+
Args:
7+
url: A string containing the URL to a YouTube video.
8+
9+
Returns:
10+
A string containing the extracted YouTube video ID, or None if the URL is not
11+
a valid YouTube video URL.
12+
"""
13+
14+
response = requests.get(url)
15+
video_id = response.headers['X-Goog-Cid']
16+
return video_id
17+
18+
19+
link = input()
20+
21+
print(extract_youtube_video_id(link))

youtubeURL_Shorterner_SplitVersion.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def extract_youtube_video_id(url):
2+
"""Extracts the YouTube video ID from a given URL.
3+
4+
Args:
5+
url: A string containing the URL to a YouTube video.
6+
7+
Returns:
8+
A string containing the extracted YouTube video ID, or None if the URL is not
9+
a valid YouTube video URL.
10+
"""
11+
12+
if "=v" in url:
13+
parts = url.split('=v')
14+
else:
15+
parts = url.split("/")
16+
17+
# Return the last part, which is the video ID.
18+
return parts[-1]
19+
20+
21+
link = input()
22+
23+
print(extract_youtube_video_id(link))

0 commit comments

Comments
 (0)