Created
December 3, 2013 08:11
-
-
Save ranlix/7765692 to your computer and use it in GitHub Desktop.
一个外网的hls文件(.m3u8), 现在需要把其中包含的所有的url的ts文件全部下下来,顺便重命名,并且创建本地的播放列表(m3u8),里面的绝对路径的url替换成刚刚下载的新的本地的ts文件名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import os | |
url_counter = 1 | |
file_will_opened = sys.argv[1] | |
m3u8_content = open(file_will_opened, "r") | |
new_file = open("hevc.m3u8", "wb") | |
# def get_link(): | |
for item in m3u8_content.readlines(): | |
if not item.startswith("http"): | |
new_file.write(item) | |
else: | |
new_ts = str(url_counter) + ".ts" + "\n" # define downloaded file | |
wget_command = "wget" + " '" + item.split()[0] + "' -O " + new_ts | |
url_counter += 1 | |
os.popen(wget_command) | |
new_file.write(new_ts) | |
m3u8_content.close() | |
new_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment