backup
This commit is contained in:
parent
91da4a5763
commit
ce341fe360
32
Dockerfile
32
Dockerfile
@ -1,21 +1,21 @@
|
|||||||
FROM ubuntu:latest
|
# Use an official Python runtime as a parent image
|
||||||
|
FROM python:3.10
|
||||||
|
|
||||||
# Install dependencies
|
# Set the working directory inside the container
|
||||||
RUN apt update && apt install -y \
|
WORKDIR /app
|
||||||
openvpn \
|
|
||||||
python3-pip \
|
|
||||||
protonvpn-cli \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Install dependencies if you have a requirements file
|
# Ensure the directory exists
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN mkdir -p /app
|
||||||
|
|
||||||
# Copy the Python script and monitoring script
|
# Copy the requirements file before copying the app files (for better caching)
|
||||||
COPY main.py /main.py
|
COPY requirements.txt .
|
||||||
COPY vpn_monitor.sh /vpn_monitor.sh
|
COPY main.py .
|
||||||
|
COPY Loader.py .
|
||||||
|
|
||||||
# Ensure scripts are executable
|
# Create and activate a virtual environment
|
||||||
RUN chmod +x /main.py /vpn_monitor.sh
|
RUN python -m venv venv && \
|
||||||
|
. venv/bin/activate && \
|
||||||
|
pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Entry point: Start VPN and monitor status
|
# Run the application using the virtual environment
|
||||||
CMD ["bash", "/vpn_monitor.sh"]
|
CMD ["/bin/bash", "-c", "source venv/bin/activate && python main.py"]
|
||||||
@ -1,13 +1,25 @@
|
|||||||
version: "3.7"
|
version: "3.7"
|
||||||
services:
|
services:
|
||||||
aniworld:
|
wireguard:
|
||||||
build: .
|
container_name: wireguard
|
||||||
#user: "1009:1008" # should be owner of volumes
|
image: jordanpotter/wireguard
|
||||||
container_name: aniworld
|
user: "1013:1001"
|
||||||
restart: always
|
cap_add:
|
||||||
networks:
|
- NET_ADMIN
|
||||||
- bridge_network
|
- SYS_MODULE
|
||||||
|
sysctls:
|
||||||
|
net.ipv4.conf.all.src_valid_mark: 1
|
||||||
|
volumes:
|
||||||
|
- /server_aniworld/wg0.conf:/etc/wireguard/wg0.conf
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
curl:
|
||||||
|
image: curlimages/curl
|
||||||
|
command: ifconfig.io
|
||||||
|
user: "1013:1001"
|
||||||
|
network_mode: service:wireguard
|
||||||
|
depends_on:
|
||||||
|
- wireguard
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
networks:
|
|
||||||
bridge_network:
|
|
||||||
driver: bridge
|
|
||||||
38
main.py
38
main.py
@ -26,12 +26,47 @@ class Loader:
|
|||||||
logging.info("Scanning for .mp4 files")
|
logging.info("Scanning for .mp4 files")
|
||||||
for root, dirs, files in os.walk(self.directory):
|
for root, dirs, files in os.walk(self.directory):
|
||||||
mp4_files = [file for file in files if file.endswith('.mp4')]
|
mp4_files = [file for file in files if file.endswith('.mp4')]
|
||||||
|
|
||||||
if mp4_files:
|
if mp4_files:
|
||||||
relative_path = os.path.relpath(root, self.directory)
|
relative_path = os.path.relpath(root, self.directory)
|
||||||
root_folder_name = relative_path.split(os.sep)[0]
|
root_folder_name = relative_path.split(os.sep)[0]
|
||||||
logging.debug(f"Found {len(mp4_files)} .mp4 files in {root_folder_name}")
|
logging.debug(f"Found {len(mp4_files)} .mp4 files in {root_folder_name}")
|
||||||
yield root_folder_name, mp4_files
|
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):
|
def __remove_year(self, input_string: str):
|
||||||
cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip()
|
cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip()
|
||||||
logging.debug(f"Removed year from '{input_string}' -> '{cleaned_string}'")
|
logging.debug(f"Removed year from '{input_string}' -> '{cleaned_string}'")
|
||||||
@ -92,7 +127,8 @@ class Loader:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Read the base directory from an environment variable
|
# 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 = Loader(directory_to_search)
|
||||||
loader.LoadMissing()
|
loader.LoadMissing()
|
||||||
@ -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
|
|
||||||
Loading…
x
Reference in New Issue
Block a user