Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
import urllib.request
|
4 |
+
|
5 |
+
# Replace 'YOUR_API_KEY' with your actual YouTube Data API key
|
6 |
+
API_KEY = os.getenv('api_key')
|
7 |
+
|
8 |
+
def check_cc_license(youtube_url):
|
9 |
+
# Extract video ID from the URL
|
10 |
+
video_id = youtube_url.split('v=')[-1]
|
11 |
+
|
12 |
+
# YouTube Data API URL to get video details
|
13 |
+
api_url = f'https://www.googleapis.com/youtube/v3/videos?id={video_id}&part=status&key={API_KEY}'
|
14 |
+
|
15 |
+
try:
|
16 |
+
# Fetch video details
|
17 |
+
response = urllib.request.urlopen(api_url)
|
18 |
+
data = json.load(response)
|
19 |
+
|
20 |
+
# Check the license status
|
21 |
+
for item in data['items']:
|
22 |
+
if item['status']['license'] == 'creativeCommon':
|
23 |
+
return f"Yes."
|
24 |
+
else:
|
25 |
+
return f"No."
|
26 |
+
|
27 |
+
except Exception as e:
|
28 |
+
return f"An error occurred: {str(e)}"
|
29 |
+
|
30 |
+
# Gradio interface
|
31 |
+
interface = gr.Interface(
|
32 |
+
fn=check_cc_license,
|
33 |
+
inputs=gr.Textbox(label="YouTube Video URL"),
|
34 |
+
outputs=gr.Textbox(label="Creative Commons license?")
|
35 |
+
)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
interface.launch()
|