import gradio as gr import json, os import urllib.request # Replace 'YOUR_API_KEY' with your actual YouTube Data API key API_KEY = os.getenv('api_key') def get_youtube_id(youtube_url): if 'youtube.com' in youtube_url: video_id = youtube_url.split('v=')[-1] elif 'youtu.be' in youtube_url: video_id = youtube_url.split('/')[-1].split('?')[0] return video_id def check_cc_license(youtube_url): # Extract video ID from the URL video_id = get_youtube_id(youtube_url) # YouTube Data API URL to get video details api_url = f'https://www.googleapis.com/youtube/v3/videos?id={video_id}&part=status&key={API_KEY}' try: # Fetch video details response = urllib.request.urlopen(api_url) data = json.load(response) # Check the license status for item in data['items']: if item['status']['license'] == 'creativeCommon': return f"Yes." else: return f"No." except Exception as e: return f"An error occurred: {str(e)}" # Gradio interface interface = gr.Interface( fn=check_cc_license, inputs=gr.Textbox(label="YouTube Video URL"), outputs=gr.Textbox(label="Creative Commons license?") ) if __name__ == "__main__": interface.launch()