osaaso commited on
Commit
65732ea
·
1 Parent(s): 0d7bef1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -4,18 +4,21 @@ 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
  #soup=soup.prettify()
16
  #viewSoupMeta = [line for line in soup.split('viewCount') if "views" in line]
17
 
18
- response=response.text[response.text.find("viewCount"):].split('"')[2]
19
  # Store JSON data in API_Data
20
  #for key in API_Data:{
21
  # print(key,":", API_Data[key])
@@ -30,7 +33,7 @@ def greet(link):
30
  '''
31
  #viewSoupMeta = API_Data #str(response).find("viewCount")
32
 
33
- return response #soup.prettify()
34
 
35
 
36
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
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])
 
33
  '''
34
  #viewSoupMeta = API_Data #str(response).find("viewCount")
35
 
36
+ return results #soup.prettify()
37
 
38
 
39
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")