Spaces:
Building
Building
import os | |
# os.system('pip install jedi') | |
# os.system('python -m pip install --upgrade pip setuptools wheel') | |
# os.system('python -m pip install lbry-libtorrent') | |
# os.system('apt-get install ffmpeg -y') | |
# os.system('apt install python3-libtorrent') | |
import streamlit as st | |
from streamlit_option_menu import option_menu | |
from Torrent import torrent_info, torrent_download, torrent_group, simpan_txt, link_redirect | |
from bokeh.models.widgets import Button | |
from bokeh.models import CustomJS | |
from streamlit_bokeh_events import streamlit_bokeh_events | |
# Navigasi Sidebar | |
with st.sidebar: | |
selected = option_menu("Torrent", ['Magnet Link', 'Index Torrent', 'Link Redirect'], | |
icons=['search', 'house', 'fire'], menu_icon="cast", default_index=0) | |
st.sidebar.image('DanMachi.png') | |
if selected == 'Magnet Link': | |
url = 'DanMachi.png' | |
st.image(url) | |
st.title("Magnet Link Torrent") | |
link = st.text_input("Masukkan Magnet Link", "") | |
search = link = st.text_input("Masukkan Pencarian", "") | |
extension = st.selectbox('Pilih Extension', ['.mp4', '.zip']) | |
if st.button("Trace On"): | |
info = torrent_info(link, search, extension) | |
file_priority = st.selectbox('Pilih File', info) | |
if st.button("Download"): | |
selected_index = int(file_priority.split('.')[0]) | |
downloaded_files = torrent_download(link, [selected_index]) | |
elif selected == 'Index Torrent': | |
st.title("Index Torrent") | |
teks = st.text_area("Masukkan Teks", '', height=(25 * 10)) | |
tim = st.checkbox("Gak Perlu Dikelompokkan") | |
if tim: | |
group = 1000 | |
else: | |
group = st.slider("Pilih Jumlah Group", min_value=1, max_value=25, value=5) | |
if st.button("Trace On"): | |
info = torrent_group(int(group), teks) | |
lokasi_file = simpan_txt('Group Torrent', info) | |
st.session_state.info = info | |
st.session_state.lokasi_file = lokasi_file | |
if 'info' in st.session_state: | |
num_lines = st.session_state.info.count('\n') + 1 | |
text_area_height = 25 * num_lines | |
st.text_area("Hasil Redirect", st.session_state.info, height=text_area_height) | |
with open(st.session_state.lokasi_file, 'rb') as f: | |
file_contents = f.read() | |
st.download_button( | |
label="Download File TXT", | |
data=file_contents, | |
file_name=st.session_state.lokasi_file.replace('/home/user/app/', '').title().replace('Txt', 'txt'), | |
mime='text/plain' | |
) | |
copy_dict = {"content": info} | |
copy_button = Button(label="Copy Text") | |
copy_button.js_on_event("button_click", CustomJS(args=copy_dict, code=""" | |
navigator.clipboard.writeText(content); | |
""")) | |
no_event = streamlit_bokeh_events( | |
copy_button, | |
events="GET_TEXT", | |
key="get_text", | |
refresh_on_update=True, | |
override_height=75, | |
debounce_time=0 | |
) | |
else: | |
st.title("Link Redirect") | |
link = st.text_input("Masukkan Link", "https://t.co/c31TBe7s4W") | |
if st.button("Trace On"): | |
info = link_redirect(link) | |
lokasi_file = simpan_txt('Group Torrent', info) | |
st.session_state.info = info | |
st.session_state.lokasi_file = lokasi_file | |
if 'info' in st.session_state: | |
num_lines = st.session_state.info.count('\n') + 1 | |
text_area_height = 25 * num_lines | |
st.text_area("Hasil Redirect", st.session_state.info, height=text_area_height) | |
with open(st.session_state.lokasi_file, 'rb') as f: | |
file_contents = f.read() | |
st.download_button( | |
label="Download File TXT", | |
data=file_contents, | |
file_name=st.session_state.lokasi_file.replace('/home/user/app/', '').title().replace('Txt', 'txt'), | |
mime='text/plain' | |
) | |
copy_dict = {"content": info} | |
copy_button = Button(label="Copy Text") | |
copy_button.js_on_event("button_click", CustomJS(args=copy_dict, code=""" | |
navigator.clipboard.writeText(content); | |
""")) | |
no_event = streamlit_bokeh_events( | |
copy_button, | |
events="GET_TEXT", | |
key="get_text", | |
refresh_on_update=True, | |
override_height=75, | |
debounce_time=0 | |
) | |