shikharyashmaurya commited on
Commit
3b01476
1 Parent(s): e672f4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -3,6 +3,19 @@ import streamlit as st
3
  import os
4
  import google.generativeai as genai
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  from youtube_transcript_api import YouTubeTranscriptApi
7
 
8
  secret_key = os.getenv("SECRET_KEY")
@@ -17,7 +30,8 @@ within 250 words. Please provide the summary of the text given here: """
17
  ## getting the transcript data from yt videos
18
  def extract_transcript_details(youtube_video_url):
19
  try:
20
- video_id=youtube_video_url.split("=")[1]
 
21
 
22
  transcript_text=YouTubeTranscriptApi.get_transcript(video_id)
23
 
@@ -41,7 +55,8 @@ st.title("YouTube Transcript to Detailed Notes Converter")
41
  youtube_link = st.text_input("Enter YouTube Video Link:")
42
 
43
  if youtube_link:
44
- video_id = youtube_link.split("=")[1]
 
45
  print(video_id)
46
  st.image(f"http://img.youtube.com/vi/{video_id}/0.jpg", use_column_width=True)
47
 
 
3
  import os
4
  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
+
19
  from youtube_transcript_api import YouTubeTranscriptApi
20
 
21
  secret_key = os.getenv("SECRET_KEY")
 
30
  ## getting the transcript data from yt videos
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
 
 
55
  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