understanding commited on
Commit
6190b71
·
verified ·
1 Parent(s): 968eeaa

Update terabox_utils.py

Browse files
Files changed (1) hide show
  1. terabox_utils.py +27 -35
terabox_utils.py CHANGED
@@ -1,45 +1,37 @@
1
  # terabox_utils.py
2
 
3
- import aiohttp
4
- import asyncio
5
  import os
6
- import logging
7
- import config
8
 
9
- async def extract_terabox_short_id(link: str) -> str:
10
- # Simple example: extract ID from Terabox link (you can customize this!)
11
- import re
12
- match = re.search(r'/s/([a-zA-Z0-9]+)', link)
13
- return match.group(1) if match else None
 
14
 
15
- async def get_final_url_and_filename(link: str):
16
- # Example worker call
17
  try:
18
- async with aiohttp.ClientSession() as session:
19
- async with session.post(config.TERABOX_WORKER_URL, json={"link": link}) as resp:
20
- if resp.status != 200:
21
- return None, None, f"Worker error: {resp.status}"
22
- data = await resp.json()
23
- return data["url"], data["name"], None
24
  except Exception as e:
25
- logging.exception("Error in get_final_url_and_filename")
26
- return None, None, str(e)
27
 
28
- async def download_terabox_file(bot, chat_id, message_id, download_url, filename):
29
- # Fast simple downloader
30
- local_path = f"downloads/{filename}"
31
  try:
32
- async with aiohttp.ClientSession() as session:
33
- async with session.get(download_url) as resp:
34
- with open(local_path, "wb") as f:
35
- while True:
36
- chunk = await resp.content.read(1024 * 1024)
37
- if not chunk:
38
- break
39
- f.write(chunk)
40
- # Simulate thumbnail creation (skip FFMPEG encoding!)
41
- thumb_path = None
42
- return local_path, thumb_path, None
43
  except Exception as e:
44
- logging.exception("Error in download_terabox_file")
45
- return None, None, str(e)
 
1
  # terabox_utils.py
2
 
 
 
3
  import os
4
+ import asyncio
 
5
 
6
+ # Example extract function
7
+ async def extract_terabox_short_id(url: str) -> str | None:
8
+ # Dummy logic — implement your real one
9
+ if "terabox.com" in url:
10
+ return url.split("/")[-1].split("?")[0]
11
+ return None
12
 
13
+ # Example function to get direct download URL & filename
14
+ async def get_final_url_and_filename(original_link: str) -> tuple[str, str, str | None]:
15
  try:
16
+ # Here you should implement calling your TERABOX_WORKER_URL or scraping logic
17
+ # For now we return dummy values:
18
+ download_url = f"https://dummy-terabox-link/{original_link.split('/')[-1]}"
19
+ filename = f"{original_link.split('/')[-1]}.mp4"
20
+ return download_url, filename, None
 
21
  except Exception as e:
22
+ return "", "", str(e)
 
23
 
24
+ # Example function to simulate download
25
+ async def download_terabox_file(bot, chat_id, message_id, download_url, raw_filename) -> tuple[str, str, str | None]:
 
26
  try:
27
+ # Simulate a file download — here you would implement your real download logic
28
+ local_filepath = f"downloads/{raw_filename}"
29
+ with open(local_filepath, "wb") as f:
30
+ f.write(b"dummy content") # Replace with actual file download
31
+
32
+ # Thumbnail path — you can leave empty or create a dummy image
33
+ thumb_path = "" # Optional thumbnail path
34
+
35
+ return local_filepath, thumb_path, None
 
 
36
  except Exception as e:
37
+ return "", "", str(e)