python嗅探m3u8_python通过m3u8下载视频

python可以通过安装ffmpeg扩展来实现下载m3u8的视频,很多视频网站都提供m3u8

ffmpeg命令行格式如下

D:\Python36\Lib\site-packages\imageio_ffmpeg\binaries\ffmpeg-win64-v4.1.exe -i  url -vcodec copy -acodec copy 视频.mp4

通过解析视频网站活动m3u8的url,再使用ffmeg可以实现视频下载

python代码如下:

# -*- coding:utf-8 -*-

import requests

from lxml import etree

# import ffmpeg

import imageio_ffmpeg

import subprocess

# url = 'https://jx.618g.com/?url=https://v.qq.com/x/cover/59l8gzmf4d9cjuu.html'

# response = requests.get(url)

# # print(response.text)

# # print(response.content)

# html_str = response.content

# html = etree.HTML(html_str)

# m3u8_url = html.xpath("//div[@class='player']/iframe/@src")[0].split('=')[-1]

# print(m3u8_url)

url = 'https://cn4.download05.com/hls/20190618/be22d970332fd4ba4d3c63b19ebd0667/1560840680/index.m3u8'

ffmpeg = imageio_ffmpeg.get_ffmpeg_exe()

cmd = ffmpeg + " -i " + url + " -vcodec copy -acodec copy 1.mp4"

print(cmd)

res = subprocess.call(cmd, shell=True)

你可能感兴趣的:(python嗅探m3u8)