tiktokautouploader 4.1__py2.py3-none-any.whl → 4.2__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  const { chromium } = require('playwright-extra')
2
-
2
+ const fs = require('fs');
3
3
 
4
4
  const stealth = require('puppeteer-extra-plugin-stealth')()
5
5
 
@@ -18,8 +18,33 @@ async function checkForRedirect(page) {
18
18
  }
19
19
 
20
20
  (async () => {
21
+ const args = process.argv.slice(2);
22
+ let proxy = null;
23
+
24
+ for (let i = 0; i < args.length; i++) {
25
+ if (args[i] === '--proxy' && args[i + 1]) {
26
+ try {
27
+ fs.writeFileSync('proxy_data.txt', args[i+1]);
28
+ proxy = JSON.parse(args[i + 1]); // Parse the proxy string as JSON
29
+ } catch (error) {
30
+ console.error('Failed to parse proxy argument:', error);
31
+ }
32
+ }
33
+ }
34
+
35
+ const browserOptions = {
36
+ headless: false,
37
+ };
38
+
39
+ if (proxy && proxy.server) {
40
+ browserOptions.proxy = {
41
+ server: proxy.server,
42
+ username: proxy.username || undefined,
43
+ password: proxy.password || undefined,
44
+ }
45
+ }
21
46
  let redirected = false;
22
- const browser = await chromium.launch({ headless: false });
47
+ const browser = await chromium.launch(browserOptions);
23
48
  const page = await browser.newPage();
24
49
  await page.goto('https://www.tiktok.com/login');
25
50
 
@@ -32,9 +57,8 @@ async function checkForRedirect(page) {
32
57
 
33
58
  sleep(2000)
34
59
  const cookies = await page.context().cookies();
35
- const fs = require('fs');
36
60
  fs.writeFileSync('TK_cookies.json', JSON.stringify(cookies, null, 2));
37
61
 
38
-
62
+
39
63
  await browser.close();
40
64
  })();
@@ -39,6 +39,9 @@ def check_expiry(accountname):
39
39
  for cookie in cookies:
40
40
  if cookie['name'] in ['sessionid', 'sid_tt', 'sessionid_ss', 'passport_auth_status']:
41
41
  expiry = cookie.get('expires')
42
+ # for manually extracted cookies
43
+ if not expiry:
44
+ expiry = cookie.get('expirationDate')
42
45
  cookies_expire.append(expiry < current_time)
43
46
 
44
47
  if all(cookies_expire):
@@ -46,9 +49,18 @@ def check_expiry(accountname):
46
49
 
47
50
  return expired
48
51
 
49
- def run_javascript():
52
+ def run_javascript(proxy_data=None):
53
+ env_vars = {"PROXY": str(proxy_data) if proxy_data is not None else ""}
50
54
  js_file_path = pkg_resources.resource_filename(__name__, 'Js_assets/login.js')
51
- result = subprocess.run(['node', js_file_path], capture_output=True, text=True)
55
+ proxy_argument = str(proxy_data) if proxy_data is not None else str({})
56
+ try:
57
+ result = subprocess.run(
58
+ ['node', js_file_path, '--proxy', proxy_argument],
59
+ capture_output=True,
60
+ text=True,
61
+ )
62
+ except Exception as e:
63
+ sys.exit(f"Error while running the JavaScript file, when trying to parse cookies: {e}")
52
64
  return result
53
65
 
54
66
  def install_js_dependencies():
@@ -59,9 +71,16 @@ def install_js_dependencies():
59
71
  print("JavaScript dependencies not found. Installing...")
60
72
  try:
61
73
  subprocess.run(['npm', 'install', '--silent'], cwd=js_dir, check=True)
62
- except subprocess.CalledProcessError as e:
74
+ except Exception as e:
63
75
  print("An error occurred during npm installation.")
64
76
  print(f"Error details: {e}")
77
+
78
+ print("Trying to install JavaScript dependencies with shell...")
79
+ try:
80
+ subprocess.run(['npm', 'install', '--silent'], cwd=js_dir, check=True, shell=True)
81
+ except Exception as e:
82
+ print("An error occurred during shell npm installation.")
83
+ print(f"Error details: {e}")
65
84
  else:
66
85
  time.sleep(0.1)
67
86
 
@@ -146,7 +165,7 @@ def run_inference_on_image_tougher(image_path, object):
146
165
 
147
166
  #rk <- Roboflow key
148
167
  rk = 'kyHFbAWkOWfGz8fSEw8O'
149
-
168
+
150
169
  CLIENT = InferenceHTTPClient(
151
170
  api_url="https://detect.roboflow.com",
152
171
  api_key=f"{rk}"
@@ -179,7 +198,6 @@ def run_inference_on_image(image_path):
179
198
 
180
199
  #rk <- Roboflow key
181
200
  rk = 'kyHFbAWkOWfGz8fSEw8O'
182
-
183
201
  CLIENT = InferenceHTTPClient(
184
202
  api_url="https://detect.roboflow.com",
185
203
  api_key=f"{rk}"
@@ -236,9 +254,37 @@ def click_on_objects(page, object_coords):
236
254
  page.mouse.click(x, y)
237
255
  time.sleep(0.5)
238
256
 
257
+ def validate_proxy(proxy):
258
+ if not proxy:
259
+ return
239
260
 
261
+ if not isinstance(proxy, dict):
262
+ raise ValueError("Proxy must be a dictionary.")
240
263
 
241
- def upload_tiktok(video, description, accountname, hashtags=None, sound_name=None, sound_aud_vol='mix', schedule=None, day=None, copyrightcheck=False, suppressprint=False, headless=True, stealth=False):
264
+ if "server" not in proxy or not isinstance(proxy["server"], str):
265
+ raise ValueError("Proxy must contain a 'server' key with a string value.")
266
+
267
+ try:
268
+ proxies = {
269
+ "http": f'http://{proxy["server"]}/',
270
+ "http": f'https://{proxy["server"]}/',
271
+ }
272
+ if proxy.get("username"):
273
+ proxies = {
274
+ "http": f'http://{proxy.get("username")}:{proxy.get("password")}@{proxy["server"]}/',
275
+ "http": f'https://{proxy.get("username")}:{proxy.get("password")}@{proxy["server"]}/',
276
+ }
277
+
278
+ response = requests.get("https://www.google.com", proxies=proxies)
279
+ if response.status_code == 200:
280
+ print("Proxy is valid!")
281
+ else:
282
+ raise ValueError(f"Proxy test failed with status code: {response.status_code}")
283
+ except Exception as e:
284
+ raise ValueError(f"Invalid proxy configuration when trying to simple request: {e}")
285
+
286
+
287
+ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=None, sound_aud_vol='mix', schedule=None, day=None, copyrightcheck=False, suppressprint=False, headless=True, stealth=False, proxy=None):
242
288
 
243
289
  """
244
290
  UPLOADS VIDEO TO TIKTOK
@@ -246,15 +292,16 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
246
292
  video (str) -> path to video to upload
247
293
  description (str) -> description for video
248
294
  accountname (str) -> account to upload on
249
- hashtags (str)(array) -> hashtags for video
250
- sound_name (str) -> name of tik tok sound to use for video
251
- sound_aud_vol (str) -> volume of tik tok sound, 'main', 'mix' or 'background', check documentation for more info -> https://github.com/haziq-exe/TikTokAutoUploader
252
- schedule (str) -> format HH:MM, your local time to upload video
253
- day (int) -> day to schedule video for, check documentation for more info -> https://github.com/haziq-exe/TikTokAutoUploader
254
- copyrightcheck (bool) -> include copyright check or not; CODE FAILS IF FAIL COPYRIGHT CHECK
255
- suppressprint (bool) -> True means function doesnt print anything to provide updates on progress
256
- headless (bool) -> run in headless mode or not
257
- stealth (bool) -> will wait second(s) before each operation
295
+ hashtags (str)(array)(opt) -> hashtags for video
296
+ sound_name (str)(opt) -> name of tik tok sound to use for video
297
+ sound_aud_vol (str)(opt) -> volume of tik tok sound, 'main', 'mix' or 'background', check documentation for more info -> https://github.com/haziq-exe/TikTokAutoUploader
298
+ schedule (str)(opt) -> format HH:MM, your local time to upload video
299
+ day (int)(opt) -> day to schedule video for, check documentation for more info -> https://github.com/haziq-exe/TikTokAutoUploader
300
+ copyrightcheck (bool)(opt) -> include copyright check or not; CODE FAILS IF FAIL COPYRIGHT CHECK
301
+ suppressprint (bool)(opt) -> True means function doesnt print anything to provide updates on progress
302
+ headless (bool)(opt) -> run in headless mode or not
303
+ stealth (bool)(opt) -> will wait second(s) before each operation
304
+ proxy (dict)(opt) -> proxy server to run code on, check documentation for more info -> https://github.com/haziq-exe/TikTokAutoUploader
258
305
  --------------------------------------------------------------------------------------------------------------------------------------------
259
306
  """
260
307
  try:
@@ -262,6 +309,11 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
262
309
  except:
263
310
  time.sleep(0.1)
264
311
 
312
+ try:
313
+ validate_proxy(proxy)
314
+ except Exception as e:
315
+ sys.exit(f'Error validating proxy: {e}')
316
+
265
317
  retries = 0
266
318
  cookie_read = False
267
319
  oldQ = 'N.A'
@@ -280,7 +332,7 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
280
332
  if cookie_read == False:
281
333
  install_js_dependencies()
282
334
  login_warning(accountname=accountname)
283
- result = run_javascript()
335
+ result = run_javascript(proxy_data=proxy)
284
336
  os.rename('TK_cookies.json', f'TK_cookies_{accountname}.json')
285
337
 
286
338
  cookies, cookie_read = read_cookies(f"TK_cookies_{accountname}.json")
@@ -290,7 +342,7 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
290
342
 
291
343
  with sync_playwright() as p:
292
344
 
293
- browser = p.firefox.launch(headless=headless)
345
+ browser = p.firefox.launch(headless=headless, proxy=proxy)
294
346
  context = browser.new_context()
295
347
  context.add_cookies(cookies)
296
348
  page = context.new_page()
@@ -471,8 +523,9 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
471
523
  except:
472
524
  if suppressprint == False:
473
525
  print(f"Tik tok hashtag not working for {hashtag}, moving onto next")
474
- for _ in range(len(hashtag)):
475
- page.keyboard.press("Backspace")
526
+ page.keyboard.type(f"{hashtag[-1]} ")
527
+ # for _ in range(len(hashtag)):
528
+ # page.keyboard.press("Backspace")
476
529
 
477
530
  if suppressprint == False:
478
531
  print("Description and Hashtags added")
@@ -485,7 +538,7 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
485
538
  time.sleep(0.2)
486
539
  if suppressprint == False:
487
540
  print("Tik tok done loading file onto servers")
488
-
541
+
489
542
  if (schedule == None) and (day != None):
490
543
  sys.exit("ERROR: CANT SCHEDULE FOR ANOTHER DAY USING 'day' WITHOUT ALSO INCLUDING TIME OF UPLOAD WITH 'schedule'; PLEASE ALSO INCLUDE TIME WITH 'schedule' PARAMETER")
491
544
 
@@ -646,12 +699,13 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
646
699
  break
647
700
  if page.locator("span", has_text="Copyright issues detected.").is_visible():
648
701
  sys.exit("COPYRIGHT CHECK FAILED: VIDEO SAVED AS DRAFT, COPYRIGHT AUDIO DETECTED FROM TIKTOK")
702
+
649
703
 
650
704
  try:
651
705
  if schedule == None:
652
706
  if stealth == True:
653
707
  time.sleep(1)
654
- page.click('button:has-text("Post")[aria-disabled="false"]', timeout=10000)
708
+ page.click('button:has-text("Post")', timeout=10000)
655
709
  uploaded = False
656
710
  checks = 0
657
711
  while uploaded == False:
@@ -695,7 +749,7 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
695
749
  time.sleep(0.5)
696
750
  page.close()
697
751
 
698
- browser = p.chromium.launch(headless=headless)
752
+ browser = p.chromium.launch(headless=headless, proxy=proxy)
699
753
 
700
754
  context = browser.new_context()
701
755
  context.add_cookies(cookies)
@@ -819,7 +873,7 @@ def upload_tiktok(video, description, accountname, hashtags=None, sound_name=Non
819
873
  if schedule == None:
820
874
  if stealth == True:
821
875
  time.sleep(1)
822
- page.click('button:has-text("Post")[aria-disabled="false"]', timeout=10000)
876
+ page.click('button:has-text("Post")', timeout=10000)
823
877
  uploaded = False
824
878
  checks = 0
825
879
  while uploaded == False:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tiktokautouploader
3
- Version: 4.1
3
+ Version: 4.2
4
4
  Summary: Upload or schedule videos to TikTok with viral TikTok sounds and hashtags.
5
5
  Project-URL: Homepage, https://github.com/haziq-exe/TikTokAutoUploader
6
6
  Author-email: HAZIQ <haziqmk123@gmail.com>
@@ -0,0 +1,7 @@
1
+ tiktokautouploader/__init__.py,sha256=u7OWCK_u68ST8dfrkSF4Yw44CJOzV9NXI6ASRuoDfmE,64
2
+ tiktokautouploader/function.py,sha256=3_FNO_ayvEbuLECqet_VtOzVAsSGgMbkw2z0k_4hfzs,49215
3
+ tiktokautouploader/Js_assets/login.js,sha256=NOuTNaGteOAhae-D6-WUH7aMKokCC6rO49EOzAo5vjQ,1690
4
+ tiktokautouploader/Js_assets/package.json,sha256=aNbwSOpEpDUlplSuXugHVeN11riVwV4ofVkRPwHzbLs,273
5
+ tiktokautouploader-4.2.dist-info/METADATA,sha256=m1lNmgDggM81_k3iBri-h7eAe8w7kogignTvj5ppSMs,5835
6
+ tiktokautouploader-4.2.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
7
+ tiktokautouploader-4.2.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- tiktokautouploader/__init__.py,sha256=u7OWCK_u68ST8dfrkSF4Yw44CJOzV9NXI6ASRuoDfmE,64
2
- tiktokautouploader/function.py,sha256=V0RU7usdPkZtsj_hR84LogRVjSWB1CeVjBAbVUYbF90,46887
3
- tiktokautouploader/Js_assets/login.js,sha256=SLhtPYo8ZfTRUnbR7Xqp084lSuAOqIWUxi75FlFH3vs,966
4
- tiktokautouploader/Js_assets/package.json,sha256=aNbwSOpEpDUlplSuXugHVeN11riVwV4ofVkRPwHzbLs,273
5
- tiktokautouploader-4.1.dist-info/METADATA,sha256=LGnXE25BKdSh4EBrHn1RCjs7bPpCBIyhu-LNF8oWEgc,5835
6
- tiktokautouploader-4.1.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
7
- tiktokautouploader-4.1.dist-info/RECORD,,