Topic: How to download gif/videos from Twitter using Youtube-dl in 2024?

Posted under Off Topic

Tried to follow some guides, some say I have to copy my auth key from the cookies but it skips saying "invalid length", without it if I try twitter "unable to download json data", "x" it is "error 403 forbidden" so I am a bit stumped in what I could do lol, maybe I am using a wrong version?

Is using Jdownloader2 a good alternative?

notknow said:
Tried to follow some guides, some say I have to copy my auth key from the cookies but it skips saying "invalid length", without it if I try twitter "unable to download json data", "x" it is "error 403 forbidden" so I am a bit stumped in what I could do lol.

Is using Jdownloader2 a good alternative?

If you're planning on uploading to e6, you'll need Youtube Premium

you'll have to update to the latest version of yt-dlp
https://github.com/yt-dlp/yt-dlp

older versions of even yt-dlp only had a concept of the twitter.com domain and didn't have x.com on their list i guess. i ran across this problem before and just had to do a basic update

I remember Mairo recommending the "-f best -g" parameters, tried that and the cmd screamed at me saying "but if you really want it use -f b" but...it didn't download anything lol.

Without these parameters it did download the video...but then said I dont have ffmpeg installed lol.

I will have to convert to .mkv after that right? Or is there something that can make it automatic with yt-dlp?

thegreatwolfgang said:
Youtube-dl is obsolete, make sure you are using yt-dlp like @Dripen_Arn has mentioned above.

And this is exactly why I hate giving out instructions, especially for one specific software, because when time moves on, things change like this and now the old instructions are obsolete and even hinderance.

notknow said:
I remember Mairo recommending the "-f best -g" parameters, tried that and the cmd screamed at me saying "but if you really want it use -f b" but...it didn't download anything lol.

Without these parameters it did download the video...but then said I dont have ffmpeg installed lol.

I will have to convert to .mkv after that right? Or is there something that can make it automatic with yt-dlp?

Because -g is option to print the URL into the command line instead of downloading anything. This way you can put the URL to the file into the sources, so that people can access and download that without needing to do any of this.
Also with ๐• it is literally just MP4 file, so when you get the URL, you can just download it as is with your browser. With Windows 11 command prompt, you can also CTRL+Click the link to open it immidiately.

Reason for warning is that -f best is, really missleading at best, because especially on youtube, the "best" is the highest resolution video track that is not DASH, meaning 720p h264, even if video was 4K and VP9 already. However this was required with Twitter because othervice it could select lower resolution tracks.
That's also why yt-dlp warns about this because they know that it's not actually best most of the time, so it gives warning to user that if they want best, using -f best might not actually give it with many websites.

If the video file is not available as video directly, the software uses FFmpeg to compile it back into such, e.g. with Youtube, the DASH breaks the video into hundreds of parts, which have to be individually downloaded.

notknow said:
I remember Mairo recommending the "-f best -g" parameters, tried that and the cmd screamed at me saying "but if you really want it use -f b" but...it didn't download anything lol.

Without these parameters it did download the video...but then said I dont have ffmpeg installed lol.

I will have to convert to .mkv after that right? Or is there something that can make it automatic with yt-dlp?

While I wouldn't recommend downloading videos from Twitter/X since the quality is subpar, you will need to convert it from the original .mp4 to .webm to upload here on e6 (see e621:supported filetypes).

You can refer to the how-to I have written for yt-dlp on my profile page to get started. It is written for downloading YouTube videos, but the steps are mostly the same for Twitter.

Getting Started and Downloading from YouTube
  • YouTube Downloader & Video Converter (useful for downloading YouTube videos and in the desired format)
    • 1) Make sure both yt-dlp.exe and ffmpeg.exe are in the same folder.
    • 2) Launch the Command Prompt app, and copy-paste the application path of yt-dlp.exe into the command line.
    • 3) Insert the YouTube video link using the command "C:\...\yt-dlp.exe" -F https://www.youtube.com/watch?v=XXXXXXXXXXX and press Enter to find the available video and audio files.
      • If the video is age-restricted, make sure you are signed into Google first and then use the alt command "C:\...\yt-dlp.exe" --cookies-from-browser BROWSER -F https://www.youtube.com/watch?v=XXXXXXXXXXX. Change BROWSER to the default browser you are using (e.g., chrome, firebox, edge, etc.).
    • 4) Check through the available video resolution and audio files on the list and remember the IDs for the desired format.
      • MP4+M4A will generate an .mp4 video, WEBM+WEBM will generate a .webm video, and a combination between them will generate a .mkv video.
      • For uploading to e621, choose the highest WEBM+WEBM files and make sure they stay within the file size limit. Videos with small resolutions and/or currently being monetised will be deleted.
    • 5) Insert the chosen IDs using the command "C:\...\yt-dlp.exe" -f <video ID>+<audio ID> https://www.youtube.com/watch?v=XXXXXXXXXXX and press Enter to start downloading.
      • Alternatively, insert "C:\...\yt-dlp.exe" --cookies ~/Downloads/cookies.txt -f <video ID>+<audio ID> https://www.youtube.com/watch?v=XXXXXXXXXXX to use cookies in downloading.
    • 6) Downloaded videos can be found in C:\Users\<username>.
      • If errors happen, remember to update your downloader to the latest version using "C:\...\yt-dlp.exe" -U.
