Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
import urllib.request | |
# Replace 'YOUR_API_KEY' with your actual YouTube Data API key | |
API_KEY = os.getenv('api_key') | |
def check_cc_license(youtube_url): | |
# Extract video ID from the URL | |
video_id = youtube_url.split('v=')[-1] | |
# 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() | |