Skip to content

Commit 979be0d

Browse files
authored
add watch
1 parent cc8d2a7 commit 979be0d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

week-7/watch/watch.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import re
2+
3+
4+
def main():
5+
print(parse(input("HTML: ")))
6+
7+
8+
def parse(s):
9+
"""
10+
this function take an youtube iframe like and return short version of link
11+
"""
12+
13+
# - user walrus -
14+
# if src_link := re.search(r"^<iframe(?:.+)? src=\"(?:https?://)?(?:www\.)?youtube.com/embed/(\w+)\".?(?:.+)?></iframe>$", s):
15+
# return f"https://youtu.be/{src_link.group(1)}"
16+
# return None
17+
18+
19+
# - normal way -
20+
src_link = re.search(r"^<iframe(?:.+)? src=\"(?:https?://)?(?:www\.)?youtube.com/embed/(\w+)\".?(?:.+)?></iframe>$", s):
21+
if src_link:
22+
return f"https://youtu.be/{src_link.group(1)}"
23+
return None
24+
25+
26+
if __name__ == "__main__":
27+
main()

0 commit comments

Comments
 (0)