From fb393778e23742aa44cc419275a7cdf5321be6f6 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:13:45 +0200 Subject: [PATCH 01/15] Update requirements.txt --- requirements.txt | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7487ea6..f2801fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,43 +1,12 @@ -attrs==23.2.0 -babelfish==0.6.1 -build==1.2.1 -certifi==2024.7.4 -charset-normalizer==3.3.2 -click==8.1.7 -diskcache==5.6.3 -flatbencode==0.2.1 -frozenlist==1.4.1 guessit==3.8.0 -idna==3.7 -markdown-it-py==3.0.0 -mdurl==0.1.2 -multidict==6.0.5 -mypy-extensions==1.0.0 -numpy==2.0.1 opencv-python==4.10.0.84 -packaging==24.1 -pathspec==0.12.1 -platformdirs==4.2.2 -Pygments==2.18.0 -pdf2image==1.17.0 pymediainfo==6.1.0 -pyproject_hooks==1.1.0 -python-dateutil==2.9.0.post0 python-decouple==3.8 python-qbittorrent==0.4.3 -rapidfuzz==3.9.5 -rebulk==3.2.0 requests==2.32.3 rich==13.7.1 -six==1.16.0 +torf==4.2.7 +tqdm==4.66.5 thefuzz==0.22.1 tmdbv3api==1.9.0 -tomli==2.0.1 -torf==4.2.7 -tqdm==4.66.4 -typing_extensions==4.12.2 -ua-parser==0.18.0 -Unidecode==1.3.8 -urllib3==2.2.2 -user-agents==2.2.0 -yarl==1.9.4 +unidecode==1.3.8 \ No newline at end of file From 58b1ca3f80d1acb4acf9087ee80195b7ba3db2e4 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:14:09 +0200 Subject: [PATCH 02/15] Remove unused import --- unit3dup/utility.py | 1 - 1 file changed, 1 deletion(-) diff --git a/unit3dup/utility.py b/unit3dup/utility.py index 8866c46..72b9c6b 100644 --- a/unit3dup/utility.py +++ b/unit3dup/utility.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import os -from pdf2image import convert_from_path from thefuzz import fuzz From f9ffdd94b3cc8a72eeea81ab1d0ae7438ff1f2ca Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:14:51 +0200 Subject: [PATCH 03/15] Remove unused import --- unit3dup/utility.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/unit3dup/utility.py b/unit3dup/utility.py index 72b9c6b..39763c7 100644 --- a/unit3dup/utility.py +++ b/unit3dup/utility.py @@ -145,11 +145,6 @@ def media_docu_type(file_name: str) -> str: return type_.get(ext, None) - @staticmethod - def get_cover(file_name: str): - pages = convert_from_path(file_name, first_page=1, last_page=1) - pages[0].save(f"{file_name}.png", "PNG") - @staticmethod def fuzzyit(str1: str, str2: str) -> int: return fuzz.ratio(str1.lower(), str2.lower()) From 19ad5574757a11b9ba649163e5b0316463e4c4e4 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:47:50 +0200 Subject: [PATCH 04/15] Remove preference.cfg --- preferences.cfg | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 preferences.cfg diff --git a/preferences.cfg b/preferences.cfg deleted file mode 100644 index 7e6740c..0000000 --- a/preferences.cfg +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- - -# duplicate_on = True -> It Searches for duplicates -# duplicate_on = False -> Does not search for duplicates -duplicate_on=False - -# Choose the numbers of screenshots you want upload to tracker -number_of_screenshots=4 - -# Path for torrent file -torrent_archive ='' - From 42a07f0d7978fcf255164335cb5cb9e98321f8b3 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:48:25 +0200 Subject: [PATCH 05/15] Move preferences in service.env --- unit3dup/command.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/unit3dup/command.py b/unit3dup/command.py index 6fa70d8..3e96ede 100644 --- a/unit3dup/command.py +++ b/unit3dup/command.py @@ -102,12 +102,4 @@ def __init__(self): console.log( f"Configuration file '{self.args.tracker}.json' not found for tracker '{self.args.tracker}'" ) - sys.exit() - - database_tracker = os.path.join(f'preferences.cfg') - if not os.path.exists(database_tracker): - console.log( - f"Configuration file 'preferences.cfg' not found'" - ) - sys.exit() - + sys.exit() \ No newline at end of file From 072dcaf90e62ad7cf3022fec0c612b31a5a1ea7f Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:50:27 +0200 Subject: [PATCH 06/15] Move preferences in service.env --- unit3dup/config.py | 50 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/unit3dup/config.py b/unit3dup/config.py index 8b458bf..ea68de3 100644 --- a/unit3dup/config.py +++ b/unit3dup/config.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- import os -import ast - import decouple from decouple import Config, RepositoryEnv from rich.console import Console @@ -65,16 +63,16 @@ def __init__(self): self.QBIT_PORT: str = "" self.API_TOKEN: str = "" self.BASE_URL: str = "" + self.DUPLICATE: str = "" + self.SCREENSHOTS = 0 + self.TORRENT_ARCHIVE: str = "" + self.tracker_values: dict = {} self.trackers = None - self.duplicate_on = None - self.torrent_archive = None - self.number_of_screenshots = None def service(self): service_not_found: bool = False - preferences_not_found: bool = False # Get the current folder current_folder = os.path.dirname(__file__) @@ -92,34 +90,6 @@ def service(self): ) console.log(self.message) - preferences_path = os.path.join(root_folder, "preferences.cfg") - - # Does it Exist ? - if not os.path.isfile(preferences_path): - preferences_not_found = True - - if preferences_not_found: - self.message.append( - f"\nfile 'preferences.cfg' not found in {preferences_path.upper()}", - style="bold red", - ) - console.log(self.message) - - try: - config_load_preferences = Config(RepositoryEnv(preferences_path)) - self.duplicate_on = ast.literal_eval(config_load_preferences("duplicate_on")) - self.number_of_screenshots = int(config_load_preferences("number_of_screenshots")) - - torrent_archive_path = config_load_preferences("torrent_archive") - if torrent_archive_path != '' and not os.path.exists(torrent_archive_path): - console.log("The torrent archive path does not exist. Default path has been set", style="bold red") - else: - self.torrent_archive = torrent_archive_path - - except decouple.UndefinedValueError as e: - console.log(f"* preferences.cfg * {e}", style="red bold") - exit(1) - try: config_load_service = Config(RepositoryEnv(service_path)) self.TMDB_APIKEY = config_load_service("TMDB_APIKEY") @@ -129,6 +99,9 @@ def service(self): self.QBIT_PASS = config_load_service("QBIT_PASS") self.QBIT_URL = config_load_service("QBIT_URL") self.QBIT_PORT = config_load_service("QBIT_PORT") + self.DUPLICATE = config_load_service("duplicate_on") + self.SCREENSHOTS = int(config_load_service("number_of_screenshots")) + self.TORRENT_ARCHIVE = config_load_service("torrent_archive") except decouple.UndefinedValueError as e: console.log(f"* service.env * {e}", style="red bold") exit(1) @@ -136,15 +109,14 @@ def service(self): pass exit(1) - def validate(self): env_files = [ os.path.splitext(file_name)[0].lower() for file_name in os.listdir() if os.path.isfile(file_name) - and os.path.splitext(file_name)[1].lower() == ".env" - and "service.env" not in file_name.lower() + and os.path.splitext(file_name)[1].lower() == ".env" + and "service.env" not in file_name.lower() ] for tracker_name in env_files: @@ -153,7 +125,9 @@ def validate(self): # Build complete paths tracker_env_path = os.path.join(self.root_folder, tracker_env_name) - tracker_json_path = os.path.join(self.root_folder, 'database', tracker_json_name) + tracker_json_path = os.path.join( + self.root_folder, "database", tracker_json_name + ) # // check tracker file configuration .env e .json config_load_tracker = Config(RepositoryEnv(tracker_env_path)) From 1396152c9ae9c6d4c686b52224a30528d08264d4 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:52:13 +0200 Subject: [PATCH 07/15] Move preferences in service.env --- unit3dup/media.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unit3dup/media.py b/unit3dup/media.py index 835af2b..ab4a4d9 100644 --- a/unit3dup/media.py +++ b/unit3dup/media.py @@ -54,10 +54,13 @@ def process(self, mode="man"): for content in contents: console.rule(content.file_name) - if content.category == self.movie_category or content.category == self.serie_category: + if ( + content.category == self.movie_category + or content.category == self.serie_category + ): video_manager = VideoManager(content=content) - if config.duplicate_on: + if config.DUPLICATE: results = video_manager.check_duplicate() if results: console.log( From e7307dfb1127c5376abefe5a3537b0ceefaeaf1b Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:53:12 +0200 Subject: [PATCH 08/15] Move preferences in service.env --- unit3dup/qbitt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unit3dup/qbitt.py b/unit3dup/qbitt.py index 5cdb4a1..3eb28b2 100644 --- a/unit3dup/qbitt.py +++ b/unit3dup/qbitt.py @@ -16,13 +16,13 @@ class Qbitt: def __init__( - self, tracker_data_response: str, torrent: Mytorrent, contents: Contents + self, tracker_data_response: str, torrent: Mytorrent, contents: Contents ): self.torrent = torrent self.torrent_path = contents.torrent_path self.torrent_file = None self.torrents = None - self.torrent_archive = config.torrent_archive + self.torrent_archive = config.TORRENT_ARCHIVE self.qb = Client(f"{config.QBIT_URL}:{config.QBIT_PORT}/") download_torrent_dal_tracker = requests.get(tracker_data_response) From e75bb960576a34d4f4eaecb104d3c9b8fb504f00 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:53:31 +0200 Subject: [PATCH 09/15] Move preferences in service.env --- service.back | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/service.back b/service.back index af935b7..6099cb0 100644 --- a/service.back +++ b/service.back @@ -1,7 +1,26 @@ +## TMDDB API KEY - https://www.themoviedb.org/ TMDB_APIKEY= + +## IMGBB API KEY - https://imgbb.com/ IMGBB_KEY= + +## FREEIMAGE API_KEY - https://freeimage.host/ FREE_IMAGE_KEY= + +## QBITTORRENT REMOTE CONTROL QBIT_USER= QBIT_PASS= -QBIT_URL=http://127.0.0.1 -QBIT_PORT= \ No newline at end of file +QBIT_URL= +QBIT_PORT= + +## USER OPTIONS + +# True = It Searches for duplicates +# False = Does not search for duplicates +duplicate_on=False + +# Choose the numbers of screenshots you want upload to tracker +number_of_screenshots=4 + +# Path for your local torrent file +torrent_archive ='' \ No newline at end of file From c6dde7100147fb79a2666523b688beac2c2e86cd Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 18:55:55 +0200 Subject: [PATCH 10/15] Move preferences in service.env --- unit3dup/pvtVideo.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/unit3dup/pvtVideo.py b/unit3dup/pvtVideo.py index 8abb67e..b2238c1 100644 --- a/unit3dup/pvtVideo.py +++ b/unit3dup/pvtVideo.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -import pprint import random import cv2 import os @@ -34,11 +33,7 @@ def __init__(self, fileName: str): # Frame count self.numero_di_frame = None # Screenshots samples - self.samples_n = ( - config.number_of_screenshots - if 2 <= config.number_of_screenshots <= 10 - else 4 - ) + self.samples_n = config.SCREENSHOTS if 2 <= config.SCREENSHOTS <= 10 else 4 # Catturo i frames del video self.video_capture = cv2.VideoCapture(self.file_name) From 4422858f45a898a0fbddbb036936feab630c8409 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 21:38:29 +0200 Subject: [PATCH 11/15] gitignore --- .gitignore | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b78217 --- /dev/null +++ b/.gitignore @@ -0,0 +1,165 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# Env file +*.env + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ From 314d35e1aeb4fca56b90b6ce5e27601560b45ce6 Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 23:18:42 +0200 Subject: [PATCH 12/15] Add an autouploader --- autoupdate.py | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 autoupdate.py diff --git a/autoupdate.py b/autoupdate.py new file mode 100644 index 0000000..0379791 --- /dev/null +++ b/autoupdate.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +import subprocess +import os +import sys + + +def install_git(package): + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + + +def install_requirements(): + subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) + + +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.repo_exist = os.path.exists(self.repo_local_path) + + def process(self) -> bool: + if not self.repo_exist: + print(f"Cloning repository from {self.repo_url} to {self.repo_local_path}") + git.Repo.clone_from(self.repo_url, self.repo_local_path) + install_requirements() + return True + else: + self._update() + + def _update(self): + # Check if the path is a valid Git repository + try: + repo = git.Repo(self.repo_local_path) + except git.exc.InvalidGitRepositoryError: + print(f"{self.repo_local_path} is not a valid Git repository") + exit(1) + + # If there are uncommitted local changes + if repo.is_dirty(untracked_files=True): + repo.git.stash('save', '--include-untracked') + + # Update the repository + origin = repo.remotes.origin + origin.pull() + print("Repository updated successfully.") + + # Reapply stashed local changes, if any + if repo.git.stash('list'): + repo.git.stash('pop') + print("Local changes reapplied.") + + +if __name__ == "__main__": + # Test Imports + try: + import git + import rich + except ImportError: + print("GitPython is not installed. Installation in progress...") + install_git("gitpython") + install_git("rich") + + import git + from rich.console import Console + + console = Console(log_path=False) + + console.rule("Welcome - Autoupdate for Unit3D-up - Welcome", style='violet bold') + my_git = MyGit(repo_local_path=os.getcwd()) + my_git.process() From f23b5b1b4730eea68e17986dc54bf8474969fa1e Mon Sep 17 00:00:00 2001 From: Parzival Date: Tue, 20 Aug 2024 23:45:46 +0200 Subject: [PATCH 13/15] Remove requirements --- autoupdate.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/autoupdate.py b/autoupdate.py index 0379791..29cc626 100644 --- a/autoupdate.py +++ b/autoupdate.py @@ -8,10 +8,6 @@ def install_git(package): subprocess.check_call([sys.executable, "-m", "pip", "install", package]) -def install_requirements(): - subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) - - class MyGit: """ Install gitPython and update the repository @@ -26,7 +22,6 @@ def process(self) -> bool: if not self.repo_exist: print(f"Cloning repository from {self.repo_url} to {self.repo_local_path}") git.Repo.clone_from(self.repo_url, self.repo_local_path) - install_requirements() return True else: self._update() @@ -51,7 +46,7 @@ def _update(self): # Reapply stashed local changes, if any if repo.git.stash('list'): repo.git.stash('pop') - print("Local changes reapplied.") + print("Local changes reapplied") if __name__ == "__main__": @@ -60,7 +55,7 @@ def _update(self): import git import rich except ImportError: - print("GitPython is not installed. Installation in progress...") + print("Installation in progress...") install_git("gitpython") install_git("rich") From e96a4d97c5da93cd040e6d7f27c45b5e55326929 Mon Sep 17 00:00:00 2001 From: Parzival Date: Wed, 21 Aug 2024 00:04:55 +0200 Subject: [PATCH 14/15] Add colors --- autoupdate.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/autoupdate.py b/autoupdate.py index 29cc626..1692e3a 100644 --- a/autoupdate.py +++ b/autoupdate.py @@ -20,7 +20,7 @@ def __init__(self, repo_local_path: str): def process(self) -> bool: if not self.repo_exist: - print(f"Cloning repository from {self.repo_url} to {self.repo_local_path}") + console.log(f"Cloning repository from {self.repo_url} to {self.repo_local_path}", style="bold blue") git.Repo.clone_from(self.repo_url, self.repo_local_path) return True else: @@ -31,7 +31,7 @@ def _update(self): try: repo = git.Repo(self.repo_local_path) except git.exc.InvalidGitRepositoryError: - print(f"{self.repo_local_path} is not a valid Git repository") + console.log(f"{self.repo_local_path} is not a valid Git repository", style='red bold') exit(1) # If there are uncommitted local changes @@ -41,12 +41,11 @@ def _update(self): # Update the repository origin = repo.remotes.origin origin.pull() - print("Repository updated successfully.") + console.log(f"Repository updated successfully", style="bold green") # Reapply stashed local changes, if any if repo.git.stash('list'): repo.git.stash('pop') - print("Local changes reapplied") if __name__ == "__main__": From 5b0e9e626afc27ea134198f1a3e9443c6f46e9fe Mon Sep 17 00:00:00 2001 From: Parzival Date: Wed, 21 Aug 2024 00:10:16 +0200 Subject: [PATCH 15/15] Add colors --- autoupdate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoupdate.py b/autoupdate.py index 1692e3a..254bdc0 100644 --- a/autoupdate.py +++ b/autoupdate.py @@ -41,8 +41,8 @@ def _update(self): # Update the repository origin = repo.remotes.origin origin.pull() - console.log(f"Repository updated successfully", style="bold green") - + console.log(f"Repository updated successfully to '{repo.tags[-1]}'", style="bold blue") + console.rule("", style='violet bold') # Reapply stashed local changes, if any if repo.git.stash('list'): repo.git.stash('pop') @@ -63,6 +63,6 @@ def _update(self): console = Console(log_path=False) - console.rule("Welcome - Autoupdate for Unit3D-up - Welcome", style='violet bold') + console.rule("- Autoupdate for Unit3D-up -", style='violet bold') my_git = MyGit(repo_local_path=os.getcwd()) my_git.process()