Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[Twitter] Extract mp4 urls via mobile User-Agent #12726
Comments
|
Any example of User-Agent and Tweet URL combination that has |
|
@singhpratyush: Not sure what you want. Hasn't @dban0001 already mentioned one?
|
|
@yan12125: I was looking for a User Agent for which $ http <some_url> User-Agent:<some_user_agent>
...
<video ... >
...
<source src="https://video.twimg.com/amplify_video/<ID>/vid/<resolution>/<some_stirng>.mp4" ...>
</video>
...I have seen that these links are generated in |
|
mp4 URLs are not embedded in web pages. Here's the flow:
<script crossorigin="anonymous" onerror="showFailureMessage('https://ma-0.twimg.com/twitter-assets/responsive-web/web/ltr/main.5b6bf12947d7a3a6.js');" src="https://ma-0.twimg.com/twitter-assets/responsive-web/web/ltr/main.5b6bf12947d7a3a6.js"></script>The "bearer" token can be found in https://ma-0.twimg.com/twitter-assets/responsive-web/web/ltr/main.5b6bf12947d7a3a6.js: BEARER_TOKEN: "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA",
<script>
document.cookie = decodeURIComponent("gt=869422393856360448; Max-Age=10800; Domain=.twitter.com; Path=/");
</script>869422393856360448 is the desired token.
The result is: [
{
"content_type": "application/x-mpegURL",
"url": "https://video.twimg.com/amplify_video/852077943283097602/pl/W1KWzvz9IQtK55D2.m3u8"
},
{
"bitrate": 832000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/852077943283097602/vid/640x360/e23l2ZGkx7rHBOY2.mp4"
},
{
"bitrate": 320000,
"content_type": "video/mp4",
"url": "https://video.twimg.com/amplify_video/852077943283097602/vid/320x180/wSdL-TycEjbLuseN.mp4"
}
]Here 852138619213144067 is the tweet ID, which is cut from the URL. It turns out that a mobile User-Agent string is not necessary. It just helps on analyzing the behavior of twitter video pages. |
|
Hey, any more details on getting the guest token? I do not seem to be able to get this from this page, it just doesn't appear on there. I've only found gt, when opening mobile.twitter.com, in an anonymous window and inspecting session cookies, but I totally can't find a way to make curl get it. Because even if it's logged out, even with no cookies, no cache policy, this cookie will not be sent, even though it will be available on a browser. |
|
@isklikas: Check the work-in-progress version at https://github.com/yan12125/youtube-dl/tree/wip-twitter-12726, especially the |
|
The way you suggested above, along with getting the guest token from a modern mobile client (that's the only part I've missed myself), actually seems to work for every video for me! I wrote it in Objective C, where I set the same headers and ephemeral session, which is just the name for "anonymous window" in iOS NSURLSessions. Thank you very much!
… On 15 Jun 2017, at 14:48, Yen Chi Hsuan ***@***.***> wrote:
There's a work-in-progress version at https://github.com/yan12125/youtube-dl/tree/wip-twitter-12726. It works for https://twitter.com/news_al3alm/status/852138619213144067 but I haven't checked it doesn't break other videos.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
This will be fixed in the next version. Sorry for being late as I was quite busy last month. |
|
I moved mi original comment to #17233 |
|
@yan12125 hey brother
"In the web page there's a line", I haven't found this line in web page, what is the web page url? Just like: https://twitter.com/news_al3alm/status/852138619213144067? |
|
Most likely Twitter mobile pages have changed over time. Also, I consider this approach stale as HLS streams are served even on mobile devices now. |
Make sure you are using the latest version: run
youtube-dl --versionand ensure your version is 2017.04.11. If it's not read this FAQ entry and update. Issues with outdated version will be rejected.Before submitting an issue make sure you have:
What is the purpose of your issue?
I want to have mp4 files from the --dump-json output. When I paste a twitter link, only a m3u8 url returns – although the video is available as mp4.
Example:
Twitter URL: https://twitter.com/news_al3alm/status/852138619213144067
Download URL (mp4, not from youtube-dl): https://video.twimg.com/amplify_video/852077943283097602/vid/640x360/e23l2ZGkx7rHBOY2.mp4
What youtube-dl does:
It also doesn't work if I provide -f best or -f mp4.