Celeskry commited on
Commit
100b995
·
verified ·
1 Parent(s): 106650c

Update app/tik_dl.py

Browse files
Files changed (1) hide show
  1. app/tik_dl.py +7 -4
app/tik_dl.py CHANGED
@@ -12,22 +12,25 @@ class TikTokDownloader:
12
  self.headers = {
13
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
14
  }
15
- # Lưu token trong 15 phút, chứa thông tin gốc để khởi tạo tải sau
16
  self.token_cache = TTLCache(maxsize=1000, ttl=900)
17
- self.browser = None
18
  self.pw = None
 
 
19
 
20
  async def start(self):
21
  from playwright.async_api import async_playwright
22
  self.pw = await async_playwright().start()
23
- self.browser = await self.pw.chromium.launch(headless=True)
 
 
 
24
  self.context = await self.browser.new_context()
25
 
26
  async def stop(self):
27
  if self.context: await self.context.close()
28
  if self.browser: await self.browser.close()
29
  if self.pw: await self.pw.stop()
30
-
31
  def _format_size(self, size_bytes):
32
  if not size_bytes: return "0 MB"
33
  return f"{round(size_bytes / (1024 * 1024), 2)} MB"
 
12
  self.headers = {
13
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
14
  }
 
15
  self.token_cache = TTLCache(maxsize=1000, ttl=900)
 
16
  self.pw = None
17
+ self.browser = None
18
+ self.context = None
19
 
20
  async def start(self):
21
  from playwright.async_api import async_playwright
22
  self.pw = await async_playwright().start()
23
+ self.browser = await self.pw.chromium.launch(
24
+ headless=True,
25
+ args=["--no-sandbox", "--disable-setuid-sandbox"]
26
+ )
27
  self.context = await self.browser.new_context()
28
 
29
  async def stop(self):
30
  if self.context: await self.context.close()
31
  if self.browser: await self.browser.close()
32
  if self.pw: await self.pw.stop()
33
+
34
  def _format_size(self, size_bytes):
35
  if not size_bytes: return "0 MB"
36
  return f"{round(size_bytes / (1024 * 1024), 2)} MB"