2
File size: 3,922 Bytes
033dd74
6bd6fd7
7981d3e
6bd6fd7
 
 
7981d3e
d5f4666
31cf358
7981d3e
 
d5f4666
6bd6fd7
 
d5f4666
 
 
 
033dd74
d5f4666
 
 
 
 
7981d3e
6bd6fd7
7981d3e
 
033dd74
d5f4666
 
 
 
 
7981d3e
d5f4666
 
 
 
7981d3e
 
 
033dd74
d5f4666
 
7981d3e
d5f4666
 
 
 
7981d3e
 
 
 
d5f4666
7981d3e
 
 
 
 
 
 
6bd6fd7
7981d3e
 
6bd6fd7
7981d3e
31cf358
033dd74
7981d3e
 
 
5ed3cee
7981d3e
033dd74
7981d3e
 
 
 
 
033dd74
7981d3e
 
 
 
 
 
 
 
5ed3cee
7981d3e
31cf358
6bd6fd7
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
import gradio as gr
import requests
from bs4 import BeautifulSoup
import img2pdf
import io
from PIL import Image
import os
import re

def fetch_manga_to_pdf(url):
    if not url or "http" not in url:
        return None, "⚠️ يرجى إدخال رابط صحيح"
    
    try:
        # نظام تزييف الهوية لكسر حماية المواقع
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
            'Referer': 'https://azoramoon.com/',
            'Connection': 'keep-alive'
        }
        
        session = requests.Session()
        response = session.get(url, headers=headers, timeout=15)
        soup = BeautifulSoup(response.text, 'html.parser')
        
        img_list = []
        
        # البحث عن منطقة المحتوى
        content_div = soup.find('div', {'class': re.compile(r'content|reader|chapter-video-frame|vung-doc|reading-content')})
        target = content_div if content_div else soup
        
        images = target.find_all('img')
        
        for img in images:
            img_url = img.get('src') or img.get('data-src') or img.get('data-lazy-src')
            
            if img_url:
                img_url = img_url.strip()
                if not img_url.startswith('http'):
                    img_url = "https:" + img_url if img_url.startswith('//') else img_url
                
                if "logo" in img_url.lower() or "avatar" in img_url.lower() or "banner" in img_url.lower():
                    continue
                
                try:
                    img_res = session.get(img_url, headers=headers, timeout=10)
                    if img_res.status_code == 200:
                        image = Image.open(io.BytesIO(img_res.content)).convert('RGB')
                        img_list.append(image)
                except:
                    continue

        if not img_list:
            return None, "❌ الموقع محمي أو الرابط غير مدعوم حالياً"

        pdf_io = io.BytesIO()
        img_list[0].save(pdf_io, save_all=True, append_images=img_list[1:], format='PDF')
        
        file_path = "manga_chapter.pdf"
        with open(file_path, "wb") as f:
            f.write(pdf_io.getvalue())
            
        return file_path, "✅ تم التجهيز بنجاح! حمل الملف من الأسفل"
    
    except Exception as e:
        return None, f"❌ حدث خطأ: {str(e)}"

# تصميم الواجهة
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# 📚 محول المانهوا إلى PDF")
    gr.Markdown("ضع رابط الفصل، انتظر قليلاً، ثم حمل الملف.")
    
    with gr.Column():
        url_input = gr.Textbox(label="رابط الفصل", placeholder="انسخ رابط الفصل من الموقع هنا...")
        btn = gr.Button("🚀 ابدأ التحويل الآن", variant="primary")
        
        gr.HTML("""
            <div style='background: #fff3cd; padding: 10px; border-radius: 5px; text-align: center;'>
                <p>📢 لضمان سرعة التحميل، يرجى زيارة راعي الموقع:</p>
                <a href='https://www.google.com' target='_blank' 
                   style='background: #ffc107; padding: 5px 15px; text-decoration: none; border-radius: 3px; color: black; font-weight: bold;'>
                   اضغط هنا لتفعيل التحميل السريع ⚡
                </a>
            </div>
        """)
        
        status = gr.Markdown()
        output_file = gr.File(label="ملف الـ PDF الجاهز")

    btn.click(fn=fetch_manga_to_pdf, inputs=url_input, outputs=[output_file, status])

demo.launch()