The "Run Python Code" in 0CodeKit model error

I ran this code in the terminal and it worked perfectly. The output was the transcript of the video I provided.

import subprocess
import sys

# Function to install a library using pip
def install(package):
    subprocess.check_call([sys.executable, "-m", "pip", "install", package])

# Install the required library
install("youtube_transcript_api")

from youtube_transcript_api import YouTubeTranscriptApi

def fetch_video_transcript(video_url):
    # Extracting Video ID from URL
    if "youtu.be" in video_url:
        video_id = video_url.split('/')[-1]
    else:  
        video_id = video_url.split('v=')[-1].split('&')[0]

    # Attempt to fetch the video transcript
    try:  
        transcript_list = YouTubeTranscriptApi.get_transcript(video_id)  
        full_transcript = '\n'.join([item['text'] for item in transcript_list])
        return full_transcript
    except Exception as e:
        return f"Failed to fetch transcript: {str(e)}"

# Main block to set the 'result' variable, as expected by the platform
video_url = "https://www.youtube.com/watch?v=u9m0nQ3-a58&ab_channel=JackRoberts"
result = {"data": fetch_video_transcript(video_url)}

However, when I ran it on Make with the module 0CodeKit, it said:

  • ResultCollection

    • data

Failed to fetch transcript: Could not retrieve a transcript for the video https://www.youtube.com/watch?v=u9m0nQ3-a58! This is most likely caused by: Subtitles are disabled for this video If you are sure that the described cause is not responsible for this error and that a transcript should be retrievable, please create an issue at Issues ¡ jdepoix/youtube-transcript-api ¡ GitHub. Please add which version of youtube_transcript_api you are using and provide the information needed to replicate the error. Also make sure that there are no open issues which already describe your problem!

Does anyone know how to fix this?

Hello @Adam_Tran and welcome to the Make Community!

It sort of sounds like youtube_transcript_api didn’t actually import.
Does 0CodeKit support installing packages like this?

1 Like

I followed the instructions from 0codekit: I added ‘youtube-transcript-api’ to the requirements section to install the package, but the result is still the same.
image

from youtube_transcript_api import YouTubeTranscriptApi

def fetch_video_transcript(video_url):
    # Extracting Video ID from URL
    if "youtu.be" in video_url:
        video_id = video_url.split('/')[-1]
    else:  
        video_id = video_url.split('v=')[-1].split('&')[0]

    # Attempt to fetch the video transcript
    try:  
        transcript_list = YouTubeTranscriptApi.get_transcript(video_id)  
        full_transcript = '\n'.join([item['text'] for item in transcript_list])
        return full_transcript
    except Exception as e:
        return f"Failed to fetch transcript: {str(e)}"

# Main block to set the 'result' variable, as expected by the platform
video_url = "{{2.data.`3a4nl`.value}}"
result ={'data': fetch_video_transcript(video_url)}

I see. I would maybe replicate the module in Postman and if that doesn’t work open a ticket with 0CodeKit.
If it works in Postman but not Make then maybe open a ticket with Make unless someone spots an issue with the module.

I just ran into the same issue. Unfortunately I wasn’t able to reproduce the call into postman directly since they auth method doesn’t work with me.

I just wrote to their slack channel for clarification. I think the access to youtube might be stopped since I am able to execute the same python code in my local dev box.

I’ve just stumbled upon a comment about the transcriptions from 0-CodeKit member:

@man0l, thanks for jumping in with this!

Same problem here.
I have this message:
You are using implicit requirements. This feature is deprecated, since it is inaccurate and unreliable, and will be removed in the future. Please specify the dependencies of your Python code manually. The ‘requirements’ field should be set to ‘[“youtube-transcript-api”]’.

Hello, you can try this approach:

1 Like