Suppose you would like to download a Twitter embedded video for future usage. Some of the videos are just mp4 files, and they can be easily downloaded by looking at the page source and directly open the link.
But sometimes you see something like this:
<video preload="none" playsinline="" style="width: 100%; height: 100%; position: absolute; background-color: black; transform: rotate(0deg) scale(1.005);" poster="https://pbs.twimg.com/ext_tw_video_thumb/1083861042181144576/pu/img/Z7CzxlIrm3-5td39.jpg" src="blob:https://twitter.com/0e462ebf-795f-e648-a766-4462a3e1ee5d"></video>
What is that? A blob video? Don’t get mad, the lazyweb always comes in rescue.
Open the tweet in another page, open the browser console (typically F12 or ⌘ + ⇧ + i) and click on the Network tab. You will see all the resource fetched for the page, and among them there should be a m3u8 file. What is that? Simply a multimedia playlist!
Right click on the m3u8 file and select Copy URL. Now go to console and feed that url to youtube-dl.
It will fetch the playlist, download all the video segments and merge them with ffmpeg. It takes few seconds, and the result is the whole video, usually saved as mp4.
$ youtube-dl https://video.twimg.com/ext_tw_video/1083861042181144576/pu/pl/HIUSpLP6H0q4JGdt.m3u8\?tag\=8
[generic] HIUSpLP6H0q4JGdt: Requesting header
[generic] HIUSpLP6H0q4JGdt: Downloading m3u8 information
[download] Destination: HIUSpLP6H0q4JGdt-HIUSpLP6H0q4JGdt.mp4
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-opencl --enable-videotoolbox
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[hls,applehttp @ 0x7f97ed802000] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/0/3000/414x720/oO-J3tZvt3e1FI4X.ts' for reading
[hls,applehttp @ 0x7f97ed802000] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/3000/6000/414x720/FIGnFA6AUn6eVAK9.ts' for reading
Input #0, hls,applehttp, from 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/pl/414x720/QOIrugj54yK1xVMD.m3u8':
Duration: 00:00:49.90, start: 3.000000, bitrate: 0 kb/s
Program 0
Metadata:
variant_bitrate : 0
Stream #0:0: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p, 414x720, 23.75 fps, 23.75 tbr, 90k tbn, 50 tbc
Metadata:
variant_bitrate : 0
Stream #0:1: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp
Metadata:
variant_bitrate : 0
Output #0, mp4, to 'file:HIUSpLP6H0q4JGdt-HIUSpLP6H0q4JGdt.mp4.part':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 414x720, q=2-31, 23.75 fps, 23.75 tbr, 90k tbn, 90k tbc
Metadata:
variant_bitrate : 0
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp
Metadata:
variant_bitrate : 0
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/6000/9000/414x720/R5Fg1BJ8cpdH-wqB.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/9000/12000/414x720/06wvoQLlQW8tK6fc.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/12000/15000/414x720/Y1qSwXOybn036JVo.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/15000/18000/414x720/fSuqUyg250MlKCIx.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/18000/21000/414x720/7nj3lJFKsUwsOppn.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/21000/24000/414x720/ldQahm7jF2r7qH7n.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/24000/27000/414x720/rh6L9N5QOwF_vJAC.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/27000/30000/414x720/Vg7amM1CRQt-b8Xm.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/30000/33000/414x720/sN9eF4l7UMfcVRws.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/33000/36000/414x720/15yUDCP7oir4Zju5.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/36000/39000/414x720/CSzxl0t2yL5oRZsf.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/39000/42000/414x720/UOm2B2QtjBSt9_4B.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/42000/45000/414x720/kYZBW3BvUer1JIVr.ts' for reading
[https @ 0x7f97ed804800] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/45000/48000/414x720/1Ea_rNaMwxSYxpOL.ts' for reading
[https @ 0x7f97ed018200] Opening 'https://video.twimg.com/ext_tw_video/1083861042181144576/pu/vid/48000/49895/414x720/lQnPgxYrt_y9RCCq.ts' for reading
frame= 1185 fps=0.0 q=-1.0 Lsize= 2351kB time=00:00:49.87 bitrate= 386.1kbits/s speed=72.4x
video:1906kB audio:411kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.455244%
[ffmpeg] Downloaded 2407189 bytes
[download] 100% of 2.30MiB in 00:01
Header photo by William Bayreuther on Unsplash
Thank you for being my lazyweb rescue for today, when I could not find the right resource URL to feed into youtube-dl for saving a crucial cat video from oblivion in the twitter-verse.