From 41039ea049ee777e8971b976b5c3142a5f2ae6c5 Mon Sep 17 00:00:00 2001 From: Yuanle Song Date: Fri, 8 Mar 2019 21:21:35 +0800 Subject: [PATCH] v0.7.6 always rewrite fragment lines in m3u8 list previously absolute path may not be replaced with relative path if there is no http or query param. --- m3u8downloader/__init__.py | 2 +- m3u8downloader/main.py | 7 ++----- m3u8downloader/test_main.py | 5 +++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/m3u8downloader/__init__.py b/m3u8downloader/__init__.py index ab55bb1..aed5734 100644 --- a/m3u8downloader/__init__.py +++ b/m3u8downloader/__init__.py @@ -1 +1 @@ -__version__ = "0.7.5" +__version__ = "0.7.6" diff --git a/m3u8downloader/main.py b/m3u8downloader/main.py index d0e6eff..46b7b68 100644 --- a/m3u8downloader/main.py +++ b/m3u8downloader/main.py @@ -129,18 +129,15 @@ def drop_http_link_in_m3u8_file(local_m3u8_filename): """ with open(local_m3u8_filename, 'r') as f: content = f.read() - if 'http' not in content and '?' not in content: - logger.debug("media playlist m3u8 file doesn't contain http link") - return with open(local_m3u8_filename, 'w') as f: for line in content.split('\n'): if line.startswith('#'): f.write(line) f.write('\n') - if line.strip() == '': + elif line.strip() == '': f.write(line) f.write('\n') - if line.startswith('http') or '?' in line: + else: f.write(http_line_to_relpath_line(line)) f.write('\n') logger.info("http links modified in m3u8 file: %s", local_m3u8_filename) diff --git a/m3u8downloader/test_main.py b/m3u8downloader/test_main.py index 5b6e580..a8150fe 100644 --- a/m3u8downloader/test_main.py +++ b/m3u8downloader/test_main.py @@ -20,6 +20,11 @@ def test_http_line_to_relpath_line(): assert http_line_to_relpath_line("https://m3u.x8sinablog.net/20180627/1530068509/vts/audio000.png") == "20180627/1530068509/vts/audio000.png" assert http_line_to_relpath_line("https://m3u.x8sinablog.net/20180627/1530068509/vts/audio000.png?abc=def") == "20180627/1530068509/vts/audio000.png" assert http_line_to_relpath_line("hls-720p0.ts?e=1551942309&l=0&h=d7cf2b2173b6bfda5c9f738a8e39a7f6") == "hls-720p0.ts" + assert http_line_to_relpath_line("/20190307/8fe119a63422c3af10e18aef1a36bb55/hls/hls-360p0.jpg") == "20190307/8fe119a63422c3af10e18aef1a36bb55/hls/hls-360p0.jpg" + assert http_line_to_relpath_line("20190307/8fe119a63422c3af10e18aef1a36bb55/hls/hls-360p0.jpg") == "20190307/8fe119a63422c3af10e18aef1a36bb55/hls/hls-360p0.jpg" + assert http_line_to_relpath_line("/hls-360p0.jpg") == "hls-360p0.jpg" + assert http_line_to_relpath_line("hls-360p0.jpg") == "hls-360p0.jpg" + assert http_line_to_relpath_line("hls-360p0.jpg?foo") == "hls-360p0.jpg" # test for join -- GitLab