Queer European MD passionate about IT

watch.py 378 B

1234567891011121314151617181920
  1. import re
  2. youtube_regex = re.compile(r"<iframe.*https?://(?:www\.)?youtube\.com/embed/(\w+).*</iframe>")
  3. def main():
  4. print(parse(input("HTML: ")))
  5. def parse(s):
  6. video_id = youtube_regex.search(s)
  7. if video_id:
  8. video_id = video_id.groups()[0]
  9. else:
  10. return None
  11. return f"https://youtu.be/{video_id}"
  12. if __name__ == "__main__":
  13. main()