thejagstudio commited on
Commit
e82b670
1 Parent(s): cee3998

Update home/views.py

Browse files
Files changed (1) hide show
  1. home/views.py +300 -302
home/views.py CHANGED
@@ -1,302 +1,300 @@
1
- from django.shortcuts import render, redirect, HttpResponse
2
- from django.contrib.auth import authenticate, login, logout
3
- 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, movies
8
- import threading
9
- from django.conf import settings
10
- from django.views.decorators.csrf import csrf_exempt, csrf_protect
11
- from django.core.mail import send_mail
12
- import os
13
- from pydrive.auth import GoogleAuth
14
- from pydrive.drive import GoogleDrive
15
- import requests
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
26
- gauth.Refresh()
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
41
- def index(request):
42
- context = {
43
- 'user': request.user
44
- }
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':
83
- username = request.POST['username']
84
- password = request.POST['password']
85
- user = authenticate(request, username=username, password=password)
86
- if user is not None:
87
- login(request, user)
88
- messages.success(request, ('You have been logged in!'))
89
- # print('logged in')
90
- return redirect('index')
91
- else:
92
- messages.success(request, ('Error logging in - please try again.'))
93
- # print('error logging in')
94
- return render(request, 'login.html')
95
- return render(request, 'login.html')
96
-
97
-
98
- @csrf_exempt
99
- def sign_up(request):
100
- if request.method == 'POST':
101
- name = request.POST['name']
102
- email = request.POST['email']
103
- password = request.POST['password']
104
- password2 = request.POST['password1']
105
- user = authenticate(request, email=email, password=password)
106
- if user is not None and password == password2:
107
- login(request, user)
108
- messages.success(request, ('You have been logged in!'))
109
- # print('logged in')
110
- return redirect('index')
111
- elif user is None and password == password2:
112
- user = User.objects.create_user(username=email, email=email, password=password, first_name=name)
113
- user.save()
114
- messages.success(request, ('Created new user!'))
115
- login(request, user)
116
- folder = '1N3uD81zuXY_23esOFWRvN2Fp4zEbCrzy'
117
- new_folder = DRIVE.CreateFile({'title': name, 'mimeType': 'application/vnd.google-apps.folder', 'parents': [{'id': folder}]})
118
- new_folder.Upload()
119
- new_folder.InsertPermission({'type': 'user', 'value': email, 'role': 'writer'})
120
- dataObj = Userdata(user_id=request.user, folder=new_folder['id'])
121
- dataObj.save()
122
- # print('new user created')
123
- return redirect('index')
124
- else:
125
- pass
126
- return render(request, 'signup.html')
127
-
128
-
129
- @csrf_exempt
130
- @login_required
131
- def user_logout(request):
132
- logout(request)
133
- messages.success(request, ('You have been logged out!'))
134
- # print('logged out')
135
- return redirect('index')
136
-
137
-
138
- @csrf_exempt
139
- @login_required
140
- def upload(request):
141
- return render(request, 'upload.html')
142
-
143
-
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']
154
- title = request.POST['title']
155
- if title == '':
156
- title = file.name
157
- if file.name == '':
158
- return redirect('/upload/')
159
- folder_id = Userdata.objects.get(user_id=request.user).folder
160
- thread = threading.Thread(target=GoogleDriveUpload, args=(title, folder_id, file))
161
- thread.start()
162
- thread.join()
163
- return redirect('/upload/')
164
-
165
-
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
176
- list_files = DRIVE.ListFile({'q': "'%s' in parents and trashed=false" % folder_id}).GetList()
177
- for file in list_files:
178
- if file['title'] != 'Deleted' and file['title'] != 'DeletedFile' and file['mimeType'] != 'application/vnd.google-apps.folder':
179
- files.append([file['title'], file['embedLink'], file['id'], file["iconLink"].replace("/16/", "/32/"), file["webContentLink"]])
180
- elif file['mimeType'] == 'application/vnd.google-apps.folder':
181
- folders.append([file['title'], "/list/"+file['id'][::-1]])
182
- else:
183
- pass
184
- context = {'files': files, 'folders': folders, 'back': False}
185
- return render(request, 'list.html', context=context)
186
-
187
-
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
198
- list_files = DRIVE.ListFile({'q': "'%s' in parents and trashed=false" % folder_id}).GetList()
199
- for file in list_files:
200
- if file['title'] != 'Deleted' and file['mimeType'] != 'application/vnd.google-apps.folder':
201
- files.append([file['title'], file['embedLink'], file['id'], file["iconLink"].replace("/16/", "/32/"), file["webContentLink"]])
202
- elif file['mimeType'] == 'application/vnd.google-apps.folder':
203
- folders.append([file['title'], "/list/"+file['id'][::-1]])
204
- else:
205
- pass
206
- context = {'files': files, 'folders': folders, 'back': True}
207
- return render(request, 'list.html', context=context)
208
-
209
-
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})
220
- file.Trash()
221
- return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
222
-
223
-
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']
234
- new_name = data['new_name']
235
- file = DRIVE.CreateFile({'id': file_id})
236
- file.FetchMetadata(fields="title")
237
- file['title'] = new_name
238
- file.Upload()
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()
283
- if ipIn is None:
284
- new_entry = ip_address(ip=ip)
285
- new_entry.save()
286
- return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
287
-
288
-
289
- @login_required
290
- def godMode(request):
291
- if request.user.is_superuser:
292
- ips = ip_address.objects.all()
293
- ipF = ips[0].ip
294
- g = geocoder.ip(ipF)
295
- myAddress = g.latlng
296
- my_map1 = folium.Map(location=myAddress, zoom_start=12)
297
- for ip in ips:
298
- g = geocoder.ip(ip.ip)
299
- myAddress = g.latlng
300
- folium.Marker(myAddress).add_to(my_map1)
301
- my_map1.save('templates/godMode.html')
302
- return render(request, 'godMode.html')
 
