roju / tiktok-live-recorder

A Python script for recording TikTok live streams
MIT License
16 stars 2 forks source link

Tiktok account username change #33

Open jean75000 opened 1 month ago

jean75000 commented 1 month ago

Hello,

I use the script automatically and sometimes the script no longer finds information on a user who has changed the name of their Tiktok account. Is it not possible to add a check that detects the change and modifies the -user variable with the new Tiktok account name ?

Thanks

Marksmanship256 commented 1 month ago

Nope, not possible. Unless you figure out how to access the TikTok API using a unique user ID instead of a username.

jean75000 commented 1 month ago

OK Thanks

jean75000 commented 1 month ago

@Marksmanship256

I don't want to open another ticket for this and I saw that you have a good command of python, I am a beginner, I think I have a false positive (probably linked to my VPN) of blacklist and it stops the script, when I restart the script it starts again although I have not done anything.

Basically I would like that when I have the error that it continues the script without stopping

for info I launched the script 50 times and when I have this for one user the other users it works well that's why I think it's a false positive.

Thanks :)

### ERROR - Captcha required or country blocked. Use a vpn or room_id. To get room id: https://github.com/Michele0303/TikTok-Live-Recorder/blob/main/GUIDE.md#how-to-get-room_id Unrestricted country list: https://github.com/Michele0303/TikTok-Live-Recorder/edit/main/GUIDE.md#unrestricted-country 2024-07-22 22:45:12,068 - ERROR - Exception caught in main: 2024-07-22 22:45:12,068 - ERROR - Redirect

Traceback (most recent call last): File "/home/headless/tiktok_bot.py", line 291, in get_room_id_from_user raise errors.Blacklisted('Redirect') errors.Blacklisted: Redirect

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/headless/ttlr.py", line 110, in main bot.run() File "/home/headless/tiktok_bot.py", line 98, in run raise e File "/home/headless/tiktok_bot.py", line 57, in run self.room_id = self.get_room_id_from_user() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/headless/tiktok_bot.py", line 304, in get_room_id_from_user raise errors.Blacklisted(e)****

Marksmanship256 commented 1 month ago

I'm pretty new to Python too, but I can help with errors I've personally run into and fixed. I haven't seen an error like yours, so I'm not sure what it could be. Did you update the get_room_id_from_user function like this? https://github.com/roju/tiktok-live-recorder/issues/32#issuecomment-2219283944

jean75000 commented 1 month ago

yes, I have already updated the script with the addition of cookies it worked perfectly again thanks :), but today I decided to put a VPN and suddenly I encounter the error randomly on users.

I had also modified the script on my side to add the functionality of cookies with selenium but I prefer your technique because it is less resource-intensive.I also added a telegram bot that tells me that a user is online, this allows me to monitor and follow if the script crashes or no longer works

I modified that I don't know if it will correct my problem:

Before:

image

After:

image

Marksmanship256 commented 1 month ago

Try experiment with this:

Add error output to the log file logging.info(f"HTTP error occurred: {e}")

Add time.sleep()

Try raising an error like raise errors.StreamLagging That should restart the script without stopping or closing it.

  except (req.HTTPError, errors.Blacklisted) as e:
            # raise errors.Blacklisted(e)
            logging.info(f"HTTP error occurred: {e}")
            time.sleep(10)  # 10 sec
            raise errors.StreamLagging
jean75000 commented 1 month ago

after making the code modification that I indicated to you I did not have the error again if I have it again I will test your code in any case thank you very much for your help :)

jean75000 commented 1 month ago

after several days/weeks I have no more problems, the script would be perfect if it could manage the change of account name I found how to do it but I don't know how to implement it in python can someone help me?

basically each user has a unique ID for their account it would be necessary when we put the parameter "python ttlr.py -user test" that it retrieves the id and that it is based only on this id because I did a test if we replace https://www.tiktok.com/@uidtest' it redirects well to the page of the user in question: https://www.tiktok.com/@test

to receive the uid you have to look in the source code of the user's page this: {"userInfo":{"user":{"id":"

Marksmanship256 commented 1 month ago

@jean75000

Hey, thanks for sharing your research, it really makes things easier.

You can easily get the room ID by user ID. Just find the get_room_id_from_user function in the tiktok_bot.py file and replace this line:

