selim-ba commited on
Commit
7254beb
·
verified ·
1 Parent(s): 92a60ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -132,8 +132,27 @@ class SuperSmartAgent:
132
  ###################
133
 
134
  def contains_youtube_url(text):
 
135
  return re.search(r"(https?://)?(www\.)?(youtube\.com|youtu\.be)/", text) is not None
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  def check_special_tools(state):
138
  q = state["question"].lower()
139
 
 
132
  ###################
133
 
134
  def contains_youtube_url(text):
135
+ # This regex is good for identifying the presence of a YouTube URL
136
  return re.search(r"(https?://)?(www\.)?(youtube\.com|youtu\.be)/", text) is not None
137
 
138
+ def extract_youtube_url(text):
139
+ # A more focused regex to *extract* the full YouTube URL
140
+ # This pattern attempts to match common YouTube URL formats and capture the entire URL
141
+ youtube_regex = (
142
+ r'(https?://)?(www\.)?'
143
+ '(?:youtube\.com|youtu\.be)/' # Non-capturing group for domain
144
+ '(?:watch\?v=|embed/|v/|.+\?v=)?' # Non-capturing group for path
145
+ '([a-zA-Z0-9_-]{11})' # Capturing group for the 11-character video ID
146
+ '(?:[&?].*)?' # Optional: matches any query parameters after the video ID
147
+ )
148
+ match = re.search(youtube_regex, text)
149
+ if match:
150
+ # Reconstruct the standard YouTube watch URL from the video ID
151
+ video_id = match.group(1) # The 11-character video ID
152
+ return f"https://www.youtube.com/watch?v={video_id}"
153
+ return None
154
+
155
+
156
  def check_special_tools(state):
157
  q = state["question"].lower()
158