1
+ from django.shortcuts import render, redirect, HttpResponse
2
+ from django.contrib.auth import authenticate, login, logout
3
+ 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, movies
8
+ import threading
9
+ from django.conf import settings
10
+ from django.views.decorators.csrf import csrf_exempt, csrf_protect
11
+ from django.core.mail import send_mail
12
+ import os
13
+ from pydrive.auth import GoogleAuth
14
+ from pydrive.drive import GoogleDrive
15
+ import requests
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
26
+ gauth.Refresh()
27
+ else:
28
+ gauth.Authorize()
29
+ DRIVE = GoogleDrive(gauth)
30
+
31
+
32
+ def GoogleDriveUpload(filename, folder, file):
33
+ file1 = DRIVE.CreateFile({'title': filename, 'parents': [{'id': folder}]})
34
+ file1.content = file
35
+ file1.Upload()
36
+
37
+
38
+ @csrf_exempt
39
+ def index(request):
40
+ context = {
41
+ 'user': request.user
42
+ }
43
+ return render(request, 'index.html', context=context)
44
+
45
+
46
+ @csrf_exempt
47
+ def movie(request):
48
+ all_movies = movies.objects.all()
49
+ context = {
50
+ 'movies': all_movies.values()
51
+ }
52
+ return render(request, 'movie.html', context=context)
53
+
54
+
55
+ @csrf_exempt
56
+ def movieDetail(request, id):
57
+
58
+ url = "https://api.themoviedb.org/3/movie/"+id+"?append_to_response=images,reviews,similar,recommendations,credits"
59
+ headers = {
60
+ 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI2MmY0Njg4NDE4ODI2MDNjODc1Y2EwZDMyMzE1NzkyZSIsInN1YiI6IjYyMDBlNmFmMWZkMzZmMDA2NmI5OTczNSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.mt_t8wqYYl5b8AlDy5npgiF7sbb8ZaDh_XPauDgMt8I',
61
+ 'accept': 'application/json'
62
+ }
63
+
64
+ response = requests.request("GET", url, headers=headers)
65
+ data = response.json()
66
+ try:
67
+ movie = movies.objects.get(tmdbId=id)
68
+ data["driveLink"] = movie["driveLink"]
69
+ except:
70
+ pass
71
+
72
+ context = {
73
+ 'data': data
74
+ }
75
+ return render(request, 'movieDetail.html', context=context)
76
+
77
+
78
+ @csrf_exempt
79
+ def user_login(request):
80
+ if request.method == 'POST':
81
+ username = request.POST['username']
82
+ password = request.POST['password']
83
+ user = authenticate(request, username=username, password=password)
84
+ if user is not None:
85
+ login(request, user)
86
+ messages.success(request, ('You have been logged in!'))
87
+ # print('logged in')
88
+ return redirect('index')
89
+ else:
90
+ messages.success(request, ('Error logging in - please try again.'))
91
+ # print('error logging in')
92
+ return render(request, 'login.html')
93
+ return render(request, 'login.html')
94
+
95
+
96
+ @csrf_exempt
97
+ def sign_up(request):
98
+ if request.method == 'POST':
99
+ name = request.POST['name']
100
+ email = request.POST['email']
101
+ password = request.POST['password']
102
+ password2 = request.POST['password1']
103
+ user = authenticate(request, email=email, password=password)
104
+ if user is not None and password == password2:
105
+ login(request, user)
106
+ messages.success(request, ('You have been logged in!'))
107
+ # print('logged in')
108
+ return redirect('index')
109
+ elif user is None and password == password2:
110
+ user = User.objects.create_user(username=email, email=email, password=password, first_name=name)
111
+ user.save()
112
+ messages.success(request, ('Created new user!'))
113
+ login(request, user)
114
+ folder = '1N3uD81zuXY_23esOFWRvN2Fp4zEbCrzy'
115
+ new_folder = DRIVE.CreateFile({'title': name, 'mimeType': 'application/vnd.google-apps.folder', 'parents': [{'id': folder}]})
116
+ new_folder.Upload()
117
+ new_folder.InsertPermission({'type': 'user', 'value': email, 'role': 'writer'})
118
+ dataObj = Userdata(user_id=request.user, folder=new_folder['id'])
119
+ dataObj.save()
120
+ # print('new user created')
121
+ return redirect('index')
122
+ else:
123
+ pass
124
+ return render(request, 'signup.html')
125
+
126
+
127
+ @csrf_exempt
128
+ @login_required
129
+ def user_logout(request):
130
+ logout(request)
131
+ messages.success(request, ('You have been logged out!'))
132
+ # print('logged out')
133
+ return redirect('index')
134
+
135
+
136
+ @csrf_exempt
137
+ @login_required
138
+ def upload(request):
139
+ return render(request, 'upload.html')
140
+
141
+
142
+ @csrf_exempt
143
+ @login_required
144
+ def uploader(request):
145
+ global gauth
146
+ if gauth.access_token_expired:
147
+ # Refresh them if expired
148
+ gauth.Refresh()
149
+ if request.method == 'POST':
150
+ folder = 'files/'
151
+ file = request.FILES['file']
152
+ title = request.POST['title']
153
+ if title == '':
154
+ title = file.name
155
+ if file.name == '':
156
+ return redirect('/upload/')
157
+ folder_id = Userdata.objects.get(user_id=request.user).folder
158
+ thread = threading.Thread(target=GoogleDriveUpload, args=(title, folder_id, file))
159
+ thread.start()
160
+ thread.join()
161
+ return redirect('/upload/')
162
+
163
+
164
+ @csrf_exempt
165
+ @login_required
166
+ def list(request):
167
+ global gauth
168
+ if gauth.access_token_expired:
169
+ # Refresh them if expired
170
+ gauth.Refresh()
171
+ files = []
172
+ folders = []
173
+ folder_id = Userdata.objects.get(user_id=request.user).folder
174
+ list_files = DRIVE.ListFile({'q': "'%s' in parents and trashed=false" % folder_id}).GetList()
175
+ for file in list_files:
176
+ if file['title'] != 'Deleted' and file['title'] != 'DeletedFile' and file['mimeType'] != 'application/vnd.google-apps.folder':
177
+ files.append([file['title'], file['embedLink'], file['id'], file["iconLink"].replace("/16/", "/32/"), file["webContentLink"]])
178
+ elif file['mimeType'] == 'application/vnd.google-apps.folder':
179
+ folders.append([file['title'], "/list/"+file['id'][::-1]])
180
+ else:
181
+ pass
182
+ context = {'files': files, 'folders': folders, 'back': False}
183
+ return render(request, 'list.html', context=context)
184
+
185
+
186
+ @csrf_exempt
187
+ @login_required
188
+ def folder_list(request, id):
189
+ global gauth
190
+ if gauth.access_token_expired:
191
+ # Refresh them if expired
192
+ gauth.Refresh()
193
+ files = []
194
+ folders = []
195
+ folder_id = id[::-1] # Userdata.objects.get(user_id=request.user).folder
196
+ list_files = DRIVE.ListFile({'q': "'%s' in parents and trashed=false" % folder_id}).GetList()
197
+ for file in list_files:
198
+ if file['title'] != 'Deleted' and file['mimeType'] != 'application/vnd.google-apps.folder':
199
+ files.append([file['title'], file['embedLink'], file['id'], file["iconLink"].replace("/16/", "/32/"), file["webContentLink"]])
200
+ elif file['mimeType'] == 'application/vnd.google-apps.folder':
201
+ folders.append([file['title'], "/list/"+file['id'][::-1]])
202
+ else:
203
+ pass
204
+ context = {'files': files, 'folders': folders, 'back': True}
205
+ return render(request, 'list.html', context=context)
206
+
207
+
208
+ @csrf_exempt
209
+ @login_required
210
+ def deleteFile(request):
211
+ global gauth
212
+ if gauth.access_token_expired:
213
+ # Refresh them if expired
214
+ gauth.Refresh()
215
+ if request.method == 'POST':
216
+ file_id = json.loads(request.body)['file_id']
217
+ file = DRIVE.CreateFile({'id': file_id})
218
+ file.Trash()
219
+ return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
220
+
221
+
222
+ @csrf_exempt
223
+ @login_required
224
+ def renameFile(request):
225
+ global gauth
226
+ if gauth.access_token_expired:
227
+ # Refresh them if expired
228
+ gauth.Refresh()
229
+ if request.method == 'POST':
230
+ data = json.loads(request.body)
231
+ file_id = data['file_id']
232
+ new_name = data['new_name']
233
+ file = DRIVE.CreateFile({'id': file_id})
234
+ file.FetchMetadata(fields="title")
235
+ file['title'] = new_name
236
+ file.Upload()
237
+ return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
238
+
239
+
240
+ def torrentDownloader(link):
241
+ import libtorrent as lt
242
+ ses = lt.session()
243
+ ses.listen_on(6881, 6891)
244
+ params = {
245
+ 'save_path': '/tmp/',
246
+ 'storage_mode': lt.storage_mode_t(2)
247
+ }
248
+ handle = lt.add_magnet_uri(ses, link, params)
249
+ ses.start_dht()
250
+ while (not handle.has_metadata()):
251
+ time.sleep(1)
252
+ while (handle.status().state != lt.torrent_status.seeding):
253
+ s = handle.status()
254
+ state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating']
255
+ 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]))
256
+ time.sleep(5)
257
+ with open('/tmp/'+handle.file_name, 'rb') as f:
258
+ file = f.read()
259
+ file1 = DRIVE.CreateFile({'title': handle.file_name, 'parents': [{'id': '1l6oqVFu-Ys025p7PKjIY0Nwgdr08MwlB'}]})
260
+ file1.content = file
261
+ file1.Upload()
262
+
263
+ print('Uploaded torrent file to drive from link: ', torrent_file.file_name)
264
+
265
+
266
+ @csrf_exempt
267
+ def movieDownloader(request):
268
+ if request.method == 'POST':
269
+ data = json.loads(request.body)
270
+ movie = data['movie']
271
+ tmdbId = data['tmdbId']
272
+ torrentLink = data['torrentLink']
273
+ t1 = threading.Thread(target=torrentDownloader, args=(torrentLink,))
274
+ t1.start()
275
+ return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
276
+
277
+
278
+ def ipGetter(request):
279
+ ip = request.GET.get('ip', '')
280
+ ipIn = ip_address.objects.filter(ip=ip).first()
281
+ if ipIn is None:
282
+ new_entry = ip_address(ip=ip)
283
+ new_entry.save()
284
+ return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
285
+
286
+
287
+ @login_required
288
+ def godMode(request):
289
+ if request.user.is_superuser:
290
+ ips = ip_address.objects.all()
291
+ ipF = ips[0].ip
292
+ g = geocoder.ip(ipF)
293
+ myAddress = g.latlng
294
+ my_map1 = folium.Map(location=myAddress, zoom_start=12)
295
+ for ip in ips:
296
+ g = geocoder.ip(ip.ip)
297
+ myAddress = g.latlng
298
+ folium.Marker(myAddress).add_to(my_map1)
299
+ my_map1.save('templates/godMode.html')
300
+ return render(request, 'godMode.html')