From ce341fe3608b2a2e9ffe680e721d003eb9d020bb Mon Sep 17 00:00:00 2001 From: Lukas Pupka-Lipinski Date: Sat, 17 May 2025 20:46:55 +0200 Subject: [PATCH] backup --- Dockerfile | 32 ++++++++++++++++---------------- docker-compose.yml | 32 ++++++++++++++++++++++---------- main.py | 40 ++++++++++++++++++++++++++++++++++++++-- vpn_monitor.sh | 42 ------------------------------------------ 4 files changed, 76 insertions(+), 70 deletions(-) delete mode 100644 vpn_monitor.sh diff --git a/Dockerfile b/Dockerfile index 5a934ab..bb4820c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -FROM ubuntu:latest +# Use an official Python runtime as a parent image +FROM python:3.10 -# Install dependencies -RUN apt update && apt install -y \ - openvpn \ - python3-pip \ - protonvpn-cli \ - && rm -rf /var/lib/apt/lists/* +# Set the working directory inside the container +WORKDIR /app -# Install dependencies if you have a requirements file -RUN pip install --no-cache-dir -r requirements.txt +# Ensure the directory exists +RUN mkdir -p /app -# Copy the Python script and monitoring script -COPY main.py /main.py -COPY vpn_monitor.sh /vpn_monitor.sh +# Copy the requirements file before copying the app files (for better caching) +COPY requirements.txt . +COPY main.py . +COPY Loader.py . -# Ensure scripts are executable -RUN chmod +x /main.py /vpn_monitor.sh +# Create and activate a virtual environment +RUN python -m venv venv && \ + . venv/bin/activate && \ + pip install --no-cache-dir -r requirements.txt -# Entry point: Start VPN and monitor status -CMD ["bash", "/vpn_monitor.sh"] \ No newline at end of file +# Run the application using the virtual environment +CMD ["/bin/bash", "-c", "source venv/bin/activate && python main.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 02a0887..418a149 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,25 @@ version: "3.7" services: - aniworld: - build: . - #user: "1009:1008" # should be owner of volumes - container_name: aniworld - restart: always - networks: - - bridge_network + wireguard: + container_name: wireguard + image: jordanpotter/wireguard + user: "1013:1001" + cap_add: + - NET_ADMIN + - SYS_MODULE + sysctls: + net.ipv4.conf.all.src_valid_mark: 1 + volumes: + - /server_aniworld/wg0.conf:/etc/wireguard/wg0.conf + restart: unless-stopped -networks: - bridge_network: - driver: bridge \ No newline at end of file + curl: + image: curlimages/curl + command: ifconfig.io + user: "1013:1001" + network_mode: service:wireguard + depends_on: + - wireguard + + + \ No newline at end of file diff --git a/main.py b/main.py index 088db3f..0b68455 100644 --- a/main.py +++ b/main.py @@ -26,12 +26,47 @@ class Loader: logging.info("Scanning for .mp4 files") for root, dirs, files in os.walk(self.directory): mp4_files = [file for file in files if file.endswith('.mp4')] + if mp4_files: relative_path = os.path.relpath(root, self.directory) root_folder_name = relative_path.split(os.sep)[0] logging.debug(f"Found {len(mp4_files)} .mp4 files in {root_folder_name}") yield root_folder_name, mp4_files + for dir in self.__find_empty_folders(): + relative_path = os.path.relpath(dir, self.directory) + logging.debug(f"Found no .mp4 files in {relative_path}") + yield relative_path, [] + for dir in self.__find_folders_without_mp4(): + relative_path = os.path.relpath(dir, self.directory) + logging.debug(f"Found no .mp4 files in {relative_path}") + yield relative_path, [] + def __find_empty_folders(self): + """Finds and returns a list of empty folders in the given directory.""" + empty_folders = [] + + for root, dirs, files in os.walk(self.directory): + if not files and not dirs: # If the folder contains no files or subdirectories + empty_folders.append(root) + + return empty_folders + def __find_folders_without_mp4(self): + """ + Finds folders that are either empty or contain no .mp4 files. + + :param root_dir: The directory to search within. + :return: List of folders that are empty or have no .mp4 files. + """ + result_folders = [] + + for foldername, subfolders, filenames in os.walk(self.directory): + # Check if the folder is empty or has no MP4 files + folder_name = os.path.relpath(foldername, self.directory) + if not any(file.lower().endswith('.mp4') for file in filenames): + if (folder_name != "."): + result_folders.append(foldername) + + return result_folders def __remove_year(self, input_string: str): cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip() logging.debug(f"Removed year from '{input_string}' -> '{cleaned_string}'") @@ -92,7 +127,8 @@ class Loader: continue # Read the base directory from an environment variable -directory_to_search = os.getenv("ANIME_DIRECTORY", "\\\\sshfs.r\\ubuntu@192.168.178.43\\media\\serien\\Serien") +#directory_to_search = os.getenv("ANIME_DIRECTORY", "\\\\sshfs.r\\ubuntu@192.168.178.43\\media\\serien\\Serien") +directory_to_search = os.getenv("ANIME_DIRECTORY", "D:\sss") loader = Loader(directory_to_search) -loader.LoadMissing() +loader.LoadMissing() \ No newline at end of file diff --git a/vpn_monitor.sh b/vpn_monitor.sh deleted file mode 100644 index be8479f..0000000 --- a/vpn_monitor.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# Try connecting to ProtonVPN with retries -MAX_RETRIES=5 -RETRY_DELAY=10 # seconds -TRIES=0 - -while [[ $TRIES -lt $MAX_RETRIES ]]; do - echo "Attempting to connect to ProtonVPN (try #$((TRIES+1)))..." - - protonvpn-cli c -r - - # Check if the connection was successful - if protonvpn-cli status | grep -q "Connected"; then - echo "VPN connected successfully!" - break - fi - - echo "VPN connection failed, retrying in $RETRY_DELAY seconds..." - sleep $RETRY_DELAY - ((TRIES++)) -done - -# If the connection still failed after retries, exit -if ! protonvpn-cli status | grep -q "Connected"; then - echo "Failed to establish VPN connection after $MAX_RETRIES attempts. Exiting..." - exit 1 -fi - -# Start the main Python script in the background -#python3 /main.py & -MAIN_PID=$! - -# Monitor VPN connection -while true; do - if ! protonvpn-cli status | grep -q "Connected"; then - echo "VPN disconnected! Stopping main.py..." - kill $MAIN_PID - exit 1 - fi - sleep 5 # Check every 5 seconds -done