m3u8動画のダウンロード

windows10でm3u8の動画をダウンロードしようとしているのですが、あらゆる方法を試しましたが、ダウンロードできませんでした。

誰か助けてくれませんか? ビデオのリンクは以下の通りです。

http://s6.vidshare.tv/hls/pdommq4tlsm4f4kmledsh5d5fcn27i35msjxqw62l,w63wt5bgaqhzzy5tnfq,7p3ut5bgaqjxkd423pq,fflut5bgaqkj42irb5q,.urlset/master.m3u8

http://s6.vidshare.tv/hls/pdommq4tlsm4f4kmledsh5d5fcn27i35msjxqw62lfflut5bgaqhb5kirb5q/index-v1-a1.m3u8

ところで、これらのリンクは同じビデオのものですが、私にはどれもうまくいきませんでした。

ソリューション

からffmpegを入手します。 http://ffmpeg.zeranoe.com/builds/

そして、次のコマンドでビデオをダウンロードできます。

ffmpeg -protocol_whitelist file,http,https,tcp,tls,crypto -i "http://s6.vidshare.tv/hls/pdommq4tlsm4f4kmledsh5d5fcn27i35msjxqw62lfflut5bgaqhb5kirb5q/index-v1-a1.m3u8" -c copy video.mp4

しかし、youtube-dlを使う方が簡単かもしれません。ビデオを含むウェブサイトをサポートしている場合は、例えば、youtube-dl https://www.youtube.com/...と入力できます。

これはyoutubeだけでなく、他の多くの動画サイトでも使えます。

解説 (1)

1つ目のセグメントのURLとセグメントの数(.m3u8ファイルから)を指定するだけです。

def dumpSegs(initUrl, n, path, append=False):
    """ downlaod and combine the .ts files
    given the first seg's url, the number of segments and
    the destination download path """
    with open(path, 'ab' if append else 'wb') as f:
        for i in range(1, n + 1):
            segurl = initUrl.replace('seg-1-', 'seg-{:d}-'.format(i))
            success = False
            while not success:
                try:
                    seg = requests.get(segurl, headers=HEADERS)
                    success = True
                except:
                    print('retrying...')
            f.write(seg.content)

Here'は同じコードにいくつかの機能を追加したものです。

解説 (0)