Skip to content

Commit

Permalink
feat: clear out cache
Browse files Browse the repository at this point in the history
  • Loading branch information
r3tr0ananas committed Jun 12, 2024
1 parent dd5f503 commit 25fdae5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions mov_cli/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BasicCacheData(TypedDict):

import json
from datetime import datetime
import shutil
from devgoldyutils import LoggerAdapter, Colours

from .logger import mov_cli_logger
Expand All @@ -34,9 +35,9 @@ class Cache():
def __init__(self, platform: SUPPORTED_PLATFORMS, section: Optional[str] = None) -> None:
self.section = section

temp_dir = get_temp_directory(platform)
self.temp_dir = get_temp_directory(platform)

self._basic_cache_file_path = temp_dir.joinpath("osaka_cache") # ◔_◔ https://static.wikia.nocookie.net/parody/images/f/fd/Osaka.png/revision/latest
self._basic_cache_file_path = self.temp_dir.joinpath("osaka_cache") # ◔_◔ https://static.wikia.nocookie.net/parody/images/f/fd/Osaka.png/revision/latest

super().__init__()

Expand Down Expand Up @@ -153,6 +154,10 @@ def clear_all_cache(self) -> None:
def delete_cache_file(self) -> None:
logger.info(f"Deleting basic cache file ({self._basic_cache_file_path.name})...")
self._basic_cache_file_path.unlink(True)

def delete_entire_folder(self) -> None:
logger.info(f"Deleting mov-cli's temp folder...")
shutil.rmtree(self.temp_dir)

def __get_cache_file(self, mode: str) -> TextIOWrapper:

Expand Down
9 changes: 8 additions & 1 deletion mov_cli/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from ..media import MetadataType
from ..logger import mov_cli_logger
from ..http_client import HTTPClient
from ..utils import hide_ip
from ..utils import hide_ip, what_platform
from .. import Cache

__all__ = ("mov_cli",)

Expand All @@ -44,6 +45,7 @@ def mov_cli(
edit: bool = typer.Option(False, "--edit", "-e", help = "Opens the mov-cli config with your respective editor."),
download: bool = typer.Option(False, "--download", "-d", help = "Downloads the media instead of playing."),
list_plugins: bool = typer.Option(False, "--list-plugins", "-lp", help = "Prints all configured plugins and their scrapers."),
delete_cache: bool = typer.Option(False, "--clear-cache", help = "Clears the mov-cli's temp folder.")
):
config = Config()

Expand All @@ -59,6 +61,11 @@ def mov_cli(

if config.debug:
mov_cli_logger.setLevel(logging.DEBUG)

if delete_cache:
Cache(
what_platform()
).delete_entire_folder()

mov_cli_logger.debug(f"Config -> {config.data}")

Expand Down

0 comments on commit 25fdae5

Please sign in to comment.