From dc2a83e1f4f1875fb28e7eb9666102fd9a88c143 Mon Sep 17 00:00:00 2001 From: datawhores Date: Sat, 18 Jan 2025 14:34:29 -0600 Subject: [PATCH] refactor: remove transfor v4 options --- cyberdrop_dl/ui/program_ui.py | 31 ----- cyberdrop_dl/ui/prompts/user_prompts.py | 26 ---- .../utils/transfer/transfer_v4_config.py | 129 ------------------ cyberdrop_dl/utils/transfer/transfer_v4_db.py | 34 ----- 4 files changed, 220 deletions(-) delete mode 100644 cyberdrop_dl/utils/transfer/transfer_v4_config.py delete mode 100644 cyberdrop_dl/utils/transfer/transfer_v4_db.py diff --git a/cyberdrop_dl/ui/program_ui.py b/cyberdrop_dl/ui/program_ui.py index eed3d7174..ce7f6c27f 100644 --- a/cyberdrop_dl/ui/program_ui.py +++ b/cyberdrop_dl/ui/program_ui.py @@ -17,8 +17,6 @@ from cyberdrop_dl.ui.prompts.basic_prompts import ask_dir_path, enter_to_continue from cyberdrop_dl.ui.prompts.defaults import DONE_CHOICE, EXIT_CHOICE from cyberdrop_dl.utils.cookie_management import clear_cookies -from cyberdrop_dl.utils.transfer.transfer_v4_config import transfer_v4_config -from cyberdrop_dl.utils.transfer.transfer_v4_db import transfer_v4_db from cyberdrop_dl.utils.utilities import check_latest_pypi, clear_term, open_in_text_editor if TYPE_CHECKING: @@ -102,35 +100,6 @@ def _check_updates(self) -> None: check_latest_pypi(call_from_ui=True) enter_to_continue() - @repeat_until_done - def _import_from_v4(self) -> None: - options_map = { - 1: self._import_v4_config, - 2: self._import_v4_download_history, - } - answer = user_prompts.import_cyberdrop_v4_items_prompt(self.manager) - return self._process_answer(answer, options_map) - - def _import_v4_config(self) -> None: - new_config = user_prompts.import_v4_config_prompt(self.manager) - if not new_config: - return - transfer_v4_config(self.manager, *new_config) - - def _import_v4_download_history(self) -> None: - import_download_history_path = user_prompts.import_v4_download_history_prompt() - if import_download_history_path.is_file(): - transfer_v4_db(import_download_history_path, self.manager.path_manager.history_db) - return - - for item in import_download_history_path.glob("**/*.sqlite"): - if str(item) == str(self.manager.path_manager.history_db): - continue - try: - transfer_v4_db(item, self.manager.path_manager.history_db) - except Exception as e: - self.print_error(f"Unable to import {item.name}: {e!s}") - def _change_config(self) -> None: configs = self.manager.config_manager.get_configs() selected_config = user_prompts.select_config(configs) diff --git a/cyberdrop_dl/ui/prompts/user_prompts.py b/cyberdrop_dl/ui/prompts/user_prompts.py index 2a15de77e..55156a0b8 100644 --- a/cyberdrop_dl/ui/prompts/user_prompts.py +++ b/cyberdrop_dl/ui/prompts/user_prompts.py @@ -21,8 +21,6 @@ from cyberdrop_dl.utils.utilities import clear_term if TYPE_CHECKING: - from pathlib import Path - from yarl import URL from cyberdrop_dl.managers.manager import Manager @@ -224,30 +222,6 @@ def filter_cache_urls(manager: Manager, domains: list) -> set[URL]: return urls_to_remove -""" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ V4 IMPORT PROMPTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""" - - -def import_cyberdrop_v4_items_prompt(manager: Manager) -> int: - """Import Cyberdrop_V4 Items.""" - prompt_header(manager) - OPTIONS = [["Import config", "Import download_history.sql"]] - choices = basic_prompts.create_choices(OPTIONS) - console.print("V4 Import Menu") - return basic_prompts.ask_choice(choices) - - -def import_v4_config_prompt(manager: Manager) -> tuple[str, Path] | None: - """Asks the user for the name and path of the config to import. Returns `None` if the config name is invalid.""" - new_config = create_new_config(manager, title="What should this config be called:") - if not new_config: - return None - return new_config, basic_prompts.ask_file_path("Select the config file to import:") - - -def import_v4_download_history_prompt() -> Path: - return basic_prompts.ask_file_path("Select the download_history.sql file to import:") - - """ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OTHERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""" diff --git a/cyberdrop_dl/utils/transfer/transfer_v4_config.py b/cyberdrop_dl/utils/transfer/transfer_v4_config.py deleted file mode 100644 index 86bbd7340..000000000 --- a/cyberdrop_dl/utils/transfer/transfer_v4_config.py +++ /dev/null @@ -1,129 +0,0 @@ -from __future__ import annotations - -from pathlib import Path -from typing import TYPE_CHECKING - -from cyberdrop_dl.config_definitions import AuthSettings, ConfigSettings, GlobalSettings -from cyberdrop_dl.utils import yaml - -if TYPE_CHECKING: - from cyberdrop_dl.managers.manager import Manager - - -def transfer_v4_config(manager: Manager, new_config_name: str, old_config_path: Path) -> None: - """Transfers a V4 config into V5 possession.""" - new_auth_data = AuthSettings() - new_user_data = ConfigSettings() - new_global_data = GlobalSettings() - old_data = yaml.load(old_config_path) - old_data = old_data["Configuration"] - - from cyberdrop_dl.managers.path_manager import constants - - new_user_data.files.input_file = constants.APP_STORAGE / "Configs" / new_config_name / "URLs.txt" - new_user_data.files.download_folder = constants.DOWNLOAD_STORAGE / "Cyberdrop-DL Downloads" - new_user_data.logs.log_folder = constants.APP_STORAGE / "Configs" / new_config_name / "Logs" - new_user_data.sorting.sort_folder = constants.DOWNLOAD_STORAGE / "Cyberdrop-DL Sorted Downloads" - - # Auth data transfer - new_auth_data.forums.nudostar_username = old_data["Authentication"]["nudostar_username"] - new_auth_data.forums.nudostar_password = old_data["Authentication"]["nudostar_password"] - new_auth_data.forums.simpcity_username = old_data["Authentication"]["simpcity_username"] - new_auth_data.forums.simpcity_password = old_data["Authentication"]["simpcity_password"] - new_auth_data.forums.socialmediagirls_username = old_data["Authentication"]["socialmediagirls_username"] - new_auth_data.forums.socialmediagirls_password = old_data["Authentication"]["socialmediagirls_password"] - new_auth_data.forums.xbunker_username = old_data["Authentication"]["xbunker_username"] - new_auth_data.forums.xbunker_password = old_data["Authentication"]["xbunker_password"] - - new_auth_data.jdownloader.username = old_data["JDownloader"]["jdownloader_username"] - new_auth_data.jdownloader.password = old_data["JDownloader"]["jdownloader_password"] - new_auth_data.jdownloader.device = old_data["JDownloader"]["jdownloader_device"] - - new_auth_data.reddit.personal_use_script = old_data["Authentication"]["reddit_personal_use_script"] - new_auth_data.reddit.secret = old_data["Authentication"]["reddit_secret"] - - new_auth_data.gofile.api_key = old_data["Authentication"]["gofile_api_key"] - new_auth_data.imgur.client_id = old_data["Authentication"]["imgur_client_id"] - new_auth_data.pixeldrain.api_key = old_data["Authentication"]["pixeldrain_api_key"] - - # User data transfer - new_user_data.download_options.block_download_sub_folders = old_data["Runtime"]["block_sub_folders"] - new_user_data.download_options.disable_download_attempt_limit = old_data["Runtime"]["disable_attempt_limit"] - new_user_data.download_options.include_album_id_in_folder_name = old_data["Runtime"]["include_id"] - new_user_data.download_options.remove_generated_id_from_filenames = old_data["Runtime"]["remove_bunkr_identifier"] - new_user_data.download_options.separate_posts = old_data["Forum_Options"]["separate_posts"] - new_user_data.download_options.skip_download_mark_completed = False - - new_user_data.file_size_limits.maximum_image_size = old_data["Runtime"]["filesize_maximum_images"] - new_user_data.file_size_limits.maximum_other_size = old_data["Runtime"]["filesize_maximum_other"] - new_user_data.file_size_limits.maximum_video_size = old_data["Runtime"]["filesize_maximum_videos"] - new_user_data.file_size_limits.minimum_image_size = old_data["Runtime"]["filesize_minimum_images"] - new_user_data.file_size_limits.minimum_other_size = old_data["Runtime"]["filesize_minimum_other"] - new_user_data.file_size_limits.minimum_video_size = old_data["Runtime"]["filesize_minimum_videos"] - - new_user_data.ignore_options.exclude_videos = old_data["Ignore"]["exclude_videos"] - new_user_data.ignore_options.exclude_images = old_data["Ignore"]["exclude_images"] - new_user_data.ignore_options.exclude_other = old_data["Ignore"]["exclude_other"] - new_user_data.ignore_options.exclude_audio = old_data["Ignore"]["exclude_audio"] - new_user_data.ignore_options.ignore_coomer_ads = old_data["Ignore"]["skip_coomer_ads"] - new_user_data.ignore_options.skip_hosts = old_data["Ignore"]["skip_hosts"] - new_user_data.ignore_options.only_hosts = old_data["Ignore"]["only_hosts"] - - new_user_data.runtime_options.ignore_history = old_data["Ignore"]["ignore_history"] - new_user_data.runtime_options.skip_check_for_partial_files = old_data["Runtime"][ - "skip_check_for_partial_files_and_empty_dirs" - ] - new_user_data.runtime_options.skip_check_for_empty_folders = old_data["Runtime"][ - "skip_check_for_partial_files_and_empty_dirs" - ] - new_user_data.runtime_options.send_unsupported_to_jdownloader = old_data["JDownloader"]["apply_jdownloader"] - - new_user_data.sorting.sort_downloads = old_data["Sorting"]["sort_downloads"] - - # Global data transfer - new_global_data.general.allow_insecure_connections = old_data["Runtime"]["allow_insecure_connections"] - new_global_data.general.user_agent = old_data["Runtime"]["user_agent"] - new_global_data.general.proxy = old_data["Runtime"]["proxy"] or None - new_global_data.general.max_file_name_length = old_data["Runtime"]["max_filename_length"] - new_global_data.general.max_folder_name_length = old_data["Runtime"]["max_folder_name_length"] - new_global_data.general.required_free_space = old_data["Runtime"]["required_free_space"] - - new_global_data.rate_limiting_options.connection_timeout = old_data["Ratelimiting"]["connection_timeout"] - new_global_data.rate_limiting_options.download_attempts = old_data["Runtime"]["attempts"] - new_global_data.rate_limiting_options.download_delay = old_data["Ratelimiting"]["throttle"] - new_global_data.rate_limiting_options.read_timeout = old_data["Ratelimiting"]["read_timeout"] - new_global_data.rate_limiting_options.rate_limit = old_data["Ratelimiting"]["ratelimit"] - new_global_data.rate_limiting_options.max_simultaneous_downloads_per_domain = old_data["Runtime"][ - "max_concurrent_downloads_per_domain" - ] - - # Save Data - new_settings = manager.path_manager.config_folder / new_config_name / "settings.yaml" - new_logs = manager.path_manager.config_folder / new_config_name / "Logs" - new_settings.parent.mkdir(parents=True, exist_ok=True) - new_logs.mkdir(parents=True, exist_ok=True) - - old_config_folder = Path(old_config_path).parent - old_input_file: str = old_data["Files"]["input_file"] - old_urls_path = Path(old_input_file.replace("{config}", old_config_folder.name)) - - new_urls = manager.path_manager.config_folder / new_config_name / "URLs.txt" - new_urls.touch(exist_ok=True) - - if not old_urls_path.is_absolute() and len(old_urls_path.parts) == 1: - old_urls_path = old_config_folder / old_urls_path.name - - if old_urls_path.is_file(): - with old_urls_path.open(encoding="utf8") as urls_file: - urls = urls_file.readlines() - with new_urls.open("w", encoding="utf8") as urls_file: - urls_file.writelines(urls) - else: - new_urls.touch(exist_ok=True) - - manager.config_manager.authentication_data = AuthSettings.model_validate(new_auth_data.model_dump()) - manager.config_manager.global_settings_data = GlobalSettings.model_validate(new_global_data.model_dump()) - manager.config_manager.save_as_new_config(new_settings, ConfigSettings.model_validate(new_user_data.model_dump())) - manager.config_manager.write_updated_authentication_config() - manager.config_manager.write_updated_global_settings_config() - manager.config_manager.change_config(new_config_name) diff --git a/cyberdrop_dl/utils/transfer/transfer_v4_db.py b/cyberdrop_dl/utils/transfer/transfer_v4_db.py deleted file mode 100644 index 3d40f8c10..000000000 --- a/cyberdrop_dl/utils/transfer/transfer_v4_db.py +++ /dev/null @@ -1,34 +0,0 @@ -import sqlite3 -from pathlib import Path - -from cyberdrop_dl.utils.database.table_definitions import create_history - - -def transfer_v4_db(db_path: Path, new_db_path: Path) -> None: - """Transfers a V4 database into V5 possession.""" - old_db_connection = sqlite3.connect(db_path) - if not new_db_path.exists(): - new_db_path.parent.mkdir(parents=True, exist_ok=True) - new_db_path.touch() - new_db_connection = sqlite3.connect(new_db_path) - - new_db_connection.execute(create_history) - - query = "SELECT domain, url_path, referer, download_path, download_filename, original_filename, completed FROM media WHERE completed = 1" - old_data_history = old_db_connection.execute(query).fetchall() - - old_data_revised = [] - for row in old_data_history: - row_list = list(row) - row_list[3] = str(Path(row_list[3]).parent) - old_data_revised.append(tuple(row_list)) - - new_db_connection.executemany( - "insert or ignore into media (domain, url_path, referer, download_path, download_filename, original_filename, completed) values (?, ?, ?, ?, ?, ?, ?)", - old_data_revised, - ) - del old_data_history - - new_db_connection.commit() - old_db_connection.close() - new_db_connection.close()