Compare commits
2 Commits
91da4a5763
...
4dae1d037f
| Author | SHA1 | Date | |
|---|---|---|---|
| 4dae1d037f | |||
| 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
|
||||
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"]
|
||||
# Run the application using the virtual environment
|
||||
CMD ["/bin/bash", "-c", "source venv/bin/activate && python main.py"]
|
||||
BIN
__pycache__/Loader.cpython-310.pyc
Normal file
BIN
__pycache__/Loader.cpython-310.pyc
Normal file
Binary file not shown.
@ -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
|
||||
curl:
|
||||
image: curlimages/curl
|
||||
command: ifconfig.io
|
||||
user: "1013:1001"
|
||||
network_mode: service:wireguard
|
||||
depends_on:
|
||||
- wireguard
|
||||
|
||||
|
||||
|
||||
47
main.py
47
main.py
@ -26,11 +26,26 @@ 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():
|
||||
logging.debug(f"Found no .mp4 files in {dir}")
|
||||
yield dir, []
|
||||
|
||||
def __find_empty_folders(self):
|
||||
"""Yield folder names that do not contain any mp4 files in a given directory."""
|
||||
for folder in os.listdir(self.directory):
|
||||
folder_path = os.path.join(self.directory, folder)
|
||||
|
||||
if os.path.isdir(folder_path): # Ensure it's a directory
|
||||
has_mp4 = any(file.endswith(".mp4") for file in os.listdir(folder_path))
|
||||
|
||||
if not has_mp4:
|
||||
yield folder # Yield the folder name if no mp4 files found
|
||||
|
||||
def __remove_year(self, input_string: str):
|
||||
cleaned_string = re.sub(r'\(\d{4}\)', '', input_string).strip()
|
||||
@ -60,11 +75,36 @@ class Loader:
|
||||
season = match.group(1)
|
||||
episode = match.group(2)
|
||||
logging.debug(f"Extracted season {season}, episode {episode} from '{filename}'")
|
||||
return season, episode
|
||||
return int(season), int(episode)
|
||||
else:
|
||||
logging.error(f"Failed to find season/episode pattern in '{filename}'")
|
||||
raise MatchNotFoundError("Season and episode pattern not found in the filename.")
|
||||
|
||||
def __GetEpisodesAndSeasons(self, mp4_files: []):
|
||||
episodes_dict = {}
|
||||
|
||||
for file in mp4_files:
|
||||
season, episode = self.__GetEpisodeAndSeason(file)
|
||||
|
||||
if season in episodes_dict:
|
||||
episodes_dict[season].append(episode)
|
||||
else:
|
||||
episodes_dict[season] = [episode]
|
||||
|
||||
return episodes_dict
|
||||
|
||||
def __GetMissingEpisodesAndSeason(self, key: str, mp4_files: []):
|
||||
expected_dict = get_season_episode_count(key) # key season , value count of episodes
|
||||
filedict = self.__GetEpisodesAndSeasons(mp4_files)
|
||||
|
||||
for season, expected_count in expected_dict.items():
|
||||
existing_episodes = filedict.get(season, [])
|
||||
missing_episodes = [ep for ep in range(1, expected_count + 1) if ep not in existing_episodes]
|
||||
|
||||
if missing_episodes:
|
||||
yield season, missing_episodes
|
||||
|
||||
|
||||
def LoadMissing(self):
|
||||
logging.info("Starting process to load missing episodes")
|
||||
result = self.__find_mp4_files()
|
||||
@ -92,7 +132,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()
|
||||
@ -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