My solution for .m3u8 video's downloading

awesome-hacking

disclaimer: There is NO copyright violation what so ever during the composing of this blog. The material I downloaded is a free and open course for everybody.

Six days ago my buddy Z.L. asked me if I can help him download some course video online, I said I will take a look. So there I went, to this website, called XDF Weike (looks like MOOC and stuff).

My target video requires Flash to play, I'm not gonna get any luck there, so I switched the user-agent to phone and opened up element inspection. From what I gathered, its using .m3u8 video format, and URL for the .m3u8 file is right there in the HTML codes. So no security, well, looks like kids' stuff to me.

So how does .m3u8 file work? Well, .m3u8 file alone is not a video format, but it acts like an inventory for all the fragments known as .ts files. All the .ts files joined in correct order will then become a full video file, that file is what I want eventually.

And after some package caption I learned that all the .ts files are stored in the same directory with .m3u8 file on server, which makes sense. It's the easiest way to download .ts files according to .m3u8 files if they are stored in the same directory.

So, my solution became clear: parse the .m3u8 file to download all .ts files associated with .m3u8 file and then join them in the right order. The result should be a big .ts file, change filetype from .ts to .mp4 and it's done!

I uploaded my source code to my GitHub, you can go check it out!

I added a progress bar for visual appeal:
demo