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

Error Downloading Clips #12

Open
Mitix-EPI opened this issue Mar 6, 2021 · 1 comment
Open

Error Downloading Clips #12

Mitix-EPI opened this issue Mar 6, 2021 · 1 comment

Comments

@Mitix-EPI
Copy link

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
Copy link

alzeric commented Mar 26, 2021

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)

`

<TITLE>Access Denied</TITLE>

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

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

No branches or pull requests

2 participants