Downloading from Twitter/X
  • You can just insert the link to the post (e.g., "C:\...\yt-dlp.exe" -F https://x.com/username/status/xxxxxxxxxx) and it will you a list of video formats available for download.
    • The list will be different from that of YouTube, in that all videos are already in .mp4 format. You just need to select one ID to download the video.
    • Ignore anything with the ID hls-audio-XXXXX-Audio, this is just the plain audio file with no video.
    • Ignore anything with the ID hls-XXXX, this is just the plain video file with no audio.
    • Choose the highest quality file with the largest file size from http-XXXX.
      • Your download command should appear as "C:\...\yt-dlp.exe" -f http-XXXX https://x.com/username/status/xxxxxxxxxx.
  • If the post is marked as NSFW, you will be required to log into a Twitter/X account to download it.
    • Easiest method: Have your account already logged in on your browser, then use an extension to extract the cookies for Twitter.
      • Rename the downloaded text file to cookies.txt and then get the list of IDs using the command "C:\...\yt-dlp.exe" --cookies ~/Downloads/cookies.txt -F https://x.com/username/status/xxxxxxxxxx.
      • Once you have the proper ID, download using the command "C:\...\yt-dlp.exe" --cookies ~/Downloads/cookies.txt -f http-XXXX https://x.com/username/status/xxxxxxxxxx.
    • Harder/Manual login method: Use the command "C:\...\yt-dlp.exe" --username AAA --password BBB -F https://x.com/username/status/xxxxxxxxxx to get the list of IDs.
      • Change AAA to your Twitter username (e.g., elonmusk) and BBB to your password.
      • If they ask you to provide your 2FA token, make sure you have selected the command prompt window first, then enter the code and press Enter. The code will NOT appear when you type in the command prompt, so your typing will be invisible until you press Enter.
      • Repeat the steps once you have the proper ID, using the command "C:\...\yt-dlp.exe" --username AAA --password BBB -f http-XXXX https://x.com/username/status/xxxxxxxxxx.
    • Note: The usual --cookies-from-browser BROWSER does not work in the current version of yt-dlp for some reason, at least for Chrome.

As for converting the downloaded .mp4 video to .webm, I can't give a solid answer to this so hopefully @Mairo can chip in.

Updated

Thanks for the info from both of you, I may have run the gun a bit and uploaded a conversion that I don't think it's good enough...

Next time what parameters I should use with FFMPEG to upload without losing quality? I am using the GUI QWinFF and tried to convert to WEBM.

I will hold my video uploads until I can make sure I am uploading it right...

Edit: There is one specific Ouka video that spits me an url with "m3u8" instead of "mp4", what to do in a case like this?
https://x.com/0uka/status/1340673417306021891

thegreatwolfgang said:
While I wouldn't recommend downloading videos from Twitter/X since the quality is subpar, you will need to convert it from the original .mp4 to .webm to upload here on e6 (see e621:supported filetypes).

Not my fault the artist only upload his videos to twitter and fanbox, and since fanbox is paid...

Updated

You know, I just realised that Twitter isn't as complex as YouTube in terms of the available formats and such.
You don't really need to use yt-dlp and can just resort to a simple online downloader (e.g., https://twittervideodownloader.com/) without all the hassle with command prompts.

notknow said:
Edit: There is one specific Ouka video that spits me an url with "m3u8" instead of "mp4", what to do in a case like this?
https://x.com/0uka/status/1340673417306021891

If you are following my instructions, you should see that the m3u8 file is under the hls-XXXX ID while the mp4 file is under the http-XXXX ID.
Download using the http-XXXX ID or just use https://twittervideodownloader.com/ to get the video directly. There is literally no difference in quality.

Updated

thegreatwolfgang said:
You know, I just realised that Twitter isn't as complex as YouTube in terms of the available formats and such.
You don't really need to use yt-dlp and can just resort to a simple online downloader (e.g., https://twittervideodownloader.com/) without all the hassle with command prompts.

Yeah you are right...still I am not having luck with ffmpeg to convert it lol.

thegreatwolfgang said:
...
Download using the http-XXXX ID or just use https://twittervideodownloader.com/ to get the video directly. There is literally no difference in quality.

The reason why I do not recommend many of these twitter downloader sites is that many allow "GIF download" where the site takes MP4, converts it to GIF and then gives you that.
I would have to know that which one of these sites give direct links to ๐• servers, which most won't because then they wouldn't have as much users and less users to serve ads to, at which point yt-dlp just becomes objectively better to use.

mairo said:
The reason why I do not recommend many of these twitter downloader sites is that many allow "GIF download" where the site takes MP4, converts it to GIF and then gives you that.
I would have to know that which one of these sites give direct links to ๐• servers, which most won't because then they wouldn't have as much users and less users to serve ads to, at which point yt-dlp just becomes objectively better to use.

I have checked this already, videos downloaded from both yt-dlp and this particular site are identical.
If you inserted a GIF post here, it may display the download link as "GIF download" but the output is the direct MP4 link from Twitter. No automatic conversion is done here.

Of course, I wouldn't recommend using any online downloader/converter sites in general, but this one seems to be alright to use for Twitter.

  • 1