response = self.req.get(
f'https://www.tiktok.com/@{self.user}/live',
allow_redirects=False, headers=bot_utils.headers, cookies=self.cookies)

with this:

response = self.req.get(
f'https://www.tiktok.com/@{self.user}',
allow_redirects=False, headers=bot_utils.headers, cookies=self.cookies)

I just checked - it works.

You can also grab the username inside this function and use it for the filename. I'll try to get this done in 2-3 days unless someone beats me to it.

You'll need to get the user ID manually by username. After that, just run the script with the user ID and you're good to go.

Marksmanship256 commented 1 month ago

@jean75000

thanks but unfortunately it will not solve the problem if the user changes his account name the script will indicate that it cannot find the user :(

The most reliable way is to base it on the unique id because it does not change it is composed of numbers see screenshot

that's what interests me because I have users who change the name of their account frequently and I am annoyed

This works with both username and user ID.

test

https://www.tiktok.com/@6555704086321184769

jean75000 commented 1 month ago

thanks but unfortunately it will not solve the problem if the user changes his account name the script will indicate that it cannot find the user :(

The most reliable way is to base it on the unique id because it does not change it is composed of numbers see screenshot

that's what interests me because I have users who change the name of their account frequently and I am annoyed

image image

https://github.com/user-attachments/assets/5a27a28c-481c-4992-9b0a-7e4efddc8a48

Marksmanship256 commented 1 month ago

One exception might be if TikTok changes the user ID when the username changes, since the user ID is essentially a timestamp.

jean75000 commented 1 month ago

I just changed my account name to test and my unique ID is exactly the same it has not changed so it is much more reliable to go through the unique ID than through the username

jean75000 commented 1 month ago

Now we have to find a way to make it so that when we give it a name it finds the unique ID on its own and bases itself on it and if it doesn't find a unique ID it bases itself on the username given

Marksmanship256 commented 1 month ago

Now we have to find a way to make it so that when we give it a name it finds the unique ID on its own and bases itself on it and if it doesn't find a unique ID it bases itself on the username given

If the username is already changed, you'll get an error page - user not found. No valid user ID will be in the source of this page. So, you should run the script as I shown in the example. The script needs to be modified to also extract the username for the file name if we run the script with the user ID.

jean75000 commented 1 month ago

basically you have to base yourself on the unique id because it is the only reliable element but to find it is a bit tedious and I have a list of usernames if I have to find the unique Id of each one I have it for the day :)

ideally we indicate the argument -user test it checks the username and uid of the user it is based on the uid to verify if the user is online we should add a detection to indicate to us that the user has changed his username for example when we have the log the user is offline add the old and the new account of the user

what do you think?

Marksmanship256 commented 1 month ago

basically you have to base yourself on the unique id because it is the only reliable element but to find it is a bit tedious and I have a list of usernames if I have to find the unique Id of each one I have it for the day :)

ideally we indicate the argument -user test it checks the username and uid of the user it is based on the uid to verify if the user is online we should add a detection to indicate to us that the user has changed his username for example when we have the log the user is offline add the old and the new account of the user

what do you think?

This seems a bit too complicated for me. Why not just run the script using the user ID instead of the username for users who change their username frequently (as far as I know, you can only change your username once a month)?

You could also create a simple page parser using ChatGPT. Just feed it a text document with your usernames, and it’ll generate a list of user IDs for each username.

That’s all the help I can offer.

jean75000 commented 1 month ago

thanks for the help but I'm a bit lost I've never done this with chatgpt and I don't have a paid account.

and if I had to use the user id I wanted to do it on everyone

broklin48 commented 3 weeks ago

This works with both username and user ID.

test

https://www.tiktok.com/@6555704086321184769

not working with some user id. e.g. https://www.tiktok.com/@67361217230

Marksmanship256 commented 3 weeks ago

Hey everyone who made these changes, https://github.com/roju/tiktok-live-recorder/issues/33#issuecomment-2271503099, roll them back.

As @broklin48 pointed out, roomId, you can’t always find it at https://www.tiktok.com/@{self.user}, and with these edits, it won’t work by username or ID either. So revert it to https://www.tiktok.com/@{self.user}/live and stick to using just the username.