Files changed (4) hide show
  1. Dockerfile +0 -21
  2. README.md +0 -1
  3. main.py +0 -294
  4. requirements.txt +0 -4
Dockerfile DELETED
@@ -1,21 +0,0 @@
1
- FROM python:3.9
2
-
3
- # Video Rendering ke liye FFmpeg install kar rahe hain
4
- RUN apt-get update && \
5
- apt-get install -y ffmpeg git && \
6
- rm -rf /var/lib/apt/lists/*
7
-
8
- WORKDIR /app
9
-
10
- # Permissions set kar rahe hain taaki downloading/uploading mein error na aaye
11
- RUN chmod 777 /app
12
-
13
- COPY requirements.txt .
14
- RUN pip install --no-cache-dir -r requirements.txt
15
-
16
- COPY . .
17
-
18
- # Hugging Face ke liye port 7860 khol rahe hain
19
- EXPOSE 7860
20
-
21
- CMD ["python", "main.py"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -6,6 +6,5 @@ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  ---
9
- p
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: docker
7
  pinned: false
8
  ---
 
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
main.py DELETED
@@ -1,294 +0,0 @@
1
- import os
2
- import time
3
- import uuid
4
- import asyncio
5
- import threading
6
- import logging
7
- from flask import Flask, redirect
8
- from pyrogram import Client, filters, idle
9
- from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
10
- from huggingface_hub import HfApi
11
-
12
- # --- LOGGING ---
13
- logging.basicConfig(level=logging.INFO)
14
- logger = logging.getLogger("Rajasthan_Bot")
15
-
16
- # --- ENV VARIABLES ---
17
- def get_clean_var(name):
18
- val = os.environ.get(name, "")
19
- return val.strip() if val else ""
20
-
21
- API_ID = get_clean_var("API_ID")
22
- API_HASH = get_clean_var("API_HASH")
23
- BOT_TOKEN = get_clean_var("BOT_TOKEN")
24
- SESSION_STRING = get_clean_var("SESSION_STRING")
25
- HF_TOKEN = get_clean_var("HF_TOKEN")
26
- HF_REPO = get_clean_var("HF_REPO")
27
- ACCESS_PASSWORD = get_clean_var("PASSWORD") or "Maharaja Jaswant Singh"
28
-
29
- SPACE_HOST = os.environ.get("SPACE_HOST", "localhost:7860")
30
- BASE_URL = f"https://{SPACE_HOST}"
31
-
32
- # --- FLASK SERVER ---
33
- app = Flask(__name__)
34
-
35
- @app.route('/')
36
- def home():
37
- return "Rajasthan Bot System Online 🟢"
38
-
39
- @app.route('/rajasthan/<path:filename>')
40
- def serve_file(filename):
41
- real_link = f"https://huggingface.co/datasets/{HF_REPO}/resolve/main/{filename}?download=true"
42
- return redirect(real_link, code=302)
43
-
44
- def run_web_server():
45
- app.run(host="0.0.0.0", port=7860)
46
-
47
- # --- HELPERS ---
48
- def humanbytes(size):
49
- if not size: return "0 B"
50
- power = 2**10
51
- n = 0
52
- power_labels = {0 : '', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB'}
53
- while size > power:
54
- size /= power
55
- n += 1
56
- return f"{size:.2f} {power_labels[n]}"
57
-
58
- # --- GLOBAL VARS ---
59
- process_lock = asyncio.Lock()
60
- AUTH_USERS = set()
61
- USERBOT_ALIVE = False
62
-
63
- # --- CLIENTS ---
64
- if not API_ID or not BOT_TOKEN:
65
- print("❌ ERROR: API_ID ya BOT_TOKEN missing hai!")
66
- exit(1)
67
-
68
- try:
69
- API_ID = int(API_ID)
70
- except:
71
- print("❌ ERROR: API_ID number hona chahiye.")
72
- exit(1)
73
-
74
- bot = Client("main_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
75
-
76
- userbot = None
77
- if SESSION_STRING:
78
- userbot = Client("user_bot", api_id=API_ID, api_hash=API_HASH, session_string=SESSION_STRING)
79
-
80
- # --- PROGRESS ---
81
- async def progress(current, total, message, start_time, status_text):
82
- now = time.time()
83
- diff = now - start_time
84
- if round(diff % 5.00) == 0 or current == total:
85
- percentage = current * 100 / total
86
- speed = current / diff if diff > 0 else 0
87
- try:
88
- await message.edit(
89
- f"{status_text}\n"
90
- f"━━━━━━━━━━━━━━━━━━\n"
91
- f"📊 **Progress:** {percentage:.1f}%\n"
92
- f"💾 **Done:** {humanbytes(current)} / {humanbytes(total)}\n"
93
- f"⚡ **Speed:** {humanbytes(speed)}/s"
94
- )
95
- except:
96
- pass
97
-
98
- # --- PROCESS LOGIC ---
99
- async def process_media(client, media_msg, status_msg, user_request_msg):
100
- unique_id = uuid.uuid4().hex[:5]
101
-
102
- media = media_msg.video or media_msg.audio or media_msg.photo or media_msg.document
103
- file_size_bytes = getattr(media, "file_size", 0)
104
- readable_size = humanbytes(file_size_bytes)
105
-
106
- if media_msg.video:
107
- ext = "mp4"
108
- name_type = "Video"
109
- elif media_msg.audio:
110
- ext = "mp3"
111
- name_type = "Music"
112
- elif media_msg.photo:
113
- ext = "jpg"
114
- name_type = "Image"
115
- elif media_msg.document:
116
- try: ext = media_msg.document.file_name.split(".")[-1]
117
- except: ext = "pdf"
118
- name_type = "File"
119
- else:
120
- ext = "file"
121
- name_type = "File"
122
-
123
- filename = f"Rajasthan_{name_type}_{unique_id}.{ext}"
124
- save_path = f"./{filename}"
125
-
126
- try:
127
- start = time.time()
128
- await status_msg.edit(f"⬇️ **Downloading...**\n`{filename}`")
129
-
130
- await client.download_media(
131
- message=media_msg,
132
- file_name=save_path,
133
- progress=progress,
134
- progress_args=(status_msg, start, "⬇️ **Downloading (Userbot)...**")
135
- )
136
-
137
- await status_msg.edit("☁️ **Uploading to Cloud...**")
138
- api = HfApi(token=HF_TOKEN)
139
- await asyncio.to_thread(
140
- api.upload_file,
141
- path_or_fileobj=save_path,
142
- path_in_repo=filename,
143
- repo_id=HF_REPO,
144
- repo_type="dataset"
145
- )
146
-
147
- final_link = f"{BASE_URL}/rajasthan/{filename}"
148
-
149
- await status_msg.delete()
150
-
151
- hyperlink_text = f"[{filename}]({final_link})"
152
-
153
- await user_request_msg.reply_text(
154
- f"⚡ **GENERATED SUCCESSFULLY**\n"
155
- f"━━━━━━━━━━━━━━━━━━\n"
156
- f"📂 **File:** {hyperlink_text}\n"
157
- f"💾 **Size:** `{readable_size}`\n"
158
- f"━━━━━━━━━━━━━━━━━━\n"
159
- f"🔗 **Link:** `{final_link}`",
160
- disable_web_page_preview=True,
161
- reply_markup=InlineKeyboardMarkup([
162
- [InlineKeyboardButton("🚀 One Click Download", url=final_link)]
163
- ])
164
- )
165
-
166
- except Exception as e:
167
- logger.error(f"Error: {e}")
168
- await status_msg.edit(f"❌ **Error:** {str(e)}")
169
-
170
- finally:
171
- if os.path.exists(save_path): os.remove(save_path)
172
-
173
- # --- HANDLERS ---
174
- @bot.on_message(filters.command("start"))
175
- async def start(c, m):
176
- if m.from_user.id in AUTH_USERS:
177
- await m.reply_text("👋 **Welcome Back!**")
178
- else:
179
- await m.reply_text("🔒 **Access Denied!** Enter Password.")
180
-
181
- @bot.on_message(filters.private & filters.text)
182
- async def text_handler(c, m):
183
- if m.from_user.id not in AUTH_USERS:
184
- if m.text == ACCESS_PASSWORD:
185
- AUTH_USERS.add(m.from_user.id)
186
- await m.reply_text("🔓 **Access Granted!**")
187
- else:
188
- await m.reply_text("❌ **Wrong Password!**")
189
- return
190
-
191
- if "t.me/" in m.text:
192
- if not userbot or not USERBOT_ALIVE: return await m.reply_text("⚠️ **Userbot Error.**")
193
- if process_lock.locked(): return await m.reply_text("⚠️ **Queue Full.**")
194
-
195
- async with process_lock:
196
- status = await m.reply_text("🔎 **Deep Scanning (Range: 100)...**")
197
- try:
198
- # 1. Clean Link
199
- link = m.text.strip().replace("https://", "").replace("http://", "")
200
- if "t.me/" in link: link = link.split("t.me/")[1]
201
-
202
- parts = link.split("/")
203
-
204
- if parts[0] == "c":
205
- chat_id = int("-100" + parts[1]) # Private
206
- else:
207
- chat_id = parts[0] # Public Username
208
-
209
- start_msg_id = int(parts[-1].split("?")[0])
210
-
211
- print(f"DEBUG: Chat: {chat_id}, Start ID: {start_msg_id}")
212
-
213
- # 2. DEEP SCAN: Check Start ID + Next 100 messages
214
- # Topic ID gaps can be huge in busy groups
215
-
216
- target_msg = None
217
- found_at_id = 0
218
- check_limit = 100 # Increased from 10 to 100
219
-
220
- try:
221
- messages = await userbot.get_messages(chat_id, range(start_msg_id, start_msg_id + check_limit))
222
- except Exception as e:
223
- return await status.edit(f"❌ **Scan Error:** {e}")
224
-
225
- if not isinstance(messages, list):
226
- messages = [messages]
227
-
228
- for msg in messages:
229
- if msg:
230
- # Check 1: Direct Media
231
- if msg.media and not msg.web_page:
232
- target_msg = msg
233
- found_at_id = msg.id
234
- break
235
-
236
- # Check 2: If message is a Reply to a file
237
- if msg.reply_to_message and msg.reply_to_message.media:
238
- target_msg = msg.reply_to_message
239
- found_at_id = msg.reply_to_message.id
240
- break
241
-
242
- if not target_msg:
243
- return await status.edit(
244
- f"❌ **No Media Found in Range!**\n"
245
- f"Bot scanned from ID `{start_msg_id}` to `{start_msg_id + check_limit}`.\n\n"
246
- f"**Reason:** In Topic groups, Message IDs are shared across all topics. The file might be very far down.\n"
247
- f"👉 **Try:** Copy the link of the File itself, NOT the heading."
248
- )
249
-
250
- if found_at_id != start_msg_id:
251
- await status.edit(f"✅ **Found File at ID:** `{found_at_id}`\n(Scanned forward due to Topic gaps)\n\n⬇️ **Processing...**")
252
-
253
- await process_media(userbot, target_msg, status, m)
254
-
255
- except Exception as e:
256
- await status.edit(f"❌ **Error:** {e}")
257
-
258
- @bot.on_message(filters.private & (filters.document | filters.video | filters.audio | filters.photo))
259
- async def file_handler(c, m):
260
- if m.from_user.id not in AUTH_USERS: return await m.reply_text("🔒 **Password Required.**")
261
- if process_lock.locked(): return await m.reply_text("⚠️ **Queue Full.**")
262
-
263
- async with process_lock:
264
- status = await m.reply_text("⏳ **Added to Queue...**")
265
- await process_media(bot, m, status, m)
266
-
267
- # --- STARTUP ---
268
- async def main():
269
- threading.Thread(target=run_web_server, daemon=True).start()
270
-
271
- print("🚀 Bot Starting...")
272
- try:
273
- await bot.start()
274
- print("✅ Main Bot Connected Successfully!")
275
- except Exception as e:
276
- print(f"❌ Main Bot Start Error: {e}")
277
- return
278
-
279
- global USERBOT_ALIVE
280
- if userbot:
281
- try:
282
- await userbot.start()
283
- USERBOT_ALIVE = True
284
- print("✅ Userbot Connected!")
285
- except Exception as e:
286
- print(f"⚠️ Userbot Failed: {e}")
287
- USERBOT_ALIVE = False
288
-
289
- await idle()
290
- await bot.stop()
291
-
292
- if __name__ == "__main__":
293
- loop = asyncio.get_event_loop()
294
- loop.run_until_complete(main())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt DELETED
@@ -1,4 +0,0 @@
1
- pyrogram
2
- tgcrypto
3
- flask
4
- huggingface_hub