Skip to content

Commit f3de7af

Browse files
committed
Add YouTube Link Finder
1 parent 0a5a169 commit f3de7af

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

Python/MilitaryTime-substringSolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
########## Solution ##########
2626
##############################
2727

28-
# This solution uses regex
28+
# This solution uses substrings
2929

3030
# Take Sololearn input
3131
standardTime = input()

Python/YouTubeLinkFinder.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# YouTube Link Finder +50 XP
2+
3+
##############################
4+
#### Problem Description #####
5+
##############################
6+
7+
# You and your friends like to share YouTube links all throughout the day. You want to keep track of all the videos you watch in your own personal notepad, but you find that keeping the entire link is unnecessary.
8+
# Keep the video ID (the combination of letters and numbers at the end of the link) in your notepad to slim down the URL.
9+
10+
# Task:
11+
# Create a program that parses through a link, extracts and outputs the YouTube video ID.
12+
13+
# Input Format:
14+
# A string containing the URL to a YouTube video. The format of the string can be in "https://www.youtube.com/watch?v=kbxkq_w51PM" or the shortened "https://youtu.be/KMBBjzp5hdc" format.
15+
16+
# Output Format:
17+
# A string containing the extracted YouTube video id.
18+
19+
# Sample Input:
20+
# https://www.youtube.com/watch?v=RRW2aUSw5vU
21+
22+
# Sample Output:
23+
# RWW2aUSwvU
24+
25+
##############################
26+
########## Solution ##########
27+
##############################
28+
29+
# Take Sololearn input
30+
link = input()
31+
32+
# Find the start location of the video id based on the two different link formats. Find a section of the link that identifies the format, and then add the appropriate number of characters to the start of the video id.
33+
if link.find('.be/') > -1:
34+
linkStart = link.find('.be/') + 4
35+
else:
36+
linkStart = link.find('?v=') + 3
37+
38+
# print the link by substringing from the start of the link through the end of the string. This works by not including a specified number of characters so the substring goes through the end.
39+
print(link[linkStart:])

0 commit comments

Comments
 (0)