Skip to content

Commit

Permalink
Merge pull request #38 from 31December99/0.x.x
Browse files Browse the repository at this point in the history
Add ftp , pw , rar files
  • Loading branch information
31December99 authored Sep 21, 2024
2 parents bcbe078 + fae0e02 commit 76c6f90
Show file tree
Hide file tree
Showing 76 changed files with 3,530 additions and 1,244 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ PATH environment user variable
1. Download the updater (zip) [Download autoupdate.py](https://gist.github.com/31December99/8e51466feb9df1606fd4199141ac54bb)
2. run python3 autoupdate.py
3. run pip install -r requirements.txt
3. Set up the configuration .env file(s) service and itt ( rename .back in .env)
4. Set up the configuration .env file(s) service and itt ( rename .back in .env)

### Update Bot
python3 autoupdate.py
Expand Down
99 changes: 99 additions & 0 deletions autoupdate_0xx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# -*- coding: utf-8 -*-
import subprocess
import os
import sys


def install_git(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])


class MyGit:
"""
Install gitPython and update the repository
"""

def __init__(self, repo_local_path: str):
self.repo_local_path = repo_local_path
self.repo_url = "https://github.com/31December99/Unit3Dup.git"
self.branch_name = "0.x.x"
self.repo_exist = os.path.exists(self.repo_local_path)

def process(self) -> bool:
if not self.repo_exist:
console.log(
f"Cloning repository from {self.repo_url} to {self.repo_local_path}",
style="bold blue",
)
self._clone()
return True
else:
self._update()

def _update(self):
# Validate git repo
try:
repo = git.Repo(self.repo_local_path)
except git.exc.InvalidGitRepositoryError:
console.log(
f"{self.repo_local_path} is not a valid Git repository.",
style="red bold",
)
self._clone()
return

# Checkout new branche
repo.git.checkout(self.branch_name)

if repo.is_dirty(untracked_files=True):
repo.git.stash("save", "--include-untracked")

origin = repo.remotes.origin
origin.pull(self.branch_name)
console.log(
f"Repository updated successfully to branch '{self.branch_name}'",
style="bold blue",
)
console.rule("", style="violet bold")

# Stash
if repo.git.stash("list"):
repo.git.stash("pop")

def _clone(self):
current_dir = os.getcwd()
new_folder_path = os.path.join(current_dir, "Unit3d-up_0.x.x")

if os.path.exists(new_folder_path):
console.log(
f"Folder {new_folder_path} already exists. Please remove it manually and retry",
style="red bold",
)
exit(1)

repo = git.Repo.clone_from(
self.repo_url, new_folder_path, branch=self.branch_name
)
console.log(
f"Cloned repository from {self.repo_url} to {new_folder_path} on branch {self.branch_name}",
style="bold blue",
)


if __name__ == "__main__":
try:
import git
import rich
except ImportError:
print("Installation in progress...")
install_git("gitpython")
install_git("rich")

import git
from rich.console import Console

console = Console(log_path=False)

console.rule("- Autoupdate for Unit3D-up_0.x.x -", style="violet bold")
my_git = MyGit(repo_local_path=os.getcwd())
my_git.process()
97 changes: 67 additions & 30 deletions common/bdinfo_string.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
# -*- coding: utf-8 -*-


class BDInfo:
def __init__(self, disc_label, disc_size, protection, playlist, size, length, total_bitrate, video, audio,
languages, subtitles):
"""
A class to represent information about a Blu-ray disc.
Attributes:
disc_label (str): The label or name of the disc.
disc_size (str): The size of the disc.
protection (str): The type of protection applied to the disc.
playlist (str): The playlist information.
size (str): The size of the content on the disc.
length (str): The length of the content on the disc.
total_bitrate (str): The total bitrate of the disc content.
video (str): The video specifications.
audio (list[str]): A list of audio specifications.
languages (list[str]): A list of languages extracted from audio specifications.
subtitles (list[str]): A list of subtitle specifications.
Methods:
from_bdinfo_string(bd_info_string: str) -> 'BDInfo':
Creates an instance of BDInfo from a formatted string.
"""

