File size: 4,210 Bytes
a568782
 
f33309d
4e6c980
a568782
f33309d
 
 
 
 
 
 
73e493c
f33309d
 
 
 
a568782
73e493c
4e6c980
 
 
 
 
 
73e493c
4e6c980
 
73e493c
 
 
 
1d4abf3
73e493c
 
 
1d4abf3
73e493c
 
 
 
 
 
1d4abf3
73e493c
 
 
1d4abf3
3bd11cb
 
 
 
 
 
 
 
 
 
 
 
73e493c
4e6c980
 
 
 
 
 
 
3bd11cb
 
 
 
4e6c980
f33309d
a568782
73e493c
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
97
98
99
100
101
102
103
104
105
106
107
108
109
import gradio as gr
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) if hashtags else "هاشتاغات غير متوفرة"

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

        # استخراج عدد الإعجابات
        likes_element = video.find('strong', {"data-e2e": "browse-like-count"})
        video_info["Likes"] = likes_element.get_text(strip=True) if likes_element else "غير متوفر"

        # استخراج عدد التعليقات
        comments_element = video.find('strong', {"data-e2e": "browse-comment-count"})
        video_info["Comments"] = comments_element.get_text(strip=True) if comments_element else "غير متوفر"

        # استخراج عدد المشاركات
        shares_element = video.find('strong', {"data-e2e": "undefined-count"})
        video_info["Shares"] = shares_element.get_text(strip=True) if shares_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']}\n"
        f"- عدد الإعجابات: {video['Likes']}\n"
        f"- عدد التعليقات: {video['Comments']}\n"
        f"- عدد المشاركات: {video['Shares']}"
        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()