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

Download video/GIF #34

Open
sindresorhus opened this Issue Dec 23, 2017 · 5 comments

Comments

3 participants
@sindresorhus
Owner

sindresorhus commented Dec 23, 2017

Add a button to download the video/GIF in a tweet.

@gdad-s-river

This comment has been minimized.

Contributor

gdad-s-river commented Mar 11, 2018

I'll work on it.

@gdad-s-river

This comment has been minimized.

Contributor

gdad-s-river commented Mar 13, 2018

@sindresorhus @filipekiss

I did some research and tried. Twitter uses HTTP Live Streaming (HLS) protocol to stream its videos using MPEG Transport Streams (.ts files). Also, their video tags are blob URLs like so – 

<video 
  preload="none" 
  playsinline="" 
  src="blob:https://twitter.com/13f32643-9f8e-4048-a75a-84d124ba8324">
</video>

I can't help but think on the lines of

Somehow listen to .m3u8 files (which have upcoming .ts file (video streams) addresses), keep fetching .ts files until no more, pass them to a mux (something like mux.js) to get an .mp4 formatted data and then somehow download it. Doing this will be very time consuming I guess?

But at the same time through a simple google search I found https://twdown.net/, which is somehow able to find the .mp4 video file which is streamed on hitting the play button. Twitter doesn't have an API that one could use to fetch .mp4 files anymore. I wonder how they are able to do that, or if it's very obvious I'm missing something.

I'm stuck and could use some thought process / resource(s) / direction.

@filipekiss

This comment has been minimized.

Collaborator

filipekiss commented Mar 13, 2018

@gdad-s-river Yeah, it seems that the only way to provide proper video download, for now, would be to make a call to the old API (1.1), get the tweet data and there we could find the link to the MP4 directly instead of the blob. But that would eventually break if (when) Twitter disables that version of the API. twdown.net most likely uses the old API but even if they didn't, having a backend means they can use something like ffmpeg to stream from that blob url, save to a temporary file and then download it (but I'd bet they use the old API, at least for now. It's cheaper :P)

Maybe focus on image/gif downloads for now and we'll take a look at this later.

@sindresorhus

This comment has been minimized.

Owner

sindresorhus commented Mar 31, 2018

But that would eventually break if (when) Twitter disables that version of the API.

I'd be fine with using that. I don't think it will go away anytime soon, and we can deal with it then if so.

@filipekiss

This comment has been minimized.

Collaborator

filipekiss commented Apr 2, 2018

Great! Let me know if you need any help with this @gdad-s-river! I'll be glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment