-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
244 lines (180 loc) · 8.52 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
from flask import Flask, render_template, request, redirect, url_for,jsonify
import os
import subprocess
import threading
from flask_socketio import SocketIO, emit
from racaty_upload_by_slash_title import racaty_upload_slash
from scrape_jav.javeve.main import scrape_javeve,fetch_redirect_url
app = Flask(__name__)
def write_links_to_file(output_file_path,final_results):
# Ensure the directory exists
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
with open(output_file_path, 'a') as file: # Open the file in append mode
for title, urls in final_results.items():
for url in urls:
file.write(f"{url}\n") # Write each URL on a new line
@app.route("/read_output", methods=['GET'])
def read_output():
# Get the path from the query parameters
output_file_path = request.args.get('path', default='scrape_jav/javeve/output_javeve.txt', type=str)
# Ensure the path is safe (you can implement more robust checks as needed)
if not output_file_path.startswith('scrape_jav/javeve/'):
return "Invalid file path.", 400
# Check if the file exists and read its contents
if os.path.exists(output_file_path):
with open(output_file_path, 'r') as file:
content = file.read()
else:
content = "File not found."
return content
@app.route("/scrape/javeve", methods=['GET', 'POST'])
def scrapejaveve():
final_results = {}
page = 1 # Default page number
search = "" # Default search term
if request.method == 'POST':
page = request.form.get('page', default=1, type=int) # Get the page number from the form
search = request.form.get('search', default="", type=str) # Get the search term from the form
scraped_data = scrape_javeve(page, search)
if scraped_data:
for item in scraped_data:
additional_data = item['additional_data']
if additional_data:
for title, data_link in additional_data.items():
redirect_url = fetch_redirect_url(data_link)
if redirect_url:
# If the title is already in final_results, append the URL
if title in final_results:
final_results[title].append(redirect_url)
else:
# Otherwise, create a new list with the URL
final_results[title] = [redirect_url]
# Write the links to the output file
write_links_to_file("scrape_jav/javeve/output_javeve.txt",final_results)
return render_template("/jav/javeve/index.html", data=final_results, page=page, search=search)
socketio = SocketIO(app) # Inisialisasi SocketIO
# Nama file untuk menyimpan data
LINK_FILE = 'link.txt'
OUTPUT_FILE = 'zfinal_hasil.txt'
RACATY_LINK_FILE = 'racaty_link.txt'
with open('output_link.txt', 'w') as file:
pass # Tidak ada isi, hanya membuat file kosong
with open(OUTPUT_FILE, 'w') as file:
pass # Tidak ada isi, hanya membuat file kosong
@app.route('/save_racaty_links', methods=['POST'])
def save_racaty_links():
links = request.json.get('links', [])
overwrite = request.json.get('overwrite', False)
try:
# Kosongkan file terlebih dahulu
with open(RACATY_LINK_FILE, "w") as f:
f.truncate(0) # Mengosongkan file
# Tulis data baru ke file
with open(RACATY_LINK_FILE, "a") as f: # Gunakan mode append untuk menulis data baru
for link in links:
if link.strip(): # Hanya simpan link yang tidak kosong
# Misalkan format link adalah "Judul - DoodStream/<>/URL"
# Ambil judul dan URL dari link
parts = link.split('/<>/')
if len(parts) == 2: # Pastikan ada dua bagian
title = parts[0].strip() # Ambil judul
url = parts[1].strip() # Ambil URL
f.write(f"{title}/<>/{url}\n") # Tulis judul dan link ke file
print(f"{title} - {url}")
else:
print(f"Format tidak valid untuk link: {link}")
racaty_upload_slash(RACATY_LINK_FILE)
return jsonify({'status': 'success'}), 200
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
@app.route('/save_links', methods=['POST'])
def save_links():
links = request.json.get('links', [])
with open(LINK_FILE, 'w') as f:
for link in links:
f.write(link + '\n') # Tulis setiap link ke file
return {'status': 'success', 'links': links}, 200 # Kembalikan status dan link yang disimpan
@app.route('/output_link.txt')
def output_link():
with open('output_link.txt', 'r') as file:
content = file.read() # Baca isi file
return content, 200, {'Content-Type': 'text/plain'} # Kembalikan isi file dengan status 200
@app.route('/zfinal_hasil.txt')
def output_zfinal():
with open('zfinal_hasil.txt', 'r') as file:
content = file.read() # Baca isi file
print(content)
return content, 200, {'Content-Type': 'text/plain'} # Kembalikan isi file dengan status 200
@app.route('/', methods=['GET', 'POST'])
def index():
preview_links = []
output_process = ""
# Cek apakah file link.txt ada dan baca isinya
if os.path.exists(LINK_FILE):
with open(LINK_FILE, 'r') as f:
preview_links = f.read().splitlines() # Baca semua baris dan pisahkan
if request.method == 'POST':
if 'link_data' in request.form:
# Ambil data dari textarea
link_data = request.form['link_data']
# Hapus isi file jika sudah ada, kemudian tulis data baru
with open(LINK_FILE, 'w') as f:
f.write(link_data + '\n') # Simpan data ke file
# Ambil link yang baru disimpan untuk ditampilkan sebagai preview
preview_links = link_data.splitlines() # Pisahkan berdasarkan baris
return render_template('index.html', preview_links=preview_links, output_process=output_process)
return render_template('index.html', preview_links=preview_links, output_process=output_process)
def run_process():
# Jalankan proses.py dan ambil outputnya
process = subprocess.Popen(['python3', 'proses.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
print(process)
while True:
output = process.stdout.readline()
print(output.strip())
if output == '' and process.poll() is not None:
break
if output:
# Emit output ke client
socketio.emit('process_output', {'data': output.strip()})
with open(OUTPUT_FILE, 'r') as f:
results = f.read().splitlines() # Baca setiap baris
# Emit event ketika proses selesai
socketio.emit('process_complete',{'results': results})
@socketio.on('start_process')
def start_process():
# Mulai proses di thread terpisah
thread = threading.Thread(target=run_process)
thread.start()
@socketio.on('start_extract')
def start_extract():
# Mulai proses extract di thread terpisah
thread = threading.Thread(target=run_extract_process)
thread.start()
def run_extract_process():
# Jalankan pooplink.txt dan ambil outputnya
process = subprocess.Popen(['python3', 'pooplink.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
while True:
output = process.stdout.readline()
if output == '' and process.poll() is not None:
break
if output:
# Emit output ke client
socketio.emit('process_output', {'data': output.strip()})
with open('output_link.txt', 'r') as f:
results = f.read().splitlines() # Baca setiap baris
# Emit event ketika proses selesai
socketio.emit('process_complete', {'results': results, 'type': 'extract'}) # Tambahkan type
@socketio.on('dood_extract')
def start_dood_extract():
# Start the dood extract process in a separate thread
thread = threading.Thread(target=run_dood_extract_process)
thread.start()
def run_dood_extract_process():
# Import the convert_dood function from doodextract.py
from doodextract import convert_dood
# Call the convert_dood function and get the results
results = convert_dood()
# Emit the results back to the client
socketio.emit('dood_extract_output', {'results': results})
if __name__ == '__main__':
socketio.run(app, debug=True)