inteoryx / twitter-video-dl

Download twitter videos as mp4 files
The Unlicense
218 stars 52 forks source link

Status code: 400. #36

Open ylogachev opened 8 months ago

ylogachev commented 8 months ago

python twitter-video-dl.py https://twitter.com/iamyomas/status/1745417287631347837 test_twitter/test.mp4 Traceback (most recent call last): File "/Users/ylogachev/Development/fuckvpnbot/twitter-video-dl/twitter-video-dl.py", line 25, in tvdl.download_video(args.twitter_url, file_name) File "/Users/ylogachev/Development/fuckvpnbot/twitter-video-dl/src/twitter_video_dl/twitter_video_dl.py", line 347, in download_video bearer_token, guest_token = get_tokens(tweet_url) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/ylogachev/Development/fuckvpnbot/twitter-video-dl/src/twitter_video_dl/twitter_video_dl.py", line 37, in get_tokens assert html.status_code == 200, f'Failed to get tweet page. If you are using the correct Twitter URL this suggests a bug in the script. Please open a GitHub issue and copy and paste this message. Status code: {html.status_code}. Tweet url: {tweet_url}' AssertionError: Failed to get tweet page. If you are using the correct Twitter URL this suggests a bug in the script. Please open a GitHub issue and copy and paste this message. Status code: 400. Tweet url: https://twitter.com/iamyomas/status/1745417287631347837

7rikazhexde commented 8 months ago

@inteoryx @ylogachev

This issue is the same as https://github.com/7rikazhexde/twitter-video-dl-for-sc/issues/7. Some of the error output is different, but the function(get_tokens) in issue is the same.

In other words, this problem is caused by the browser not supporting it. You can access the tweet page by specifying the User-Agent in the header of the GET request, as shown below.

    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
        "Accept": "*/*",
        "Accept-Language": "de,en-US;q=0.7,en;q=0.3",
        "Accept-Encoding": "gzip, deflate, br",
        "TE": "trailers"
    }

    html = requests.get(tweet_url, headers=headers)

Although I am proposing a fix in the pull request below along with other issues, https://github.com/inteoryx/twitter-video-dl/pull/33

There was a problem with the following fix. Therefore, I would like to update the pull request to fix it along with the above issue.

  1. Addition of URL detection pattern (x)