Skip to content

Commit

Permalink
fix: youtube issue
Browse files Browse the repository at this point in the history
  • Loading branch information
madawei2699 committed Apr 18, 2023
1 parent 14f7b62 commit 29b33d7
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/fetch_web_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ def scrape_website_by_phantomjscloud(url: str) -> str:

def get_youtube_transcript(video_id: str) -> str:
try:
srt = YouTubeTranscriptApi.get_transcript(video_id)
transcript = ""
for chunk in srt:
transcript = transcript + chunk["text"] + "\n"
transcripts = YouTubeTranscriptApi.list_transcripts(video_id)
transcript = next((transcript.fetch() for transcript in transcripts if transcript), None)
if transcript:
return "\n".join(chunk["text"] for chunk in transcript)
except Exception as e:
logging.warning(f"Error: {e} - {video_id}")
transcript = None
return transcript
return None

0 comments on commit 29b33d7

Please sign in to comment.