HA6Bots / TikTok-Compilation-Video-Generator

A system of bots that collects clips automatically via custom made filters, lets you easily browse these clips, and puts them together into a compilation video ready to be uploaded straight to any social media platform. Full VPS support is provided, along with an accounts system so multiple users can use the bot at once. This bot is split up into three separate programs. The server. The client. The video generator. These programs perform different functions that when combined creates a very powerful system for auto generating compilation videos.
https://www.youtube.com/watch?v=Ua-NbCDuYrE
MIT License
766 stars 121 forks source link

Error Downloading Clips #12

Open Mitix-EPI opened 3 years ago

Mitix-EPI commented 3 years ago

In TikTokServer, when I try to dl (clicking on Start Downloading), there are some errors on the terminal. I added some print to debug the thing

Downloading...
Downloading Clip 1/9
VideoFiles Zach King6932104074846375173
<pymediainfo.MediaInfo object at 0x0000017D3FA53940>
[<Track track_id='None', track_type='General'>]
<Track track_id='None', track_type='General'>
None
float() argument must be a string or a number, not 'NoneType'
Error downloading clip
Downloading Clip 2/9
VideoFiles user5066131102056930292632715382021
Exception in callback _ProactorBasePipeTransport._call_connection_lost(None)
handle: <Handle _ProactorBasePipeTransport._call_connection_lost(None)>
Traceback (most recent call last):
  File "C:\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Python38\lib\asyncio\proactor_events.py", line 162, in _call_connection_lost
    self._sock.shutdown(socket.SHUT_RDWR)
ConnectionResetError: [WinError 10054] Une connexion existante a dû être fermée par l’hôte distant
<pymediainfo.MediaInfo object at 0x0000017D3FAF6640>
[<Track track_id='None', track_type='General'>]
<Track track_id='None', track_type='General'>
None
float() argument must be a string or a number, not 'NoneType'
Error downloading clip

TikTokServer/tiktok.py

try:
            api.downloadVideoById(clip.id, f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")
            media_info = MediaInfo.parse(f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")
            print(media_info)
            print(media_info.tracks)
            print(media_info.tracks[0])
            duration = media_info.tracks[0].duration
            print(duration)
            clip.vid_duration = float(duration) / 1000
            database.updateStatusWithClip(clip.id, "DOWNLOADED", clip)
except Exception as e:
            print(e)
            print("Error downloading clip")
            database.updateStatusWithClip(clip.id, "BAD", clip)

I think the error is from the MediaInfo. MediaInfo.parse does not read correctly the file.

Also, when I open Clip Bin, I can't play the videos. I don't know why ? Format mp4, ~380ko. I also try to read the informations inside the videos with the MediaInfo software but impossible to read any information.

alzeric commented 3 years ago

This may be an issue with the avilash TikTokAPI or could be Token Related not sure right now. If you peer into the "Broken" mp4 that get outputted into the VideoFiles folder you'll see the following. (Open with Text Editor or view with VSCode)

`

Access Denied

Access Denied

You don't have permission to access "http://v16-web.tiktok.com/video/tos/useast2a/tos-useast2a-ve-0068c003/266a4097bbec490ebbb277817c074f2a/?" on this server.

Reference #18.54a8ce17.1616762934.62c4c265 ` [EDIT] Upon further Inspection the issue is with the .downloadVideoById method in the avilash TikTokAPI Here is a quick fix until the API can be properly fixed

tiktok.py

[Top Imports Section Add]

import requests
import time

[Replace]

      try:
            api.downloadVideoById(clip.id, f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")            
            media_info = MediaInfo.parse(
                f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")
            duration = media_info.tracks[0].duration
            clip.vid_duration = float(duration) / 1000
            database.updateStatusWithClip(clip.id, "DOWNLOADED", clip)

[With]

      try:
            #api.downloadVideoById(clip.id, f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")
            download_file = requests.get(clip.url)
            with open(f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4", 'wb') as f:
                f.write(download_file.content)
            media_info = MediaInfo.parse(
                f"{settings.vid_filepath}/{clip.author_name}-{clip.id}.mp4")
            duration = media_info.tracks[0].duration
            clip.vid_duration = float(duration) / 1000
            database.updateStatusWithClip(clip.id, "DOWNLOADED", clip)
            time.sleep(1) 

Note: I added a 1 second sleep after each video download as TikTok has been started banning residential IPs and/or throttling, this slight delay should help keep them off your back