-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownup.py
128 lines (121 loc) · 4.05 KB
/
downup.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
# Name: Quiz 0.1.5
# Purpose: Download magnet links from url and upload completed file
#
# Author: cosmo.zavoda, NHTHEBEST
#
# Created: 25/09/2019
# Copyright: (c) cosmo.zavoda 2019 (The Drive)
# Licence: MIT
# Change Log:
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#Getting an error on HASH in magnet links its being a bitch
#
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# globals
#<<<<<<< HEAD
#=======
URL = "http://noserver.hadar.net.nz/thedrive/" #URL for downloading magnet link
#>>>>>>> dbce5bc6b8bc41261eb33f610150b20a88fbaaee
#global URL
DELFILE = True #Deletes downloaded data after uploading
#global DELFILE
SAVEPATH= "/tmp/stuff/" #Path to dumped data
#global SAVEPATH
UPDDELAY= 60 #Delay between database syncs
#global UPDDELAY
UPLOADCMD = "gdrive upload -p 1BMRqZT7fwv0X_ZzweNrePfd3pgqaJ8Il -r "
#global UPLOADCMD
HASH = "" #hash to download
#global HASH
#Trakers
TRAKERS_file = open("trakers.txt","r")
TRAKERS = TRAKERS_file.read()
#print(TRAKERS)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# modules
import libtorrent as lt
import time
import os
import requests
#-------------------------------------------------------------------------------
#loop for ever
#gethash
# if gethash returns nothing
#deley of UPDDELAY
#end if
# torrent
# upload
# delet
# update server of completion
#-------------------------------------------------------------------------------
# torrenter
def torrent():
ses = lt.session()
ses.listen_on(6881, 6891)
params = {
'save_path': SAVEPATH,
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'duplicate_is_error': True}
link = "magnet:?xt=urn:btih:"+HASH+TRAKERS
print(link)
handle = lt.add_magnet_uri(ses, link, params)
ses.start_dht()
print('downloading metadata...')
while (not handle.has_metadata()):
time.sleep(1)
print("#", end = '')
print('got metadata, starting torrent download...')
while (handle.status().state != lt.torrent_status.seeding):
s = handle.status()
state_str = ['queued', 'checking', 'downloading metadata', \
'downloading', 'finished', 'seeding', 'allocating']
# print '%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s %.3' % \
# (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
# s.num_peers, state_str[s.state], s.total_download/1000000)
print(s.progress*100,end="\r")
time.sleep(5)
#-------------------------------------------------------------------------------
#get the hash from server
def gethash():
output = requests.get(URL+"get.php?ISALT").text
print("hash is:"+output)
print("url reveived")
return output
#-------------------------------------------------------------------------------
#upload file to the drive
def upload():
os.system("rm /tmp/stuff/**/*.jpg /tmp/stuff/**/*.txt /tmp/stuff/**/*.sub /tmp/stuff/**/*.png /tmp/stuff/**/*.str")
os.system(UPLOADCMD+str(SAVEPATH)+"*")
print("file uploaded")
#-------------------------------------------------------------------------------
#delete uploaded data
def deldata():
if DELFILE:
os.system("rm -r "+SAVEPATH+"*")
print("File deleted")
#-------------------------------------------------------------------------------
# updates the server
def updateserver(hash):
requests.get(URL+"/rm.php?key=625c93b527b7da51aa10&hash="+hash)
print("server updated")
#-------------------------------------------------------------------------------
#main
while True:
hash = gethash()
if hash == "":
time.sleep(UPDDELAY)
else:
HASH = hash
torrent()
upload()
deldata()
updateserver(hash)
#-------------------------------------------------------------------------------