Schnee (schnee) wrote,

HTTP Live Streaming downloads

If you're finding yourself wanting to save a video that's available on the web, but only served in the form of a bunch of TS files over HTTP Live Streaming (HLS), you may want to take a look at m3u8downloader. It's a command line tool, but you really only need to have Python installed, and it also works on Windows just fine, though you may have to hunt for the executable after installing it (it'll likely be in %APPDATA%\Python\Python38\Scripts, with the obvious adjustment if you're using a different Python version).

Using it is easy enough, too:

$ /path/to/downloadm3u8 '' -o outputfile.mp4
2020-08-27 13:47:04,326 INFO     chose resolution=1920x1080 uri=[...]
2020-08-27 13:47:04,570 INFO     http links rewrote in m3u8 file: [...]
2020-08-27 13:47:04,851 INFO     playlist has 627 fragments
2020-08-27 13:47:31,846 INFO     [ 2%]  10/627 fragments fetched
2020-08-27 13:47:58,210 INFO     [ 3%]  20/627 fragments fetched
2020-08-27 13:48:23,242 INFO     [ 5%]  30/627 fragments fetched
2020-08-27 14:13:24,966 INFO     [97%] 610/627 fragments fetched
2020-08-27 14:13:47,360 INFO     [99%] 620/627 fragments fetched
2020-08-27 14:13:48,842 INFO     100%, 627 fragments fetched
2020-08-27 14:13:48,898 INFO     media playlist all fragments downloaded
2020-08-27 14:13:48,898 INFO     Running: ['ffmpeg', '-loglevel', 'warning', '-allowed_extensions', 'ALL', '-i', '[...]', '-acodec', 'copy', '-vcodec', 'copy', '-bsf:a', 'aac_adtstoasc', '[...]']
2020-08-27 14:14:38,030 INFO     mp4 file created, size=2202.1MiB, filename=[...]
2020-08-27 14:14:38,030 INFO     Removing temp files in dir: "[...]"
2020-08-27 14:14:38,410 INFO     temp files removed

You'll need the path to the M3U file, of course; the easiest way to get that is probably to use your browser's DOM inspector and peek at the network traffic. If you have the video's page loaded but not started playing the video, the M3U file should be one of the first things being loaded after you click "Play", and you can copy its URL then.

Tags: useful stuff, videos
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded