Spaces:
Runtime error
Runtime error
thejagstudio
commited on
Commit
•
fa839da
1
Parent(s):
4ef8e81
Update home/views.py
Browse files- home/views.py +100 -22
home/views.py
CHANGED
@@ -4,7 +4,7 @@ from django.contrib import messages
|
|
4 |
from django.contrib.auth.decorators import login_required
|
5 |
from django.contrib.auth.models import User
|
6 |
import json
|
7 |
-
from .models import Userdata, ip_address
|
8 |
import threading
|
9 |
from django.conf import settings
|
10 |
from django.views.decorators.csrf import csrf_exempt, csrf_protect
|
@@ -16,8 +16,10 @@ import requests
|
|
16 |
import geocoder
|
17 |
import folium
|
18 |
from oauth2client import client
|
|
|
|
|
19 |
gauth = GoogleAuth()
|
20 |
-
content =
|
21 |
gauth.credentials = client.Credentials.new_from_json(content)
|
22 |
if gauth.access_token_expired:
|
23 |
# Refresh them if expired
|
@@ -25,26 +27,14 @@ if gauth.access_token_expired:
|
|
25 |
else:
|
26 |
gauth.Authorize()
|
27 |
DRIVE = GoogleDrive(gauth)
|
|
|
|
|
28 |
|
29 |
|
30 |
-
def
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
@csrf_exempt
|
35 |
-
def movieDownloader(request):
|
36 |
-
if request.method == 'POST':
|
37 |
-
data = json.loads(request.body)
|
38 |
-
movie = data['movie']
|
39 |
-
tmdbId = data['tmdbId']
|
40 |
-
torrentLink = data['torrentLink']
|
41 |
-
print(movie,tmdbId)
|
42 |
-
try:
|
43 |
-
t1 = threading.Thread(target=torrentDownloader, args=(torrentLink,))
|
44 |
-
t1.start()
|
45 |
-
except:
|
46 |
-
pass
|
47 |
-
return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
|
48 |
|
49 |
|
50 |
@csrf_exempt
|
@@ -55,6 +45,38 @@ def index(request):
|
|
55 |
return render(request, 'index.html', context=context)
|
56 |
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
@csrf_exempt
|
59 |
def user_login(request):
|
60 |
if request.method == 'POST':
|
@@ -122,6 +144,10 @@ def upload(request):
|
|
122 |
@csrf_exempt
|
123 |
@login_required
|
124 |
def uploader(request):
|
|
|
|
|
|
|
|
|
125 |
if request.method == 'POST':
|
126 |
folder = 'files/'
|
127 |
file = request.FILES['file']
|
@@ -140,6 +166,10 @@ def uploader(request):
|
|
140 |
@csrf_exempt
|
141 |
@login_required
|
142 |
def list(request):
|
|
|
|
|
|
|
|
|
143 |
files = []
|
144 |
folders = []
|
145 |
folder_id = Userdata.objects.get(user_id=request.user).folder
|
@@ -158,6 +188,10 @@ def list(request):
|
|
158 |
@csrf_exempt
|
159 |
@login_required
|
160 |
def folder_list(request, id):
|
|
|
|
|
|
|
|
|
161 |
files = []
|
162 |
folders = []
|
163 |
folder_id = id[::-1] # Userdata.objects.get(user_id=request.user).folder
|
@@ -176,6 +210,10 @@ def folder_list(request, id):
|
|
176 |
@csrf_exempt
|
177 |
@login_required
|
178 |
def deleteFile(request):
|
|
|
|
|
|
|
|
|
179 |
if request.method == 'POST':
|
180 |
file_id = json.loads(request.body)['file_id']
|
181 |
file = DRIVE.CreateFile({'id': file_id})
|
@@ -186,6 +224,10 @@ def deleteFile(request):
|
|
186 |
@csrf_exempt
|
187 |
@login_required
|
188 |
def renameFile(request):
|
|
|
|
|
|
|
|
|
189 |
if request.method == 'POST':
|
190 |
data = json.loads(request.body)
|
191 |
file_id = data['file_id']
|
@@ -197,6 +239,44 @@ def renameFile(request):
|
|
197 |
return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
|
198 |
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
def ipGetter(request):
|
201 |
ip = request.GET.get('ip', '')
|
202 |
ipIn = ip_address.objects.filter(ip=ip).first()
|
@@ -220,5 +300,3 @@ def godMode(request):
|
|
220 |
folium.Marker(myAddress).add_to(my_map1)
|
221 |
my_map1.save('templates/godMode.html')
|
222 |
return render(request, 'godMode.html')
|
223 |
-
|
224 |
-
|
|
|
4 |
from django.contrib.auth.decorators import login_required
|
5 |
from django.contrib.auth.models import User
|
6 |
import json
|
7 |
+
from .models import Userdata, ip_address, movies
|
8 |
import threading
|
9 |
from django.conf import settings
|
10 |
from django.views.decorators.csrf import csrf_exempt, csrf_protect
|
|
|
16 |
import geocoder
|
17 |
import folium
|
18 |
from oauth2client import client
|
19 |
+
import time
|
20 |
+
|
21 |
gauth = GoogleAuth()
|
22 |
+
content = '{"access_token": "ya29.a0AXooCgtLK5HzYMtRs4R9J7FRZSGR3i5jUkeMeVhGjorlrgq_BupFi8d9upA2skYC5FofxUqo23Nivk_P_Hy8eRn0DWM3deSKoiWMhA3lsy05JVakD0vd2fPRaFOXfRV20jAEGt6ql9yy_0up3Y9z8u9yXZ28IUxRRZAHaCgYKASQSARISFQHGX2MipVyGD4fFFZJWXGvyd-sJnQ0171", "client_id": "895306463817-h14aujg3ohgptue5safg2d81530qs4c3.apps.googleusercontent.com", "client_secret": "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", "refresh_token": "1//0gsu0CorccmScCgYIARAAGBASNwF-L9IrF-TDYDXR_MTQGAGGf4fY4BBBSBUipsz_7c0B6HjmRYZV3uxPVU4CAJjqWoWBm0T4pxA", "token_expiry": "2024-05-25T11:14:56Z", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.a0AXooCgtLK5HzYMtRs4R9J7FRZSGR3i5jUkeMeVhGjorlrgq_BupFi8d9upA2skYC5FofxUqo23Nivk_P_Hy8eRn0DWM3deSKoiWMhA3lsy05JVakD0vd2fPRaFOXfRV20jAEGt6ql9yy_0up3Y9z8u9yXZ28IUxRRZAHaCgYKASQSARISFQHGX2MipVyGD4fFFZJWXGvyd-sJnQ0171", "expires_in": 3599, "refresh_token": "1//0gsu0CorccmScCgYIARAAGBASNwF-L9IrF-TDYDXR_MTQGAGGf4fY4BBBSBUipsz_7c0B6HjmRYZV3uxPVU4CAJjqWoWBm0T4pxA", "scope": "https://www.googleapis.com/auth/drive", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/drive"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}'
|
23 |
gauth.credentials = client.Credentials.new_from_json(content)
|
24 |
if gauth.access_token_expired:
|
25 |
# Refresh them if expired
|
|
|
27 |
else:
|
28 |
gauth.Authorize()
|
29 |
DRIVE = GoogleDrive(gauth)
|
30 |
+
# save to file
|
31 |
+
gauth.SaveCredentialsFile("mycreds.txt")
|
32 |
|
33 |
|
34 |
+
def GoogleDriveUpload(filename, folder, file):
|
35 |
+
file1 = DRIVE.CreateFile({'title': filename, 'parents': [{'id': folder}]})
|
36 |
+
file1.content = file
|
37 |
+
file1.Upload()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
@csrf_exempt
|
|
|
45 |
return render(request, 'index.html', context=context)
|
46 |
|
47 |
|
48 |
+
@csrf_exempt
|
49 |
+
def movie(request):
|
50 |
+
all_movies = movies.objects.all()
|
51 |
+
context = {
|
52 |
+
'movies': all_movies.values()
|
53 |
+
}
|
54 |
+
return render(request, 'movie.html', context=context)
|
55 |
+
|
56 |
+
|
57 |
+
@csrf_exempt
|
58 |
+
def movieDetail(request, id):
|
59 |
+
|
60 |
+
url = "https://api.themoviedb.org/3/movie/"+id+"?append_to_response=images,reviews,similar,recommendations,credits"
|
61 |
+
headers = {
|
62 |
+
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI2MmY0Njg4NDE4ODI2MDNjODc1Y2EwZDMyMzE1NzkyZSIsInN1YiI6IjYyMDBlNmFmMWZkMzZmMDA2NmI5OTczNSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.mt_t8wqYYl5b8AlDy5npgiF7sbb8ZaDh_XPauDgMt8I',
|
63 |
+
'accept': 'application/json'
|
64 |
+
}
|
65 |
+
|
66 |
+
response = requests.request("GET", url, headers=headers)
|
67 |
+
data = response.json()
|
68 |
+
try:
|
69 |
+
movie = movies.objects.get(tmdbId=id)
|
70 |
+
data["driveLink"] = movie["driveLink"]
|
71 |
+
except:
|
72 |
+
pass
|
73 |
+
|
74 |
+
context = {
|
75 |
+
'data': data
|
76 |
+
}
|
77 |
+
return render(request, 'movieDetail.html', context=context)
|
78 |
+
|
79 |
+
|
80 |
@csrf_exempt
|
81 |
def user_login(request):
|
82 |
if request.method == 'POST':
|
|
|
144 |
@csrf_exempt
|
145 |
@login_required
|
146 |
def uploader(request):
|
147 |
+
global gauth
|
148 |
+
if gauth.access_token_expired:
|
149 |
+
# Refresh them if expired
|
150 |
+
gauth.Refresh()
|
151 |
if request.method == 'POST':
|
152 |
folder = 'files/'
|
153 |
file = request.FILES['file']
|
|
|
166 |
@csrf_exempt
|
167 |
@login_required
|
168 |
def list(request):
|
169 |
+
global gauth
|
170 |
+
if gauth.access_token_expired:
|
171 |
+
# Refresh them if expired
|
172 |
+
gauth.Refresh()
|
173 |
files = []
|
174 |
folders = []
|
175 |
folder_id = Userdata.objects.get(user_id=request.user).folder
|
|
|
188 |
@csrf_exempt
|
189 |
@login_required
|
190 |
def folder_list(request, id):
|
191 |
+
global gauth
|
192 |
+
if gauth.access_token_expired:
|
193 |
+
# Refresh them if expired
|
194 |
+
gauth.Refresh()
|
195 |
files = []
|
196 |
folders = []
|
197 |
folder_id = id[::-1] # Userdata.objects.get(user_id=request.user).folder
|
|
|
210 |
@csrf_exempt
|
211 |
@login_required
|
212 |
def deleteFile(request):
|
213 |
+
global gauth
|
214 |
+
if gauth.access_token_expired:
|
215 |
+
# Refresh them if expired
|
216 |
+
gauth.Refresh()
|
217 |
if request.method == 'POST':
|
218 |
file_id = json.loads(request.body)['file_id']
|
219 |
file = DRIVE.CreateFile({'id': file_id})
|
|
|
224 |
@csrf_exempt
|
225 |
@login_required
|
226 |
def renameFile(request):
|
227 |
+
global gauth
|
228 |
+
if gauth.access_token_expired:
|
229 |
+
# Refresh them if expired
|
230 |
+
gauth.Refresh()
|
231 |
if request.method == 'POST':
|
232 |
data = json.loads(request.body)
|
233 |
file_id = data['file_id']
|
|
|
239 |
return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
|
240 |
|
241 |
|
242 |
+
def torrentDownloader(link):
|
243 |
+
import libtorrent as lt
|
244 |
+
ses = lt.session()
|
245 |
+
ses.listen_on(6881, 6891)
|
246 |
+
params = {
|
247 |
+
'save_path': '/tmp/',
|
248 |
+
'storage_mode': lt.storage_mode_t(2)
|
249 |
+
}
|
250 |
+
handle = lt.add_magnet_uri(ses, link, params)
|
251 |
+
ses.start_dht()
|
252 |
+
while (not handle.has_metadata()):
|
253 |
+
time.sleep(1)
|
254 |
+
while (handle.status().state != lt.torrent_status.seeding):
|
255 |
+
s = handle.status()
|
256 |
+
state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating']
|
257 |
+
print('%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s ' % (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]))
|
258 |
+
time.sleep(5)
|
259 |
+
with open('/tmp/'+handle.file_name, 'rb') as f:
|
260 |
+
file = f.read()
|
261 |
+
file1 = DRIVE.CreateFile({'title': handle.file_name, 'parents': [{'id': '1l6oqVFu-Ys025p7PKjIY0Nwgdr08MwlB'}]})
|
262 |
+
file1.content = file
|
263 |
+
file1.Upload()
|
264 |
+
|
265 |
+
print('Uploaded torrent file to drive from link: ', torrent_file.file_name)
|
266 |
+
|
267 |
+
|
268 |
+
@csrf_exempt
|
269 |
+
def movieDownloader(request):
|
270 |
+
if request.method == 'POST':
|
271 |
+
data = json.loads(request.body)
|
272 |
+
movie = data['movie']
|
273 |
+
tmdbId = data['tmdbId']
|
274 |
+
torrentLink = data['torrentLink']
|
275 |
+
t1 = threading.Thread(target=torrentDownloader, args=(torrentLink,))
|
276 |
+
t1.start()
|
277 |
+
return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
|
278 |
+
|
279 |
+
|
280 |
def ipGetter(request):
|
281 |
ip = request.GET.get('ip', '')
|
282 |
ipIn = ip_address.objects.filter(ip=ip).first()
|
|
|
300 |
folium.Marker(myAddress).add_to(my_map1)
|
301 |
my_map1.save('templates/godMode.html')
|
302 |
return render(request, 'godMode.html')
|
|
|
|