File size: 3,188 Bytes
a568782
f33309d
a568782
f33309d
4e6c980
a568782
f33309d
 
 
 
 
 
 
4e6c980
f33309d
 
 
 
a568782
4e6c980
 
 
 
 
 
 
 
 
 
1d4abf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4e6c980
 
 
 
 
 
 
 
 
f33309d
a568782
4e6c980
f33309d
 
a568782
 
4e6c980
f33309d
a568782
4e6c980
f33309d
a568782
f33309d
 
a568782
4e6c980
 
 
f33309d
4e6c980
a568782
f33309d
a568782
4e6c980
f33309d
4e6c980
a568782
f33309d
a568782
 
f33309d
a568782
 
4dbac94
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
import gradio as gr
from collections import Counter
from bs4 import BeautifulSoup

def analyze_videos(file):
    try:
        # قراءة محتوى الملف
        if hasattr(file, 'read'):
            content = file.read()
        else:
            with open(file.name, 'r', encoding='utf-8') as f:
                content = f.read()
    except Exception as e:
        return f"خطأ أثناء قراءة الملف: {str(e)}", ""

    # تحليل HTML باستخدام BeautifulSoup
    try:
        soup = BeautifulSoup(content, 'html.parser')
    except Exception as e:
        return f"خطأ في تحليل محتوى HTML: {str(e)}", ""

    # استخراج بيانات الفيديوهات
    videos_data = []
    video_elements = soup.find_all('a', class_="css-1wrhn5c-AMetaCaptionLine")

    if not video_elements:
        return "لم يتم العثور على أي بيانات مطابقة.", ""

    for video in video_elements:
    video_info = {}
    
    # استخراج الرابط
    video_info["Link"] = video.get('href', 'رابط غير متوفر')

    # استخراج العنوان
    title_element = video.find('span', class_="css-j2a19r-SpanText")
    video_info["Title"] = title_element.get_text(strip=True) if title_element else "عنوان غير متوفر"

    # استخراج الهاشتاغات
    hashtags = [
        tag.get_text(strip=True) 
        for tag in video.find_all('strong', class_="css-1p6dp51-StrongText")
    ]
    video_info["Hashtags"] = ", ".join(hashtags)

    # استخراج عدد المشاهدات
    views_element = video.find_next('strong', {"data-e2e": "video-views"})
    video_info["Views"] = views_element.get_text(strip=True) if views_element else "عدد المشاهدات غير متوفر"

    videos_data.append(video_info)


    # تجهيز النصوص النهائية
    videos_summary = "\n\n".join(
        f"📹 الفيديو {i+1}:\n"
        f"- الرابط: {video['Link']}\n"
        f"- العنوان: {video['Title']}\n"
        f"- الهاشتاغات: {video['Hashtags']}\n"
        f"- عدد المشاهدات: {video['Views']}"
        for i, video in enumerate(videos_data)
    )

    return videos_summary or "لم يتم استخراج أي معلومات."

# إنشاء واجهة Gradio
def gradio_interface():
    with gr.Blocks() as demo:
        gr.Markdown("## 📝 محلل فيديوهات تيك توك")

        with gr.Row():
            file_input = gr.File(label="📂 رفع ملف HTML", file_types=[".html"])

        with gr.Row():
            analyze_btn = gr.Button("تحليل البيانات", variant="primary")

        with gr.Row():
            output_box = gr.Textbox(
                label="📜 البيانات المستخرجة",
                lines=20,
                interactive=False,
                placeholder="ستظهر البيانات هنا"
            )

        analyze_btn.click(
            fn=analyze_videos,
            inputs=[file_input],
            outputs=[output_box],
        )

    return demo

# تشغيل التطبيق
if __name__ == "__main__":
    demo = gradio_interface()
    demo.launch()