63 lines
2.7 KiB
Python
63 lines
2.7 KiB
Python
import os
|
||
from pathlib import Path
|
||
import shutil
|
||
from data.path_constant import DOWNLOAD_DIR, NETWORK_DIR
|
||
|
||
# input: DOWNLOAD_DIR or NETWORK_DIR
|
||
def delete_all_empty_episodes(path: Path):
|
||
for first_level_path in path.iterdir():
|
||
if first_level_path.is_dir():
|
||
for second_level_path in first_level_path.iterdir():
|
||
if second_level_path.is_dir() and not any(second_level_path.iterdir()):
|
||
print(f"Deleting directory: {second_level_path}")
|
||
shutil.rmtree(second_level_path)
|
||
print(f"Empty directory '{second_level_path}' deleted successfully.")
|
||
|
||
|
||
def delete_all_webtoons_without_episodes():
|
||
for first_level_path in NETWORK_DIR.iterdir():
|
||
if first_level_path.is_dir():
|
||
contains_dir = any(item.is_dir() for item in first_level_path.iterdir())
|
||
if not contains_dir:
|
||
# No subdirectories, safe to delete
|
||
print(f"Deleting directory: {first_level_path}")
|
||
shutil.rmtree(first_level_path)
|
||
print(f"Directory '{first_level_path}' deleted successfully.")
|
||
|
||
def get_download_list(path: Path):
|
||
url_list = []
|
||
try:
|
||
with open(path, 'r') as file:
|
||
for url in file:
|
||
if 'https://' in url:
|
||
url_list.append(url.strip())
|
||
except FileNotFoundError:
|
||
print(f"The file at {path} was not found.")
|
||
except Exception as e:
|
||
print(f"An error occurred: {e}")
|
||
return url_list
|
||
|
||
def rename_episodes(path: Path):
|
||
for first_level_path in path.iterdir():
|
||
if first_level_path.is_dir():
|
||
for second_level_path in first_level_path.iterdir():
|
||
if second_level_path.is_dir() and '. ' in second_level_path.name:
|
||
print(second_level_path)
|
||
newName = second_level_path.name.replace(". ", ".")
|
||
new_path = first_level_path / newName
|
||
os.rename(second_level_path, new_path)
|
||
if second_level_path.is_dir() and '(' in second_level_path.name:
|
||
print(second_level_path)
|
||
newName = second_level_path.name.replace("(", " (")
|
||
newName = newName.replace(")", ")")
|
||
new_path = first_level_path / newName
|
||
os.rename(second_level_path, new_path)
|
||
|
||
|
||
def get_episodes_with_wrong_name(path: Path):
|
||
for first_level_path in path.iterdir():
|
||
if first_level_path.is_dir():
|
||
for second_level_path in first_level_path.iterdir():
|
||
if second_level_path.is_dir() and len(second_level_path.name.split('.')) > 2:
|
||
print(second_level_path)
|