Add README, initial FastAPI setup, and missing configuration files

This commit is contained in:
Jose134 2024-12-08 01:57:25 +01:00
parent de7109b580
commit d3b4ce51e5
5 changed files with 45 additions and 10 deletions

View File

@ -1 +1,27 @@
# file-organizer # file-organizer
This is a custom made software to perform maintenance on downloaded files for DarkBird's anime website.
# System Overview
![System Overview](docs/overview.png)
The application consist of a simple API with a single endpoint which starts a job and returns its ID. Then the job is orchestrated on a different thread following these steps:
1. Filtering:\
Fetch from the qbittorrent API the files that are currently being downloaded in order to filter them out of the process.
2. Deduplication:\
Invoke a [Czkawka](https://github.com/qarmin/czkawka) process to identify duplicate files, keep the appropiate version for each episode.
3. Moving:\
Using regex, identify the directory where each file should be located, and the new name it should have.
4. Log storage:\
Store all the logs for the current job in order to be able to debug and keep trazability of the process.
# Roadmap:
- [x] Be able to move and rename files based on a regex
- [ ] Read qbittorrent credentials from .env file
- [ ] Implement API endpoint using FastAPI
- [ ] Deduplicate files using Czkawka
- [ ] Add unit tests
- [ ] Add logging
- [ ] Create another endpoint to retrieve the logs of a job

1
config/patterns.txt Normal file
View File

@ -0,0 +1 @@
^\[Erai-raws\] (.*) - .*$

BIN
docs/overview.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 KiB

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
requests
fastapi

View File

@ -1,8 +1,8 @@
import os import os
import shutil import shutil
import re import re
import json
import requests import requests
from fastapi import FastAPI
def login_qbittorrent(api_url, username, password): def login_qbittorrent(api_url, username, password):
login_url = f'{api_url}/api/v2/auth/login' login_url = f'{api_url}/api/v2/auth/login'
@ -84,12 +84,18 @@ else:
print(f"The config file {config_file_path} does not exist.") print(f"The config file {config_file_path} does not exist.")
patterns = [] patterns = []
if len(patterns) > 0: app = FastAPI()
# TODO: READ USER AND PASS FROM ENV FILE
cookies = login_qbittorrent('http://qbittorrent.xdarkbird.duckdns.org', 'USER', 'PASS')
downloading = get_qbittorrent_files_downloading('http://qbittorrent.xdarkbird.duckdns.org', cookies)
logout_qbittorrent('http://qbittorrent.xdarkbird.duckdns.org', cookies)
print(f"Patterns: {patterns}") @app.get("/")
print(f"Downloading files: {downloading}") async def root():
group_files_by_prefix(os.path.join(os.getcwd(), 'testfiles'), patterns, downloading) return {"Hello": "World"}
# if len(patterns) > 0:
# # TODO: READ USER AND PASS FROM ENV FILE
# cookies = login_qbittorrent('http://qbittorrent.xdarkbird.duckdns.org', 'USER', 'PASS')
# downloading = get_qbittorrent_files_downloading('http://qbittorrent.xdarkbird.duckdns.org', cookies)
# logout_qbittorrent('http://qbittorrent.xdarkbird.duckdns.org', cookies)
# print(f"Patterns: {patterns}")
# print(f"Downloading files: {downloading}")
# group_files_by_prefix(os.path.join(os.getcwd(), 'testfiles'), patterns, downloading)