Skip to content

Commit

Permalink
Dev branch draft (#590)
Browse files Browse the repository at this point in the history
feat: add a subtitle provider (subliminal)
fix: address high memory usage
refactor: events, threading, api
fix: various small bug fixes
chore: websockets for smoother frontend experience

Co-authored-by: Spoked
Co-authored-by: iPromKnight
Co-authored-by: AyushSehrawat
Co-authored-by: FlashLightning67
Co-authored-by: davidemarcoli

fix: Fix `reset_streams` function call and ensure `active_stream` is reset (#639)

- Corrected the `reset_streams` function call to pass the `MediaItem` object instead of its ID.
- Added a line to reset the `active_stream` attribute to `None` in the `reset_streams` function.
- Ensured the script exits after performing hard reset or symlink repair based on environment variables.
feat: Add custom color and icon settings for default log levels in logger setup (#640)

- Added custom color and icon settings for default log levels: DEBUG, INFO, WARNING, CRITICAL, and SUCCESS.
- Ensured consistency in log level configuration by applying the same method for both custom and default log levels.

Blue was giving me a headache for debug in dozzle :D
fix: incorrect parameter type in `blacklist_stream` function (#641)

* fix: incorrect parameter type in `blacklist_stream` function

- Corrected the parameter type for the `stream` argument in the `blacklist_stream` function from `str` to `Stream`.
- Added exception handling and logging for errors in the `blacklist_stream` function.
- Ensured session commit and refresh are always executed in `blacklist_stream` when the session is closed.
- Added an exit statement at the end of the script to ensure proper termination.

* feat: Add `package-mode` to pyproject.toml and update dependencies

- Introduced `package-mode` flag in `pyproject.toml`.
- Updated `pytest` dependency to version `8.3.2`.
- Added `testcontainers` dependency.
- Commented out all test cases in `test_container.py` as the container is no longer used. These need to be reworked.
- Added start of db function tests which utilise test-containers to spin up a container, shared across all tests. Between each test, the state of the db is cleared down, and migrated again, so that test sessions are isolated - they cannot share data. Currently only testing reset and blacklist - this forms the basis of all our db tests.
feat: Add functions to delete MediaItems and associated relationships (#642)

- Introduced `delete_media_item`, `delete_media_item_by_id`, `delete_media_item_by_item_id`, and `delete_media_items_by_ids` functions in `db_functions.py` to handle deletion of MediaItems and their associated relationships.
- Updated `MediaItem` relationships to include cascade delete options.
- Refactored `remove_item` endpoint in `items.py` to use the new deletion functions.
- Added tests for the new deletion functions in `test_db_functions.py`.
feat: Add `get_media_items_by_ids` function and integrate it into item removal process (#643)

- Introduced `get_media_items_by_ids` function in `db_functions.py` to retrieve multiple MediaItems by their IDs.
- Updated `remove_item` endpoint in `items.py` to use `get_media_items_by_ids` for validating and deleting media items.
- Added unit test `test_get_media_items_by_ids_success` in `test_db_functions.py` to verify the functionality of `get_media_items_by_ids`.
refactor: Refactor `db_functions.py` to use SQLAlchemy queries for retrieving media items by ID (#644)

fix: add item endpoint

- items added via endpoint where not bound to a session causing issue with event manager

fix: reset item if no active stream

fix: append to active connections if doesnt exist in ws manager

fix: subliminal handle initialization failures

fix: ws handle multiple connection attempts and fix _send_json

fix: Remove unused import and update log file error message in default controller

- Removed unused `EventManager` import from `program.py`.
- Updated error message in `get_logs` endpoint to be more descriptive.

Co-authored-by: iPromKnight <[email protected]>
  • Loading branch information
Gaisberg and iPromKnight authored Aug 19, 2024
1 parent 0126d7a commit 4ececcb
Show file tree
Hide file tree
Showing 35 changed files with 2,805 additions and 1,342 deletions.
5 changes: 5 additions & 0 deletions dev/attach-memray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# Attach memray to the running main.py process
# Usage: ./attach-memray.sh

pgrep -f "main.py" | head -n 1 | xargs -I{} memray attach {}
1,107 changes: 689 additions & 418 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = "Plex torrent streaming through Real Debrid and 3rd party services
authors = ["Riven Developers"]
license = "GPL-3.0"
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.11"
Expand Down Expand Up @@ -37,18 +38,20 @@ subliminal = "^2.2.1"
[tool.poetry.group.dev.dependencies]
pyright = "^1.1.352"
pyperf = "^2.2.0"
pytest = "^8.3.1"
pytest = "^8.3.2"
pyfakefs = "^5.4.1"
ruff = "^0.3.0"
isort = "^5.10.1"
codecov = "^2.1.13"
httpx = "^0.27.0"
memray = "^1.13.4"
testcontainers = "^4.8.0"

[tool.poetry.group.test]
optional = true

[tool.poetry.group.test.dependencies]
pytest= "*"
pytest = "^8.3.2"

[build-system]
requires = ["poetry-core"]
Expand Down
37 changes: 0 additions & 37 deletions src/controllers/actions.py

This file was deleted.

24 changes: 22 additions & 2 deletions src/controllers/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from program.scrapers import Scraping
from program.settings.manager import settings_manager
from sqlalchemy import func, select
from loguru import logger

router = APIRouter(
responses={404: {"description": "Not found"}},
Expand Down Expand Up @@ -70,7 +71,7 @@ async def get_torbox_user():
async def get_services(request: Request):
data = {}
if hasattr(request.app.program, "services"):
for service in request.app.program.services.values():
for service in request.app.program.all_services.values():
data[service.key] = service.initialized
if not hasattr(service, "services"):
continue
Expand Down Expand Up @@ -134,4 +135,23 @@ async def get_stats(_: Request):
payload["incomplete_retries"] = incomplete_retries
payload["states"] = states

return {"success": True, "data": payload}
return {"success": True, "data": payload}

@router.get("/logs")
async def get_logs():
log_file_path = None
for handler in logger._core.handlers.values():
if ".log" in handler._name:
log_file_path = handler._sink._path
break

if not log_file_path:
return {"success": False, "message": "Log file handler not found"}

try:
with open(log_file_path, 'r') as log_file:
log_contents = log_file.read()
return {"success": True, "logs": log_contents}
except Exception as e:
logger.error(f"Failed to read log file: {e}")
return {"success": False, "message": "Failed to read log file"}
Loading

0 comments on commit 4ececcb

Please sign in to comment.