input: Write a function to extract the titles of all YouTube videos from a given URL. The function should return a list of titles. If the URL is invalid or no titles are found, it should return an empty list.
  import requests
  import re
  
  def extract_youtube_titles(url):
      r = requests.get(url)
      if r.status_code != 200:
          return []
      titles = re.findall('<a href="/watch\?v=([^"]+)">(.+?)<\/a>', r.content.decode('utf-8'))
      return [title[1] for title in titles]
  
  assert extract_youtube_titles("https://www.youtube.com/user/Thexvid/videos")==["Title1", "Title2"]
  assert extract_youtube_titles("https://www.youtube.com/user/InvalidUser/videos")==[]
  assert extract_youtube_titles("https://invalidurl.com")==[]
  assert extract_youtube_titles("https://www.youtube.com/user/NoVideosUser/videos")==[]
output: import requests
  import re
  
  def extract_youtube_titles(url):
      r = requests.get(url)
      if r.status_code != 200:
          return []
      titles = re.findall('<a href="/watch\?v=([^"]+)">(.+?)<\/a>', r.content.decode('utf-8'))
      return [title[1] for title in titles]