Open CyberbobGR opened 1 month ago
try it
def get_room_id_from_user(self) -> str:
"""Given a username, get the room_id"""
try:
response = self.req.get(
f'https://www.tiktok.com/@{self.user}/live',
allow_redirects=False, headers=bot_utils.headers, cookies=self.cookies)
# logging.info(f'get_room_id_from_user response: {response.text}')
if response.status_code == StatusCode.REDIRECT:
raise errors.Blacklisted('Redirect')
match = re.search(r'room_id=(\d+)', response.text)
if match:
return match.group(1)
match = re.search(r'"roomId":"(\d+)"', response.text)
if match:
return match.group(1)
raise ValueError('room_id not found')
except (req.HTTPError, errors.Blacklisted) as e:
raise errors.Blacklisted(e)
except AttributeError as e:
raise errors.UserNotFound(f'{ErrorMsg.USERNAME_ERROR}\n{e}')
except ValueError as e:
raise e
except Exception as ex:
raise errors.GenericReq(ex)
If your cookies aren't loaded from a file but from headers
in bot_utils.py,
then this is:
def get_room_id_from_user(self) -> str:
"""Given a username, get the room_id"""
try:
response = self.req.get(
f'https://www.tiktok.com/@{self.user}/live',
allow_redirects=False, headers=bot_utils.headers)
# logging.info(f'get_room_id_from_user response: {response.text}')
if response.status_code == StatusCode.REDIRECT:
raise errors.Blacklisted('Redirect')
match = re.search(r'room_id=(\d+)', response.text)
if match:
return match.group(1)
match = re.search(r'"roomId":"(\d+)"', response.text)
if match:
return match.group(1)
raise ValueError('room_id not found')
except (req.HTTPError, errors.Blacklisted) as e:
raise errors.Blacklisted(e)
except AttributeError as e:
raise errors.UserNotFound(f'{ErrorMsg.USERNAME_ERROR}\n{e}')
except ValueError as e:
raise e
except Exception as ex:
raise errors.GenericReq(ex)
try it
thanks bro, it works
try it How can I make this work? iam using phone
@Marksmanship256 I would like to load my cookie.json but I don't know what to modify in the script. Have you modified the script to load your authentication cookie ? Thanks
@Marksmanship256 I would like to load my cookie.json but I don't know what to modify in the script. Have you modified the script to load your authentication cookie ? Thanks
@jean75000 I use the Chrome extension Get cookies.txt LOCALLY to export cookies in Netscape format. Then you gotta make these edits to the tiktok_bot.py file.
Make sure to back up your tiktok_bot.py
file before making these changes.
Add this line in __init__
func: (absolute path to the cookies.txt file)
self.cookies = self.load_cookies_from_netscape_file('С:/tiktok-live-recorder/www.tiktok.com_cookies.txt')
Go through the whole file, search for headers=bot_utils.headers
, and in the arguments, right after headers=bot_utils.headers
, add cookies=self.cookies
, separated by commas, in each request (in 4 places).
get_user_from_room_id
function, add this load_cookies_from_netscape_file
function to read your cookie file. def load_cookies_from_netscape_file(self, filepath):
"""Load cookies from a Netscape format cookie file."""
cookies = {}
try:
with open(filepath, 'r') as file:
for line in file:
if not line.startswith('#') and line.strip():
parts = line.strip().split('\t')
if len(parts) == 7:
domain, flag, path, secure, expiration, name, value = parts
cookies[name] = value
except FileNotFoundError as e:
logging.error(f"Cookie file not found: {e}")
except Exception as e:
logging.error(f"Error reading cookie file: {e}")
return cookies
How can I make this work? iam using phone
@Naderrnawar Someone needs to update the repo with these changes, or you gotta figure out how to make these changes yourself in your phone.
@jean75000 I use the Chrome extension Get cookies.txt LOCALLY to export cookies in Netscape format. Then you gotta make these edits to the tiktok_bot.py file.
Make sure to back up your
tiktok_bot.py
file before making these changes.
@Marksmanship256 i got some error
@jean75000 I use the Chrome extension Get cookies.txt LOCALLY to export cookies in Netscape format. Then you gotta make these edits to the tiktok_bot.py file. Make sure to back up your
tiktok_bot.py
file before making these changes.@Marksmanship256 i got some error
The TabError: inconsistent use of tabs and spaces in indentation error indicates that your code uses both tabs and spaces for indentation, which Python does not allow. All indentation in Python code must be consistent, using either tabs or spaces (spaces are recommended).
VSCode: Open the file in VSCode. Press Ctrl+Shift+P to open the command palette. Type Convert Indentation to Spaces and select the command
PyCharm: Open the file in PyCharm. From the menu, choose Code -> Reformat Code or press Ctrl+Alt+L.
Sublime Text: Open the file in Sublime Text. Select View -> Indentation -> Convert Indentation to Spaces.
If you want to fix the issue manually, open your script in a text editor and ensure that all indentations are done in a consistent manner. For example, use only spaces (usually 4 spaces per indentation level).
TBH, the console shows you everything you need to fix the error; line 36 probably has the wrong indent.
@Marksmanship256 Thanks 👍
The TabError: inconsistent use of tabs and spaces in indentation error indicates that your code uses both tabs and spaces for indentation, which Python does not allow. All indentation in Python code must be consistent, using either tabs or spaces (spaces are recommended).
TBH, the console shows you everything you need to fix the error; line 36 probably has the wrong indent.
Ok, thanks. Fixed.
@roju can you please update your script with those changes
@Marksmanship256 I added your code but the room_id error still persists. Is my tiktok id banned? I can view the live on the mobile app and web just fine though
It looks like TikTok changed something on its side and the script no longer works with username. It just shows "ERROR - room_id not found".