Mincka / DMArchiver

A tool to archive the direct messages, images and videos from your private conversations on Twitter
GNU General Public License v3.0
222 stars 25 forks source link

Download videos #6

Closed muesliq closed 7 years ago

muesliq commented 7 years ago

Neither the argument -di nor -dg currently downloads videos. Would be cool to add a -dv argument.

Mincka commented 7 years ago

I had a look into this but I've found out that the video are streamed so it would be a lot harder to download them. I did not find a direct link to download videos and I cannot rely on an external service to download them because content from private conversations are not accessible for unauthenticated users (thankfully).

Do you have any idea how to do it?

muesliq commented 7 years ago

Maybe https://github.com/rg3/youtube-dl does the trick?

Mincka commented 7 years ago

Interesting project, I will have a look into it. Thanks!

Mincka commented 7 years ago

It seems there's a bug on GitHub for the user referenced in the audit log... muesliq added the enhancement label 20 minutes ago

muesliq commented 7 years ago

Yup, I noticed that as well :-)

Mincka commented 7 years ago

Seems now possible via Twitter Lite: https://twitter.com/AndMucc/status/850428697870036993

I'm currently investigation how to automate. Steps to get the MP4 file:

1) Log (using Chrome) on https://mobile.twitter.com/ 2) Go to messages https://mobile.twitter.com/messages 3) Open the conversation https://mobile.twitter.com/messages/2350664221-2350664221 4) Open the tweet with the video https://mobile.twitter.com/messages/2350664221-2350664221/media/794917477981519875

The links (mp4/m3u8) are in the code: <video autoplay="" class="_1tHcaxlQ" controls="" poster="https://pbs.twimg.com/dm_video_preview/794911420198584321/img/4IoYosM9idmUyugqCIY2ndFIVL4cKxD87fU0o7KTyPc.jpg:small"><source src="https://video.twimg.com/dm_video/794911420198584321/vid/1280x720/I4j4aiFBQkHXnjMVLvSE1c9MUp_XADccQLuUf4tw2nE.mp4" type="video/mp4"><source src="https://video.twimg.com/dm_video/794911420198584321/pl/0NqSe4h-fGCEBZKJUCG0c4_abDUKA1eIfazohnh2a50.m3u8" type="application/x-mpegURL"><div class="_3f2NsD-H"><img src="https://pbs-h2.twimg.com/dm_video_preview/794911420198584321/img/4IoYosM9idmUyugqCIY2ndFIVL4cKxD87fU0o7KTyPc.jpg:small"><span class="Fe7ul3Lt">Votre navigateur ne prend pas en charge la lecture de cette vidéo.</span></div></video>

Note the "media/794917477981519875" part of the URL is added using JS and it is not possible to use the link to access directly to the page. I did not find yet how the links to the media are retrieved or are generated.

Also seen on the old Twitter Mobile (using IE) From the conversations, the tweets shows "pic.twitter.com/5KltZMb4ze" with a t.co link "https://t.co/5KltZMb4ze". The link redirects (301) to https://twitter.com/messages/media/794917477981519875

Change the host to mobile.twitter.com and we are redirected (302) to the MP4 file directly: https://video.twimg.com/dm_video/794911420198584321/vid/1280x720/I4j4aiFBQkHXnjMVLvSE1c9MUp_XADccQLuUf4tw2nE.mp4

Its seems to work only in IE for this one. With Chrome, it leads to a 404. Quite strange.

Currently, I retrieve in the log: [Media-video] https://twitter.com/i/videos/dm/794917477981519875

So its seems the most straightforward way to download the MP4 is to call and follow the redirection using this link with a user-agent which is not Chrome: https://mobile.twitter.com/messages/media/794917477981519875

P.S.: The last method seems to be also working with Firefox so I may keep the same user-agent in the script.