I dont like to watch on-line movies on bad internet connection because of lags. So I found a good on-line cinema, check hot video player works there and create a simple script to download full movie.
The size comparsion to regular DVD-quality on torrents is 1.5Gb to 500Mb. Sounds good!

The algorythm of service is to load an iframe. Player located in iframe, works with m3u file, where links to different video qualities playlistst located. The final playlist consist of video segments list.
On the first step I was downloading segments with wget, making a simple bash loop. But later I've figure out that ffmpeg can do it on it own! Simplier than ever.
Ok, so we should get the playlist from website with the help of bash.

First of all we should get the URL from IFRAME. This can be achieved with hxnormalize, hxselect and hxwls programs from package html-xml-utils

$ sudo apt install html-xml-utils

The div with iframe looks like this:

<div class="video-player-wrapper">
    <iframe id="video-player" width="720" height="400" src="https://somewhere.web/1234" frameborder="0" allowfullscreen></iframe>

create a function to get this url:

get_iframe_video_url() {
    echo $1 |
    wget -O- -i- --no-verbose | 
    hxnormalize -x | 
    hxselect -i "div.video-player-wrapper iframe" |

Then we should get the URI where playlist and movie segments located. It's the js scipt.

get_video_uri() {
    echo $1 |
    wget -O- -i- --no-verbose | 
    grep -E -o 'file:"(.*)m3u8' | 
    sed -n 's/file:"//p' |
    sed -n 's/index.m3u8//p'

and the last one is to concat all segments with ffmpeg:

ffmpeg -i $PLAYLIST -c copy -bsf:a aac_adtstoasc "$DIRECTORY.mp4" -y

Name of the final file is the last part of URL without extension.
For example: 
https://somewhere-onilne.web/movie/best-movie.html becomes best-movie.

get_directory_from_url() {
    echo $1 | sed 's#.*/##'
DIRECTORY=$(get_directory_from_url $URL);

And here is the first function which creates to lists with files to download and concatanate with wget and ffmpeg:

create_segments_file() {
    if test -f "$FILE_FFMPEG_LIST"; then
    if test -f "$FILE_FFMPEG_LIST"; then
       rm $FILE_WGET_LIST
    # download movie playlist
    wget $VIDEO_URI/$QUALITY/index.m3u8 --output-document=pls.file --no-verbose
    LIST=$(grep segment pls.file)
    rm pls.file
    for f in $LIST;
        echo "file '$DIRECTORY/$f'" >> $FILE_FFMPEG_LIST
        echo "$VIDEO_URI$QUALITY/$f" >> $FILE_WGET_LIST
    echo "Saving files done."

Here's gist: https://gist.github.com/onesixromcom/649a2b7ff95a78a5125b3994fbaec7aa

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.