Coder Social home page Coder Social logo

twitter-video-dl's Introduction

twitter-video-dl

Download twitter videos as mp4 files without API key, ffmpeg, or anything but python and a url.

Usage

  1. Clone the repo and pip install -r requirements.txt (just the requests library)
  2. See a video on twitter that you want to save.
  3. Invoke the script, e.g.: python twitter-video-dl.py https://twitter.com/willowhalliwell/status/1452460936116244482 output_file_name

Done, now you should have an mp4 file of the highest bitrate version of that video available.

Auto Retry Feature

From time to time, every week or so, Twitter will add some new request parameters that they expect from callers asking for their content. Twitter refers to these as "features" or "variables". The twitter-video-dl script will try to detect when a new feature or variable has been added and automatically accommodate the new element. This is not foolproof though. It's possible the script will fail with an error message. If it does, please open an issue (or send a PR).

Other

I have tested this with the 10 video files listed in test_videos.txt and it seems to work. Highly possible there are other variants out there that this won't work for. If you encounter such, please submit an issue and include the URL that doesn't work. If the script doesn't work double check you have the URL right.

twitter-video-dl's People

Contributors

0xbaguette avatar daav-dd avatar inteoryx avatar jperry004 avatar perkinss27 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

twitter-video-dl's Issues

Help!!!

Can't get guest token tonight. Everything works fine until today. The response cookie doesn't contain "gt" anymore.

Downloaded videos don't play

I tried to download some videos from the examples in the repo, but the saved MP4 doesn't play.
Even FFmpeg can't read it, it says:

$ ffmpeg -i output_file_name.mp4 a.mp4
ffmpeg version git-2020-07-25-7c8ad72 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --enable-nonfree --enable-cuda-nvcc --enable-libnpp --enable-gpl --enable-libx264 --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64
  libavutil      56. 57.100 / 56. 57.100
  libavcodec     58. 97.102 / 58. 97.102
  libavformat    58. 49.100 / 58. 49.100
  libavdevice    58. 11.101 / 58. 11.101
  libavfilter     7. 87.100 /  7. 87.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56196acbedc0] could not find corresponding trex (id 1)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56196acbedc0] could not find corresponding track id 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56196acbedc0] trun track id unknown, no tfhd was found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56196acbedc0] error reading header
output_file_name.mp4: Invalid data found when processing input

BadRequest Error 400

So I try to run the script just as the example says ->
$ python3 twitter-video-dl.py https://twitter.com/willowhalliwell/status/1452460936116244482 output

Instead of downloading, this is what I get:

