Fix for title.name == None

This commit is contained in:
Lovi 2024-11-14 11:50:23 +01:00
parent bdbcfb2fd1
commit 0996f8d415
3 changed files with 14 additions and 9 deletions

View File

@ -264,7 +264,8 @@ class ContentExtractor:
# Check if a valid HTTPS URL is obtained
if self.m3u8_index is not None and "https" in self.m3u8_index:
console.print(f"[cyan]Found m3u8 index [white]=> [red]{self.m3u8_index}")
#console.print(f"[cyan]Found m3u8 index [white]=> [red]{self.m3u8_index}")
print()
else:
logging.error("[download_m3u8] Can't find a valid m3u8 index")
@ -695,14 +696,16 @@ class HLS_Downloader:
Returns:
str: The generated output filename.
"""
root_path = config_manager.get('DEFAULT', 'root_path')
new_filename = None
new_folder = os.path.join(root_path, "undefined")
# Auto-generate output file name if not present
if output_filename is None:
if (output_filename is None) or ("mp4" not in output_filename):
if m3u8_playlist is not None:
new_filename = os.path.join("missing", compute_sha1_hash(m3u8_playlist))
new_filename = os.path.join(new_folder, compute_sha1_hash(m3u8_playlist) + ".mp4")
else:
new_filename = os.path.join("missing", compute_sha1_hash(m3u8_index))
new_filename = os.path.join(new_folder, compute_sha1_hash(m3u8_index) + ".mp4")
else:
@ -711,7 +714,7 @@ class HLS_Downloader:
# If no folder is specified, default to 'undefined'
if not folder:
folder = "undefined"
folder = new_folder
# Sanitize base name
base_name = reduce_base_name(remove_special_characters(base_name))
@ -724,14 +727,13 @@ class HLS_Downloader:
# Parse to only ASCII for compatibility across platforms
new_filename = os.path.join(folder, base_name)
new_filename = unidecode(new_filename)
return new_filename
def start(self):
"""
Initiates the downloading process. Checks if the output file already exists and proceeds with processing the playlist or index.
"""
if os.path.exists(self.output_filename):
console.log("[red]Output file already exists.")
return

View File

@ -92,6 +92,9 @@ def remove_special_characters(input_string):
Returns:
str: A new string with specified special characters removed.
"""
if input_string is None:
return "None"
# Compile regular expression pattern to match special characters
pattern = re.compile('[' + re.escape(special_chars_to_remove) + ']')

View File

@ -14,6 +14,6 @@ from Src.Lib.Downloader import HLS_Downloader
# Test
HLS_Downloader(
output_filename=r".\Video\undefined.mp4",
m3u8_index=""
output_filename="",
m3u8_playlist=""
).start()