Spaces:
Runtime error
Runtime error
CognitiveScience
commited on
Commit
•
405af5a
1
Parent(s):
94cc7ec
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from bs4 import BeautifulSoup
|
3 |
+
import requests
|
4 |
+
|
5 |
+
|
6 |
+
def greet(link):
|
7 |
+
HEADER = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
|
8 |
+
#link = "https://youtu.be/vQUCSHUlN-k?si=FfIsODGjJDzIHOAS"
|
9 |
+
response = requests.get(link) #, headers=HEADER)
|
10 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
11 |
+
#print (soup.prettify())
|
12 |
+
|
13 |
+
titleSoupMeta = soup.find("meta", property="og:title")
|
14 |
+
videoTitle = titleSoupMeta["content"] if titleSoupMeta else "NotFound"
|
15 |
+
result = {}
|
16 |
+
result["views"] = soup.find("meta", itemprop="interactionCount")['content']
|
17 |
+
|
18 |
+
#soup=soup.prettify()
|
19 |
+
#viewSoupMeta = [line for line in soup.split('viewCount') if "views" in line]
|
20 |
+
|
21 |
+
response2=response.text[response.text.find("viewCount"):].split('"')[2]
|
22 |
+
# Store JSON data in API_Data
|
23 |
+
#for key in API_Data:{
|
24 |
+
# print(key,":", API_Data[key])
|
25 |
+
#}
|
26 |
+
#viewSoupMeta=viewSoupMeta[19:25]
|
27 |
+
##videoViews = viewSoupMeta["content"] if titleSoupMeta else "NotFound"
|
28 |
+
'''
|
29 |
+
if soup.find(attrs={"viewCount": "3363"}) == None:
|
30 |
+
viewSoupMeta = "3363" #soup.find(attrs={"class": "watch-view-count"}).text
|
31 |
+
else:
|
32 |
+
viewSoupMeta= soup
|
33 |
+
'''
|
34 |
+
#viewSoupMeta = API_Data #str(response).find("viewCount")
|
35 |
+
|
36 |
+
return result #soup.prettify()
|
37 |
+
|
38 |
+
|
39 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
40 |
+
iface.launch()
|