INNER CODE UNIT · Python

get_transcript

essamamdani/search-result-scraper-markdown · main.py:123

def get_transcript(video_id: str, format: str = "markdown"):
    try:
        transcript_list = YouTubeTranscriptApi.get_transcript(video_id, proxies=get_proxies(without=True))
        transcript = " ".join([entry['text'] for entry in transcript_list])

        # Fetch the title from the video page
        video_url = f"https://www.youtube.com/watch?v={video_id}"
        video_page = fetch_content(video_url)
        title = extract_title(video_page)

        if format == "json":
            return JSONResponse({"url": video_url, "title": title, "transcript": transcript})
        return PlainTextResponse(f"Title: {title}\n\nURL Source: {video_url}\n\nTranscript:\n{transcript}")
    except Exception as e:
        return PlainTextResponse(f"Failed to retrieve transcript: {str(e)}")

def extract_title(html_content):
    if html_content:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…