Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data is the same #20

Open
smithperez opened this issue Jan 20, 2023 · 4 comments
Open

Data is the same #20

smithperez opened this issue Jan 20, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@smithperez
Copy link

smithperez commented Jan 20, 2023

I have been testing this API and notice that all the data returned is the same.
I have been playing around with the challenge method at different periods of time and I notice that when you use a hashtag to gather some data and you use it a second time, it will return the same data as the first time regardless of the time lapse between the 2 requests.

Just in case, you can find the code attached below.



    def hashtags(self, hashtag: str='funny', video_count: int=10):
        """
        Retrun information about a TikTok hashtag
        including video
        
        hashtag: str
        video_count: int
        """
        now = datetime.now()
        current_time = now.strftime(f"%H_%M ({datetime.today().strftime('%Y-%m-%d')})")
        
        with TikTokAPI() as api:
            data = {}
            challenge = api.challenge(hashtag, video_limit=video_count, )
            
             # Evaluate if the user has a folder in the database_json folder
            if(not os.path.isdir(f"Backend/hashtag_database_json/{challenge.title}")):
                print(os.path.exists(f"Backend/hashtag_database_json/{challenge.title}"))
                os.makedirs(f'Backend/hashtag_database_json/{challenge.title}')
                print(f"Hashtag {challenge.title} has been created in the DB")
            
            for video in challenge.videos:
                
                #Store all the hashtags used in the video
                video_hashtags = []
                for i in video.challenges:
                    #Append all the challenges to the list
                    video_hashtags.append(i.title)
                    
                    
                data[video.id] = {
                    "likes":video.stats.digg_count,
                    "shares": video.stats.share_count,
                    "comments": video.stats.comment_count,
                    "play_count": video.stats.play_count,
                    "description": video.desc,
                    
                    "video_info": {
                        "height": video.video.height,
                        "width": video.video.width,
                        "duration": video.video.duration,
                    },
                    
                    "hashtags": video_hashtags,
                    
                    "music_info": {
                        "title": video.music.title,
                        "author_name": video.music.author_name,
                        "original_audio": video.music.original,
                    }
                }
                
                print(video_hashtags)
                
                
                with open(f"Backend/hashtag_database_json/{challenge.title}/{current_time}.json", 'w') as f:
                    json.dump(data, f, indent=4)
                    

@Russell-Newton Russell-Newton added the enhancement New feature or request label Jan 21, 2023
@Russell-Newton
Copy link
Owner

I'll have to look into this more, but this problem arises because of how TikTok presents videos if you go to a tag's page.

TikTokPy simply visits the tag page to grab videos, but this means its subject to however TikTok wants to present the videos. TikTok decides video order by its algorithm, which means the videos aren't sorted by recent or even popular, just by what TikTok thinks you'd want to see. And because TikTokPy doesn't log in, this is a generic suggestion that doesn't change.

It's possible there's some API calls I could make to get recent videos tagged with a challenge, but at the moment I'm unsure if this is something I can do.

@AlwynHD
Copy link

AlwynHD commented Jul 3, 2023

Hi i have been using the code above to get a large array of tiktoks back however it throws an error:

    self._api.video(video.id) for video in converted.item_list
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing
itemInfo.itemStruct.video.downloadAddr
  Field required [type=missing, input_value={'cover': 'https://p77-si...meInfo': {}, 'width': 0}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.0.1/v/missing

@eelegiap
Copy link

eelegiap commented Aug 18, 2023

I'm having the same issue as @smithperez. Wish there was a way around this, but I'm not sure how. I guess it is not possible to sort videos on the tag page.

@Russell-Newton
Copy link
Owner

I'm having the same issue as @smithperez. Wish there was a way around this, but I'm not sure how. I guess it is not possible to sort videos on the tag page.

Yeah unless TikTok creates a way to sort on a tag page, this gets very complicated to do. I've got some ideas for how to grab random videos tagged with something, but I haven't had a chance to try it out yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants