File size: 1,091 Bytes
abd44d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()