Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
link = "magnet:?xt=urn:btih:SXAUXLMEOA756COGWBPNQ5WWNR72N4ZB&dn=Contact%20%232%20480p.mp4&xl=1530546742&tr=h"
|
2 |
+
isSome = False
|
3 |
+
|
4 |
+
import libtorrent as lt
|
5 |
+
import time
|
6 |
+
import datetime
|
7 |
+
|
8 |
+
ses = lt.session()
|
9 |
+
ses.listen_on(6881, 6891)
|
10 |
+
params = {
|
11 |
+
'save_path': '~/',
|
12 |
+
'storage_mode': lt.storage_mode_t(2)}
|
13 |
+
|
14 |
+
def download(torrent):
|
15 |
+
handle = lt.add_magnet_uri(ses, torrent, params)
|
16 |
+
ses.start_dht()
|
17 |
+
|
18 |
+
begin = time.time()
|
19 |
+
print(datetime.datetime.now())
|
20 |
+
|
21 |
+
print ('Получение метаданных...')
|
22 |
+
while (not handle.has_metadata()):
|
23 |
+
time.sleep(1)
|
24 |
+
print ('Метаданные получены, начинается торрент-загрузка...')
|
25 |
+
|
26 |
+
print('Запуск', handle.name())
|
27 |
+
|
28 |
+
while (True):
|
29 |
+
s = handle.status()
|
30 |
+
state_str = ['queued', 'checking', 'downloading metadata', \
|
31 |
+
'downloading', 'finished', 'seeding', 'allocating']
|
32 |
+
print ('%.2f%% информация (загрузка: %.1f kb/s отправка: %.1f kB/s пиры: %d) %s ' % \
|
33 |
+
(s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, \
|
34 |
+
s.num_peers, state_str[s.state]))
|
35 |
+
time.sleep(5)
|
36 |
+
|
37 |
+
end = time.time()
|
38 |
+
print(handle.name(), 'Загрузка кончена')
|
39 |
+
|
40 |
+
print('Затрачено времени: ', int((end-begin)//60), 'минут ',
|
41 |
+
int((end-begin)%60), 'секунд')
|
42 |
+
|
43 |
+
print(datetime.datetime.now())
|
44 |
+
|
45 |
+
|
46 |
+
if isSome:
|
47 |
+
for torrent in link:
|
48 |
+
print(torrent)
|
49 |
+
download(torrent)
|
50 |
+
else:
|
51 |
+
download(link)
|