fix bug sort

This commit is contained in:
Ghost 2024-01-07 10:08:29 +01:00
parent 94e4f09518
commit beb015685f
3 changed files with 30 additions and 25 deletions

View File

@ -52,4 +52,4 @@ def main_dw_film(id_film, title_name, domain):
m3u8_key = get_m3u8_key(json_win_video, json_win_param, title_name) m3u8_key = get_m3u8_key(json_win_video, json_win_param, title_name)
path_film = os.path.join("videos", lower_title_name.replace("+", " ").replace(",", "") + ".mp4") path_film = os.path.join("videos", lower_title_name.replace("+", " ").replace(",", "") + ".mp4")
dw_m3u8(m3u8_url, m3u8_key, path_film) dw_m3u8(m3u8_url, None, m3u8_key, path_film)

View File

@ -1,5 +1,5 @@
__title__ = 'Streaming_community' __title__ = 'Streaming_community'
__version__ = 'v0.7.0' __version__ = 'v0.7.1'
__author__ = 'Ghost6446' __author__ = 'Ghost6446'
__description__ = 'A command-line program to download film' __description__ = 'A command-line program to download film'
__license__ = 'MIT License' __license__ = 'MIT License'

View File

@ -1,7 +1,7 @@
# 5.01.24 # 5.01.24
# Import # Import
import requests, re, os, ffmpeg, shutil import requests, re, os, ffmpeg, shutil, time
from tqdm.rich import tqdm from tqdm.rich import tqdm
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@ -29,7 +29,7 @@ class M3U8Downloader:
self.segments = [] self.segments = []
self.segments_audio = [] self.segments_audio = []
self.iv = None self.iv = None
self.key = bytes.fromhex(key) if key != None: self.key = bytes.fromhex(key)
self.temp_folder = "tmp" self.temp_folder = "tmp"
os.makedirs(self.temp_folder, exist_ok=True) os.makedirs(self.temp_folder, exist_ok=True)
@ -102,13 +102,8 @@ class M3U8Downloader:
video_ts_url = self.segments[index] video_ts_url = self.segments[index]
video_ts_filename = os.path.join(self.temp_folder, f"{index}_v.ts") video_ts_filename = os.path.join(self.temp_folder, f"{index}_v.ts")
if self.download_audio:
audio_ts_url = self.segments_audio[index]
audio_ts_filename = os.path.join(self.temp_folder, f"{index}_a.ts")
video_audio_ts_filename = os.path.join(self.temp_folder, f"{index}_v_a.ts")
# Download video or audio ts file # Download video or audio ts file
if not os.path.exists(video_ts_url): if not os.path.exists(video_ts_filename): # Only for media that not use audio
ts_response = requests.get(video_ts_url, headers={'user-agent': get_headers()}).content ts_response = requests.get(video_ts_url, headers={'user-agent': get_headers()}).content
if self.key and self.iv: if self.key and self.iv:
@ -122,6 +117,11 @@ class M3U8Downloader:
# Donwload only audio ts file # Donwload only audio ts file
if self.download_audio: if self.download_audio:
audio_ts_url = self.segments_audio[index]
audio_ts_filename = os.path.join(self.temp_folder, f"{index}_a.ts")
video_audio_ts_filename = os.path.join(self.temp_folder, f"{index}_v_a.ts")
if not os.path.exists(video_audio_ts_filename): # Only for media use audio
ts_response = requests.get(audio_ts_url, headers={'user-agent': get_headers()}).content ts_response = requests.get(audio_ts_url, headers={'user-agent': get_headers()}).content
if self.key and self.iv: if self.key and self.iv:
@ -147,8 +147,12 @@ class M3U8Downloader:
current_dir = os.path.dirname(os.path.realpath(__file__)) current_dir = os.path.dirname(os.path.realpath(__file__))
file_list_path = os.path.join(current_dir, 'file_list.txt') file_list_path = os.path.join(current_dir, 'file_list.txt')
# Make sort by number
ts_files = [f for f in os.listdir(self.temp_folder) if f.endswith(".ts")] ts_files = [f for f in os.listdir(self.temp_folder) if f.endswith(".ts")]
ts_files.sort() def extract_number(file_name):
return int(''.join(filter(str.isdigit, file_name)))
ts_files.sort(key=extract_number)
with open(file_list_path, 'w') as f: with open(file_list_path, 'w') as f:
for ts_file in ts_files: for ts_file in ts_files:
@ -164,6 +168,7 @@ class M3U8Downloader:
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(f"Errore durante il salvataggio del file MP4: {e}") print(f"Errore durante il salvataggio del file MP4: {e}")
finally: finally:
time.sleep(2)
os.remove(file_list_path) os.remove(file_list_path)
shutil.rmtree("tmp", ignore_errors=True) shutil.rmtree("tmp", ignore_errors=True)