def __init__(
self,
disc_label: str,
disc_size: str,
protection: str,
playlist: str,
size: str,
length: str,
total_bitrate: str,
video: str,
audio: list[str],
languages: list[str],
subtitles: list[str],
):
self.disc_label = disc_label
self.disc_size = disc_size
self.protection = protection
Expand All @@ -17,45 +49,50 @@ def __init__(self, disc_label, disc_size, protection, playlist, size, length, to
self.subtitles = subtitles

@classmethod
def from_bdinfo_string(cls, bd_info_string):
lines = bd_info_string.strip().split('\n')
data = {
'audio': [],
'subtitles': []
}
def from_bdinfo_string(cls, bd_info_string: str) -> 'BDInfo':
"""
Creates an instance of BDInfo from a formatted string.
Args:
bd_info_string (str): A string containing Blu-ray disc information formatted with labels and values.
Returns:
BDInfo: An instance of the BDInfo class with attributes populated from the input string.
"""
lines = bd_info_string.strip().split("\n")
data = {"audio": [], "subtitles": []}

for line in lines:
# Parsing Audio
if ': ' in line:
key, value = line.split(': ', 1)
key = key.strip().replace(' ', '_').lower()

if key == 'audio':
data['audio'].append(value.strip().lower())
elif key == 'subtitle':
data['subtitles'].append(value.strip().lower())
if ": " in line:
key, value = line.split(": ", 1)
key = key.strip().replace(" ", "_").lower()

if key == "audio":
data["audio"].append(value.strip().lower())
elif key == "subtitle":
data["subtitles"].append(value.strip().lower())
else:
data[key] = value.strip()

# Parsing Languages
languages_parsed = []
for item in data['audio']:
for item in data["audio"]:
item = item.replace("(", " ")
item = item.replace(")", " ")
item = item.split('/')
item = item.split("/")
languages_parsed.append(item[0].strip())
#languages = ','.join(set(languages_parsed))

return cls(
disc_label=data.get('disc_label'),
disc_size=data.get('disc_size'),
protection=data.get('protection'),
playlist=data.get('playlist'),
size=data.get('size'),
length=data.get('length'),
total_bitrate=data.get('total_bitrate'),
video=data.get('video'),
audio=data['audio'],
disc_label=data.get("disc_label"),
disc_size=data.get("disc_size"),
protection=data.get("protection"),
playlist=data.get("playlist"),
size=data.get("size"),
length=data.get("length"),
total_bitrate=data.get("total_bitrate"),
video=data.get("video"),
audio=data["audio"],
languages=languages_parsed,
subtitles=data['subtitles']
subtitles=data["subtitles"],
)
File renamed without changes.
52 changes: 49 additions & 3 deletions common/clients/qbitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import typing
import requests
import qbittorrent

from qbittorrent import Client
from common.config import config
Expand All @@ -21,9 +22,54 @@ def __init__(
self.torrent_file = None
self.torrents = None
self.torrent_archive = config.TORRENT_ARCHIVE
self.tracker_data_response = tracker_data_response
self.qb = None

self.qb = Client(f"{config.QBIT_URL}:{config.QBIT_PORT}/")
download_torrent_dal_tracker = requests.get(tracker_data_response)
@classmethod
def _check_connection(cls) -> typing.Optional[Client]:
try:
qb = Client(f"{config.QBIT_URL}:{config.QBIT_PORT}/")

qb.login(username=config.QBIT_USER, password=config.QBIT_PASS)
qb.torrents()
custom_console.bot_log(f"[QBITTORRENT]...... Online")
return qb
except requests.exceptions.HTTPError:
custom_console.bot_error_log(
"[QBITTORENT] HTTP Error. Check IP/port or run qBittorrent"
)
except requests.exceptions.ConnectionError:
custom_console.bot_error_log(
"[QBITTORENT] Connection Error. Check IP/port or run qBittorrent"
)
except qbittorrent.client.LoginRequired:
custom_console.bot_error_log(
"[QBITTORENT] Login required. Check your username and password"
)
except Exception as e:
custom_console.bot_error_log(f"[QBITTORENT] Unexpected error: {str(e)}")
return None

@classmethod
def is_online(cls) -> bool:
qb = cls._check_connection()
return qb is not None

@classmethod
def connect(
cls, tracker_data_response: str, torrent: Mytorrent, contents: Contents
):
qb = cls._check_connection()
if qb:
# Get a new istance of `Qbitt`
instance = cls(tracker_data_response, torrent, contents)
# Reuse the same qbittorrent Client connection for the new instance
instance.qb = qb
return instance
return None

def send_to_client(self):
download_torrent_dal_tracker = requests.get(self.tracker_data_response)

if download_torrent_dal_tracker.status_code == 200:
self.torrent_file = self.download(download_torrent_dal_tracker)
Expand All @@ -46,7 +92,7 @@ def download(self, link: requests) -> typing.IO:
full_path_archive = os.path.join(self.torrent_archive, file_name)
os.replace(full_path_origin, full_path_archive)
else:
# Or save to current the path
# Or save to the current path
full_path_archive = f"{self.torrent_path}.torrent"

# File archived
Expand Down
20 changes: 2 additions & 18 deletions unit3dup/command.py → common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self):
# Upload commands
parser.add_argument("-u", "--upload", type=str, help="Upload Path")
parser.add_argument("-f", "--folder", type=str, help="Upload single folder")
parser.add_argument("-pw", "--pw", action="store_true", help="")
parser.add_argument("-ftp", "--ftp", action="store_true", help="")

parser.add_argument(
"-t", "--tracker", type=str, default="itt", help="Tracker Name"
Expand Down Expand Up @@ -97,21 +99,3 @@ def __init__(self):
if self.args.upload and not os.path.exists(self.args.upload):
custom_console.bot_error_log(f"The path {self.args.upload} does not exist.")
sys.exit()

if not os.path.exists(f"{self.args.tracker}.env"):
custom_console.bot_error_log(
f"Configuration file '{self.args.tracker}.env' not found for tracker '{self.args.tracker}'"
)
sys.exit()

if not os.path.exists(f"service.env"):
custom_console.bot_error_log(
f"Configuration file 'service.env' not found")
sys.exit()

database_tracker = os.path.join("trackers", f"{self.args.tracker}.json")
if not os.path.exists(database_tracker):
custom_console.bot_error_log(
f"Configuration file '{self.args.tracker}.json' not found for tracker '{self.args.tracker}'"
)
sys.exit()
Loading

0 comments on commit 76c6f90

Please sign in to comment.