-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (69 loc) · 2.27 KB
/
main.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python
import json
import requests
from bs4 import BeautifulSoup
with open("config.json", 'r') as f:
pay_load = json.load(f)
class udvash():
def __init__(self):
url = input("url:")
if "ViewClassNote" in url:
self.class_notes(url)
elif "ViewRecording" in url:
self.video(url)
def video(self, url):
soup = self.webpage(url)
video_link = soup.select("#video_1 > source:nth-child(1)")[0]["src"]
# print(video_link)
if video_link == "":
print("an error occurred!")
return
dir = input("Where to download:")
if dir == "":
dir = "."
if dir[-1] != '/':
dir = dir + "/"
print("got video link!")
Headers = {
'Accept': '*/*',
'Referer': 'https://online.udvash-unmesh.com/',
'Connection': 'keep-alive'
}
fname = str(input("file name:"))
if fname == "":
fname = str(video_link).split('/')[-1]
fname = dir + fname + ".mp4"
print("downloading")
with open(fname, 'wb') as video:
response = requests.get(video_link, headers=Headers)
video.write(response.content)
print(fname, '(done!)')
def class_notes(self, url):
soup = self.webpage(url)
fname = soup.select(".col-md-6")[0].text
link = soup.select(".btn")[0]["href"]
if link == "":
print("an error occurred!")
return
dir = input("Where to download:")
if dir == "":
dir = "."
if dir[-1] != '/':
dir = dir + "/"
fname = dir + str(fname) + ".pdf"
print("downloading")
response = requests.get(link)
with open(fname, 'wb') as video:
video.write(response.content)
print(fname, '(done!)')
def webpage(self, url):
print("Fetching data")
Headers = {
'User-Agent': pay_load[0]["user_agent"],
'Accept': '*/*',
'Referer': 'https://online.udvash-unmesh.com/Routine'
}
response = requests.get(url, headers=Headers, cookies=pay_load[1])
soup = BeautifulSoup(response.text, features='lxml')
return soup
udvash()