Traceback (most recent call last):
File "/home/desktop/twitter-video-dl/twitter-video-dl.py", line 25, in
tvdl.download_video(args.twitter_url, file_name)
File "/home/desktop/twitter-video-dl/src/twitter_video_dl/twitter_video_dl.py", line 139, in download_video
status_resp = send_request(
File "/home/desktop/twitter-video-dl/src/twitter_video_dl/twitter_video_dl.py", line 23, in send_request
assert response.status_code == 200, f"Failed request to {url}. {response.status_code} {response_json}. Please submit an issue including this information."
AssertionError: Failed request to https://twitter.com/i/api/graphql/T0I8jIOz1Cfea00BjAXyfA/TweetDetail?variables=%7B%22focalTweetId%22%3A%221452460936116244482%22%2C%22with_rux_injections%22%3Afalse%2C%22includePromotedContent%22%3Atrue%2C%22withCommunity%22%3Atrue%2C%22withQuickPromoteEligibilityTweetFields%22%3Atrue%2C%22withBirdwatchNotes%22%3Afalse%2C%22withSuperFollowsUserFields%22%3Atrue%2C%22withDownvotePerspective%22%3Afalse%2C%22withReactionsMetadata%22%3Afalse%2C%22withReactionsPerspective%22%3Afalse%2C%22withSuperFollowsTweetFields%22%3Atrue%2C%22withVoice%22%3Atrue%2C%22withV2Timeline%22%3Atrue%7D&features=%7B%22dont_mention_me_view_api_enabled%22%3Atrue%2C%22interactive_text_enabled%22%3Atrue%2C%22responsive_web_uc_gql_enabled%22%3Afalse%2C%22responsive_web_edit_tweet_api_enabled%22%3Afalse%2C%22vibe_tweet_context_enabled%22%3Atrue%2C%22standardized_nudges_for_misinfo_nudges_enabled%22%3Afalse%7D. 400 {'errors': [{'message': 'The following features cannot be null: responsive_web_enhance_cards_enabled, standardized_nudges_misinfo', 'extensions': {'name': 'BadRequestError', 'source': 'Client', 'code': 336, 'kind': 'Validation', 'tracing': {'trace_id': '98a7322fba760064'}}, 'code': 336, 'kind': 'Validation', 'name': 'BadRequestError', 'source': 'Client', 'tracing': {'trace_id': '98a7322fba760064'}}]}. Please submit an issue including this information.

Not working 400

emm

Traceback (most recent call last):
File "C:\Users\Phantasm\Downloads\twitter-video-dl-main\twitter-video-dl-main\twitter-video-dl.py", line 25, in
tvdl.download_video(args.twitter_url, file_name)
File "C:\Users\Phantasm\Downloads\twitter-video-dl-main\twitter-video-dl-main\src\twitter_video_dl\twitter_video_dl.py", line 382, in download_video
assert len(
^^^^
AssertionError: Could not find any mp4s to download. Make sure you are using the correct url. If you are, then file a GitHub issue and copy and paste this message. Tweet url: https://twitter.com/0521MissA/status/1664475514055315456

Status code: 404.

python twitter-video-dl.py https://twitter.com/juliann38915202/status/1694734291752886589 output
The question is as follows:
assert details.status_code == 200, f'Failed to get tweet details. 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: {details.status_code}. Tweet url: {tweet_url}' AssertionError: Failed to get tweet details. 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: 404. Tweet url: https://twitter.com/juliann38915202/status/1694734291752886589

/

/

No longer working

Bot is no longer working without account
Any suggestions to auth code? @inteoryx

It does not work with CSRF token either :(

statuscode 404

PS C:\Users\MicZon\twitter-video-dl> python twitter-video-dl.py https://twitter.com/i/status/1706676593261785178 output_file_name
Traceback (most recent call last):
get_tweet_details
assert details.status_code == 200, f'Failed to get tweet details. 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: {details.status_code}. Tweet url: {tweet_url}'
^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Failed to get tweet details. 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: 404. Tweet url: https://twitter.com/i/status/1706676593261785178

Failed to get tweet details

Couldn't download one of my own videos from twitter:

Status code: 404.
Tweet url: https://twitter.com/never_tomorrow/status/1327680318002900992

with some extra debug output below:

OUTPUT:

`(venv) C:[...]\PythonTwitterVideoScraper\Python>python twitter-video-dl.py https://twitter.com/never_tomorrow/status/1327680318002900992 test.mp4
args.twitter_url: https://twitter.com/never_tomorrow/status/1327680318002900992
file_name: test.mp4

get_tweet_details()

url:https://twitter.com/i/api/graphql/wTXkouwCKcMNQtY-NcDgAA/TweetDetail?variables=%7B%22with_rux_injections%22%3A%20false%2C%20%22includePromotedContent%22%3A%20true%2C%20%22withCommunity%22%3A%20true%2C%20%22withQuickPromoteEligibilityTweetFields%22%3A%20true%2C%20%22withBirdwatchNotes%22%3A%20true%2C%20%22withDownvotePerspective%22%3A%20false%2C%20%22withReactionsMetadata%22%3A%20false%2C%20%22withReactionsPerspective%22%3A%20false%2C%20%22withVoice%22%3A%20true%2C%20%22withV2Timeline%22%3A%20true%2C%20%22focalTweetId%22%3A%20%221327680318002900992%22%7D&features=%7B%22responsive_web_graphql_exclude_directive_enabled%22%3A%20true%2C%20%22verified_phone_label_enabled%22%3A%20false%2C%20%22responsive_web_graphql_timeline_navigation_enabled%22%3A%20true%2C%20%22responsive_web_graphql_skip_user_profile_image_extensions_enabled%22%3A%20false%2C%20%22tweetypie_unmention_optimization_enabled%22%3A%20true%2C%20%22vibe_api_enabled%22%3A%20false%2C%20%22responsive_web_edit_tweet_api_enabled%22%3A%20false%2C%20%22graphql_is_translatable_rweb_tweet_is_translatable_enabled%22%3A%20false%2C%20%22view_counts_everywhere_api_enabled%22%3A%20true%2C%20%22longform_notetweets_consumption_enabled%22%3A%20true%2C%20%22tweet_awards_web_tipping_enabled%22%3A%20false%2C%20%22freedom_of_speech_not_reach_fetch_enabled%22%3A%20false%2C%20%22standardized_nudges_misinfo%22%3A%20false%2C%20%22tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled%22%3A%20false%2C%20%22interactive_text_enabled%22%3A%20false%2C%20%22responsive_web_twitter_blue_verified_badge_is_enabled%22%3A%20true%2C%20%22responsive_web_text_conversations_enabled%22%3A%20false%2C%20%22longform_notetweets_richtext_consumption_enabled%22%3A%20false%2C%20%22responsive_web_enhance_cards_enabled%22%3A%20false%7D
bearer_token:AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA

guest_token:1716764611653878046

details:<Response [404]>

details.status_code:404

Traceback (most recent call last):
File "twitter-video-dl.py", line 26, in
tvdl.download_video(args.twitter_url, file_name)
File "C:[...]\PythonTwitterVideoScraper\Python\src\twitter_video_dl\twitter_video_dl.py", line 365, in download_video
resp = get_tweet_details(tweet_url, guest_token, bearer_token)
File "C:[...]\PythonTwitterVideoScraper\Python\src\twitter_video_dl\twitter_video_dl.py", line 160, in get_tweet_details
assert details.status_code == 200, f'Failed to get tweet details. 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: {details.status_code}. Tweet url: {tweet_url}'
AssertionError: Failed to get tweet details. 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: 404. Tweet url: https://twitter.com/never_tomorrow/status/1327680318002900992`

assert html.status_code == 200

Traceback (most recent call last):
File "D:\twitterdl\twitter-video-dl-main\twitter-video-dl-main\twitter-video-dl.py", line 25, in
tvdl.download_video(args.twitter_url, file_name)
File "D:\twitterdl\twitter-video-dl-main\twitter-video-dl-main\src\twitter_video_dl\twitter_video_dl.py", line 347, in download_video
bearer_token, guest_token = get_tokens(tweet_url)
^^^^^^^^^^^^^^^^^^^^^
File "D:\twitterdl\twitter-video-dl-main\twitter-video-dl-main\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/i/status/1742984356245758033

Error 404

I couldn't really find out why this is happening, is it because it's a subtweet?
AssertionError: Failed to get tweet details. 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: 404. Tweet url: https://twitter.com/ahmedyehia___/status/1749889932410208674

Response code 400

Thanks for your library

Reloaded modules: dl_video.twitter_video_dl, dl_video.twitter_video_dl.twitter_video_dl
Traceback (most recent call last):

File "C:\Users..\Twitter Project\download_videos.py", line 14, in
tvdl.download_video('https://twitter.com/willowhalliwell/status/1452460936116244482', '1522952577809223681.mp4')

File "C:\Users..\Twitter Project\dl_video\twitter_video_dl\twitter_video_dl.py", line 104, in download_video
f"{STATUS_ENDPOINT}{query_id}/{status_params}", session.get, headers)

File "C:\Users..\Twitter Project\dl_video\twitter_video_dl\twitter_video_dl.py", line 17, in send_request
assert response.status_code == 200, f"Failed request to {url}. {response.status_code}. Please submit an issue including this information."

AssertionError: Failed request to https://twitter.com/i/api/graphql/GKajRJ_uQ1wdg6Zs0xvIuA/TweetDetail?variables=%7B%22focalTweetId%22%3A%221452460936116244482%22%2C%22with_rux_injections%22%3Afalse%2C%22includePromotedContent%22%3Atrue%2C%22withCommunity%22%3Atrue%2C%22withQuickPromoteEligibilityTweetFields%22%3Afalse%2C%22withTweetQuoteCount%22%3Atrue%2C%22withBirdwatchNotes%22%3Afalse%2C%22withSuperFollowsUserFields%22%3Atrue%2C%22withUserResults%22%3Atrue%2C%22withNftAvatar%22%3Afalse%2C%22withBirdwatchPivots%22%3Afalse%2C%22withReactionsMetadata%22%3Afalse%2C%22withReactionsPerspective%22%3Afalse%2C%22withSuperFollowsTweetFields%22%3Atrue%2C%22withVoice%22%3Atrue%2C%22withDownvotePerspective%22%3Afalse%7D. 400. Please submit an issue including this information.

Wrong video downloaded

Hi,
while playing with your code, I figured out that for this specific tweet it wouldn't download the actual tweet video but the one from the first showed reply.
My code :
tweet_url = "https://twitter.com/nocontexthumans/status/1641810447358631938"
tvdl.download_video(tweet_url, "tweetVideo2.mp4")

First frame of the tweet's video :

scr1

First frame of the downloaded video :

scr2

If you have some free time, please try to replicate this bug on your side to see if it's unique to my setup or if it's a global bug.

Thank you for keeping this repo alive.

EDIT 1 :

I guess that I am the one wrong here. It looks like the author of the tweet I sent earlier just "reposted" a video and did not post it directly to twitter through its account as we can see here :

It could be a cool feature to download videos in such cases though, because we do not always think to open the original video's tweet.

EDIT 2 :

So I wasn't totally wrong because I found this tweet while trying to code a solution.
This tweet still cause the bug to occur, even if it's not a repost.
It still downloads the first showed video in the replies but this tweet's video isn't reposted.
As you can see both tweets feature the same video (the first one is a repost) because my solution to this bug was to extract the url of the source tweet (that contain the non reposted video) and then to send it back to the download_video function, so I could get the video, even from a reposted tweet.

EDIT 3 :

The bug actually come from the extract_mp4s function. Your ext_tw_pattern regular expression actually find the video url, but
the function automatically returns container urls if it find some :
scr222

It then skips any other video url, which in my case include the one I want.
In fact, in this tweet case the tweet video url is :
https://video.twimg.com/ext_tw_video/1641074057524174848/pu/vid/404x720/YvImuEf6bgC5P9jl.mp4?tag=12
While the first showed video in the replies has this url :
https://video.twimg.com/ext_tw_video/1634237199096123392/pu/pl/ig4YOUAgpgyowlbd.m3u8?tag=12&container=fmp4

Given that it's a container url, extract_mp4s directly returns this video link which causes this bug.

Automatic download

Jello there
Want to ask would it be possible to get this script work in loop monitoring users list and any new tweet contain a video from anyone name/user on the list the script will download that video
In downloads folder in this format
/home/downloads/usernick/video file - dated-ext

Thanks and hope this suggestion catch your eyes and made a road map to do it

not working

assert query_id, f"Did not find query id. Are you sure you used the right twitter URL? {video_url}"

Downloaded video is split and out of order

When trying to download one of the example videos python3.8 twitter-video-dl.py https://twitter.com/crabcrawler1/status/1460400562176987145 output_file_name, the output comes in four parts, and they are not in the correct order of the original video.

Status code: 400.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.