wkaisertexas / tiktok-uploader

Automatically ⬆️ upload TikTok videos
https://pypi.org/project/tiktok-uploader/
383 stars 89 forks source link

Hash tag and mention are plain text, not hyperlink, not clickable. #20

Closed nhantamz closed 1 year ago

nhantamz commented 1 year ago

Hi,

Thank you for the your good project.

I see your demo with hashtag on c_span channel and it is working. I can click on hashtag as a link. But with my video, tag just is a text, and mention is @ sign only.

upload_video(filename='2.mp4', description='#fyp @icespicee', cookies=....)

it will be text #fyp@ on video and not clickable.

I run the code in headless mode chrome on Ubuntu server.

Did I do something wrong ?

wkaisertexas commented 1 year ago

Hey, so the biggest hack that I would use to get around this is adding an extra space after the @IceSpicee simply because I think the code that I wrote to perform the action chains to go through the upload process breaks down if there is not that there.

 try:
        while description:
            nearest_mention = description.find('@')
            nearest_hash = description.find('#')

            if nearest_mention == 0 or nearest_hash == 0:
                desc.send_keys('@' if nearest_mention == 0 else '#')

                # wait for the frames to load
                time.sleep(config['implicit_wait'])

                name = description[1:].split(' ')[0]
                if nearest_mention == 0: # @ case
                    mention_xpath = config['selectors']['upload']['mention_box']
                    condition = EC.presence_of_element_located((By.XPATH, mention_xpath))
                    mention_box = WebDriverWait(driver, config['explicit_wait']).until(condition)
                    mention_box.send_keys(name)
                else:
                    desc.send_keys(name)

                time.sleep(config['implicit_wait'])

                if nearest_mention == 0: # @ case
                    mention_xpath = config['selectors']['upload']['mentions'].format('@' + name)
                    condition = EC.presence_of_element_located((By.XPATH, mention_xpath))
                else:
                    hashtag_xpath = config['selectors']['upload']['hashtags'].format(name)
                    condition = EC.presence_of_element_located((By.XPATH, hashtag_xpath))

                elem = WebDriverWait(driver, config['explicit_wait']).until(condition)

                ActionChains(driver).move_to_element(elem).click(elem).perform()

                description = description[len(name) + 2:] # this is the code which I think has the problem
            else:
                min_index = _get_splice_index(nearest_mention, nearest_hash, description)

                desc.send_keys(description[:min_index])
                description = description[min_index:]
    except Exception as exception:
        print('Failed to set description: ', exception)
        _clear(desc)
        desc.send_keys(saved_description) # if fail, use saved description

I am really sorry for writing code like this, very confusing as I tried too hard to not repeat myself I think.

nhantamz commented 1 year ago

Hi bro, thank u for your response.

I have tested on windows (same as your demo, no modification) and it i was ok. So I think this issue only occurs on Linux (I tested in headless Chrome only, even I added extra space at end of description).

BTW, on headless chrome Linux, almost every try it will give error like that:

image

it can't access the upload page.

my server is Ubuntu 20: 4 vCores 8G RAM, it have ip v4 and v6, Chrome 114 latest.

PS: If i use headless param on your function it will show error:

image

I have to add option

options.add_argument('--headless=new') options.add_argument('--no-sandbox')

Feel free to check it

Thank you.