Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Commit

Permalink
Dynamically fetch appropriate stream url
Browse files Browse the repository at this point in the history
  • Loading branch information
Loukious committed May 3, 2024
1 parent b408470 commit 1551419
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions TiktokStreamKeyGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ def createStream(
gen_replay=False,
close_room_when_close_stream=True,
age_restricted=False,
priority_region="",
stream_server=0
priority_region=""
):
if stream_server == 0:
# For some reason some regions don't work with this URL
base_url = "https://webcast16-normal-c-useast1a.tiktokv.com/"
else:
base_url = "https://webcast16-normal-c-useast2a.tiktokv.com/"
base_url = self.getServerUrl()
params = {
# App ID for TikTok Live Studio
"aid": "8311",
Expand Down Expand Up @@ -93,12 +88,8 @@ def createStream(
)
return False

def endStream(self, stream_server=0):
if stream_server == 0:
# For some reason some regions don't work with this URL
base_url = "https://webcast16-normal-c-useast1a.tiktokv.com/"
else:
base_url = "https://webcast16-normal-c-useast2a.tiktokv.com/"
def endStream(self):
base_url = self.getServerUrl()
params = {
# App ID for TikTok Live Studio
"aid": "8311",
Expand All @@ -119,7 +110,10 @@ def endStream(self, stream_server=0):
)
return False
return True

def getServerUrl(self):
url = "https://tnc16-platform-useast1a.tiktokv.com/get_domains/v4/?aid=8311&ttwebview_version=1130022000"
response = self.s.get(url)
return f"https://webcast16-normal-c-{response.url.split('/')[2].split('-')[2]}/"

def save_config():
"""Save entry values to a JSON file."""
Expand All @@ -144,7 +138,6 @@ def save_config():
"hashtag_id": topic_id,
"priority_region": region_entry.get(),
"generate_replay": replay_var.get(),
"selected_server": server_var.get(),
"close_room_when_close_stream": close_room_var.get(),
"age_restricted": age_restricted_var.get(),
}
Expand All @@ -166,7 +159,6 @@ def load_config():
else:
game_combobox.set(games.get(data.get("game_tag_id", ""), ""))
region_entry.set(data.get("priority_region", ""))
server_var.set(data.get("selected_server", 0))
replay_var.set(data.get("generate_replay", False))
close_room_var.set(data.get("close_room_when_close_stream", True))
age_restricted_var.set(data.get("age_restricted", False))
Expand Down Expand Up @@ -242,7 +234,7 @@ def clear_output_fields():
def end_stream():
"""End the current stream."""
with Stream() as s:
ended = s.endStream(server_var.get())
ended = s.endStream()
if ended:
messagebox.showinfo("Success", "Stream ended successfully.")
enable_output_fields()
Expand Down Expand Up @@ -278,8 +270,7 @@ def generate_stream():
replay_var.get(),
close_room_var.get(),
age_restricted_var.get(),
region_entry.get(),
server_var.get()
region_entry.get()
)
if created:
messagebox.showinfo("Success", "Stream created successfully.")
Expand Down Expand Up @@ -440,38 +431,27 @@ def check_selection(event):
)
region_entry.grid(row=3, column=1, padx=5, pady=2, sticky="ew")

server_var = tk.IntVar(value=0)

radio_server1 = ttk.Radiobutton(
input_frame, text="Server 1", variable=server_var, value=0
)
radio_server1.grid(row=4, column=0, padx=5, pady=2, sticky="w")

radio_server2 = ttk.Radiobutton(
input_frame, text="Server 2", variable=server_var, value=1
)
radio_server2.grid(row=4, column=1, padx=5, pady=2, sticky="w")

replay_var = tk.BooleanVar()
replay_checkbox = ttk.Checkbutton(
input_frame, text="Generate Replay", variable=replay_var
)
replay_checkbox.grid(row=5, column=0, columnspan=2, padx=5, pady=2, sticky="w")
replay_checkbox.grid(row=4, column=0, columnspan=2, padx=5, pady=2, sticky="w")

close_room_var = tk.BooleanVar(value=True)
close_room_checkbox = ttk.Checkbutton(
input_frame, text="Close Room When Close Stream", variable=close_room_var
)
close_room_checkbox.grid(
row=6, column=0, columnspan=2, padx=5, pady=2, sticky="w"
row=5, column=0, columnspan=2, padx=5, pady=2, sticky="w"
)

age_restricted_var = tk.BooleanVar()
age_restricted_checkbox = ttk.Checkbutton(
input_frame, text="Age Restricted", variable=age_restricted_var
)
age_restricted_checkbox.grid(
row=7, column=0, columnspan=2, padx=5, pady=2, sticky="w"
row=6, column=0, columnspan=2, padx=5, pady=2, sticky="w"
)

# Cookies status
Expand Down

0 comments on commit 1551419

Please sign in to comment.