GilangAlRusliadi commited on
Commit
3b90d58
β€’
1 Parent(s): 46edd03
Files changed (4) hide show
  1. README.md +1 -1
  2. Torrent.py +65 -0
  3. app.py +23 -26
  4. requirements.txt +6 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Streamlit
3
  emoji: πŸ‘
4
  colorFrom: green
5
  colorTo: yellow
 
1
  ---
2
+ title: Torrent
3
  emoji: πŸ‘
4
  colorFrom: green
5
  colorTo: yellow
Torrent.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import libtorrent as lt
2
+ import time
3
+
4
+ ses = lt.session()
5
+ ses.listen_on(6881, 6891)
6
+
7
+ params = {
8
+ 'save_path': '/home/user/app/Torrent',
9
+ 'storage_mode': lt.storage_mode_t(2),
10
+ 'paused': False,
11
+ 'auto_managed': True,
12
+ 'duplicate_is_error': True
13
+ }
14
+
15
+ def torrent_info(link, extension):
16
+ handle = lt.add_magnet_uri(ses, link, params)
17
+
18
+ print('Mendownload metadata...')
19
+ while (not handle.has_metadata()):
20
+ time.sleep(1)
21
+ print('Metadata didownload, memulai download torrent...')
22
+
23
+ torinfo = handle.get_torrent_info()
24
+ file_priorities = [0] * torinfo.num_files()
25
+ torrent_info = []
26
+ for idx, file in enumerate(torinfo.files()):
27
+ if file.path.endswith(extension):
28
+ print(f'{idx}. {file.path}')
29
+ torrent_info.append(file.path)
30
+ file_priorities[idx] = 1
31
+ handle.prioritize_files(file_priorities)
32
+ return torrent_info
33
+
34
+ def torrent_download(link, selected_files):
35
+ handle = lt.add_magnet_uri(ses, link, params)
36
+
37
+ # Menunggu metadata selesai didownload
38
+ while (not handle.has_metadata()):
39
+ time.sleep(1)
40
+
41
+ # Mengatur prioritas file sesuai dengan selected_files
42
+ torinfo = handle.get_torrent_info()
43
+ file_priorities = [0] * torinfo.num_files()
44
+ for index in selected_files:
45
+ file_priorities[index] = 1
46
+ handle.prioritize_files(file_priorities)
47
+
48
+ # Mendownload file .mp4 yang dipilih
49
+ while (handle.status().state != lt.torrent_status.seeding):
50
+ s = handle.status()
51
+ state_str = ['queued', 'checking', 'downloading metadata',
52
+ 'downloading', 'finished', 'seeding', 'allocating']
53
+ print('%.2f%% selesai (download: %.1f kb/s upload: %.1f kB/s peers: %d) %s' %
54
+ (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000,
55
+ s.num_peers, state_str[s.state]))
56
+ time.sleep(5)
57
+
58
+ # Mencari file yang telah selesai didownload dan mengembalikan path-nya
59
+ downloaded_files = []
60
+ for index in selected_files:
61
+ file_path = torinfo.files().file_path(index)
62
+ downloaded_files.append(file_path)
63
+ return downloaded_files
64
+
65
+
app.py CHANGED
@@ -1,26 +1,23 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Penjualan</title>
5
- <style>
6
- body {
7
- background-image: url('https://images.wallpaperscraft.ru/image/single/vodorosli_rastenie_makro_106345_1920x1080.jpg');
8
- background-size: cover;
9
- }
10
- .container {
11
- max-width: 800px;
12
- margin: 0 auto;
13
- text-align: center;
14
- color: white;
15
- }
16
- </style>
17
- </head>
18
- <body>
19
- <div class="container">
20
- <h1>Penjualan</h1>
21
- <img src="https://via.placeholder.com/300x300" alt="Gambar Produk">
22
- <p>Deskripsi produk di sini.</p>
23
- <button>Beli Sekarang</button>
24
- </div>
25
- </body>
26
- </html>
 
1
+ import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
+ from Torrent import torrent_info, torrent_download
4
+
5
+
6
+ # Navigasi Sidebar
7
+ with st.sidebar:
8
+ selected = option_menu("Torrent", ['Magnet Link'],
9
+ icons=['search'], menu_icon="cast", default_index=0)
10
+
11
+ if selected == 'Magnet Link':
12
+ st.title("Magnet Link Torrent")
13
+ link = st.text_input("Masukkan Magnet Link", "")
14
+ extension = st.selectbox('Select Extension', ['.mp4', '.zip'])
15
+
16
+
17
+ if st.button("Trace On"):
18
+ info = torrent_info(link, extension)
19
+ file_priority = st.selectbox('Select File', info)
20
+
21
+ if st.button("Download"):
22
+ selected_index = int(file_priority.split('.')[0])
23
+ downloaded_files = torrent_download(link, [selected_index])
 
 
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ streamlit-option-menu
3
+ jedi
4
+ libtorrent
5
+ lbry-libtorrent
6
+ ffmpeg