shikharyashmaurya commited on
Commit
42484c0
1 Parent(s): 00943e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -5,14 +5,21 @@ import google.generativeai as genai
5
 
6
  import re
7
 
8
- def extract_video_id(url):
9
- # Regular expression pattern to match the video ID
10
- pattern = r'(?<=/|v=|vi/|youtu\.be/|embed/)[^#&?]*'
11
- match = re.search(pattern, url)
12
- if match:
13
- return match.group(0)
14
- else:
15
- return None
 
 
 
 
 
 
 
16
 
17
 
18
 
@@ -31,7 +38,8 @@ within 250 words. Please provide the summary of the text given here: """
31
  def extract_transcript_details(youtube_video_url):
32
  try:
33
  # video_id=youtube_video_url.split("=")[1]
34
- video_id=extract_video_id(youtube_link)
 
35
 
36
  transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
37
 
@@ -56,7 +64,8 @@ youtube_link = st.text_input("Enter YouTube Video Link:")
56
 
57
  if youtube_link:
58
  # video_id = youtube_link.split("=")[1]
59
- video_id=extract_video_id(youtube_link)
 
60
  print(video_id)
61
  st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
62
 
 
5
 
6
  import re
7
 
8
+ # def extract_video_id(url):
9
+ # # Regular expression pattern to match the video ID
10
+ # pattern = r'(?<=/|v=|vi/|youtu\.be/|embed/)[^#&?]*'
11
+ # match = re.search(pattern, url)
12
+ # if match:
13
+ # return match.group(0)
14
+ # else:
15
+ # return None
16
+
17
+ def parseYoutubeURL(url):
18
+ url=str(url)
19
+ data = re.findall(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url)
20
+ if data:
21
+ return data[0]
22
+ return ""
23
 
24
 
25
 
 
38
  def extract_transcript_details(youtube_video_url):
39
  try:
40
  # video_id=youtube_video_url.split("=")[1]
41
+ # video_id=extract_video_id(youtube_link)
42
+ video_id=parseYoutubeUR(youtube_link)
43
 
44
  transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
45
 
 
64
 
65
  if youtube_link:
66
  # video_id = youtube_link.split("=")[1]
67
+ # video_id=extract_video_id(youtube_link)
68
+ video_id=parseYoutubeUR(youtube_link)
69
  print(video_id)
70
  st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
71