File size: 2,820 Bytes
4e350f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import libtorrent as lt
import streamlit as st
import os
import re
import time
import requests

def sesi(info, lokasi_file):
    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'
        )

    return st.session_state.info, st.session_state.lokasi_file

def simpan_txt(nama_file, teks):
    with open(nama_file + '.txt', 'w') as f:
        f.write(teks)
    lokasi_file = os.path.abspath(nama_file + '.txt')
    return lokasi_file

def link_redirect(url):
    # Kamus untuk menerjemahkan kode status
    status_codes = {
        200: 'OK',
        301: 'Dipindahkan Secara Permanen',
        302: 'Ditemukan',
        303: 'Lihat Lainnya',
        304: 'Tidak Dimodifikasi',
        307: 'Pengalihan Sementara',
        400: 'Permintaan Buruk',
        401: 'Tidak Sah',
        403: 'Dilarang',
        404: 'Tidak Ditemukan',
        500: 'Kesalahan Server Internal',
        502: 'Gerbang Buruk',
        503: 'Layanan Tidak Tersedia'
    }

    info = ''
    response = requests.get(url)
    if response.history:
        info += "Redirects: \n"
        for resp in response.history:
            status = status_codes.get(resp.status_code, 'Kode Status Tidak Diketahui')
            info += f"[{resp.status_code} {status}] \n {resp.url}\n\n"
        info += "Final destination: \n"
        status = status_codes.get(response.status_code, 'Kode Status Tidak Diketahui')
        info += f"[{response.status_code} {status}] \n {response.url}\n"
    else:
        info += "No Redirects: \n"

    return info


def format_info(info):
    # Menghapus angka '3D' dari awal string dan mengambil 10 karakter terakhir
    info = info.split('%')[-10].replace('3D1', '').replace('3D', '')

    # Pola regex untuk mencocokkan pola yang dijelaskan
    pattern = r'([a-z]+)(\d+)'

    # Mencari kecocokan dengan pola regex
    matches = re.findall(pattern, info, re.IGNORECASE)

    if matches:
        alfabet, number = matches[0]
        # Mengubah alfabet menjadi huruf besar dan menghapus '0' dari awal nomor
        number = number.lstrip('0')
        # Jika panjang nomor kurang dari 3, tambahkan '0' di depan
        if len(number) < 3:
            number = '0' + number
        info = f"{alfabet.upper()}-{number}"
    
    return info