thejagstudio commited on
Commit
5df0c32
1 Parent(s): 1ab5b54

Update home/views.py

Browse files
Files changed (1) hide show
  1. home/views.py +31 -14
home/views.py CHANGED
@@ -27,27 +27,44 @@ else:
27
  DRIVE = GoogleDrive(gauth)
28
 
29
 
30
- def GoogleDriveUpload(filename, folder, file):
31
- file1 = DRIVE.CreateFile({'title': filename, 'parents': [{'id': folder}]})
32
- file1.content = file
33
- file1.Upload()
34
-
35
  def torrentDownloader(link):
36
- import asyncio
37
- from torrentp import TorrentDownloader
38
- print('Downloading torrent file from link: ', link)
39
- torrent_file = TorrentDownloader(link, '/tmp/')
40
- # Start the download process
41
- asyncio.run(torrent_file.start_download())
42
- print('Downloaded torrent file from link: ', link)
43
- with open('/tmp/'+torrent_file.file_name, 'rb') as f:
 
 
 
 
 
 
 
 
 
44
  file = f.read()
45
- file1 = DRIVE.CreateFile({'title': torrent_file.file_name, 'parents': [{'id': '1l6oqVFu-Ys025p7PKjIY0Nwgdr08MwlB'}]})
46
  file1.content = file
47
  file1.Upload()
 
48
  print('Uploaded torrent file to drive from link: ', torrent_file.file_name)
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  @csrf_exempt
52
  def movieDownloader(request):
53
  if request.method == 'POST':
 
27
  DRIVE = GoogleDrive(gauth)
28
 
29
 
 
 
 
 
 
30
  def torrentDownloader(link):
31
+ import libtorrent as lt
32
+ ses = lt.session()
33
+ ses.listen_on(6881, 6891)
34
+ params = {
35
+ 'save_path': '/tmp/',
36
+ 'storage_mode': lt.storage_mode_t(2)
37
+ }
38
+ handle = lt.add_magnet_uri(ses, link, params)
39
+ ses.start_dht()
40
+ while (not handle.has_metadata()):
41
+ time.sleep(1)
42
+ while (handle.status().state != lt.torrent_status.seeding):
43
+ s = handle.status()
44
+ state_str = ['queued', 'checking', 'downloading metadata', 'downloading', 'finished', 'seeding', 'allocating']
45
+ 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]))
46
+ time.sleep(5)
47
+ with open('/tmp/'+handle.file_name, 'rb') as f:
48
  file = f.read()
49
+ file1 = DRIVE.CreateFile({'title': handle.file_name, 'parents': [{'id': '1l6oqVFu-Ys025p7PKjIY0Nwgdr08MwlB'}]})
50
  file1.content = file
51
  file1.Upload()
52
+
53
  print('Uploaded torrent file to drive from link: ', torrent_file.file_name)
54
 
55
 
56
+ @csrf_exempt
57
+ def movieDownloader(request):
58
+ if request.method == 'POST':
59
+ data = json.loads(request.body)
60
+ movie = data['movie']
61
+ tmdbId = data['tmdbId']
62
+ torrentLink = data['torrentLink']
63
+ t1 = threading.Thread(target=torrentDownloader, args=(torrentLink,))
64
+ t1.start()
65
+ return HttpResponse(json.dumps({'status': 'success'}), content_type='application/json')
66
+
67
+
68
  @csrf_exempt
69
  def movieDownloader(request):
70
  if request.method == 'POST':