Skip to content

Commit

Permalink
Merge pull request #77 from nandyalu/dev
Browse files Browse the repository at this point in the history
Merge changes for v0.2.4 Release
  • Loading branch information
nandyalu authored Dec 6, 2024
2 parents 0fc27ad + 9bb8a3e commit 124583d
Show file tree
Hide file tree
Showing 21 changed files with 563 additions and 247 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
- '**/.github/**'
- '**/.devcontainer/**'
- '**/*.md'
- '**/docs/**'
- '**/frontend/**'
pull_request:
branches: [ "main" ]
paths-ignore:
Expand All @@ -18,6 +20,8 @@ on:
- '**/.github/**'
- '**/.devcontainer/**'
- '**/*.md'
- '**/docs/**'
- '**/frontend/**'

jobs:

Expand Down
22 changes: 20 additions & 2 deletions backend/api/v1/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from aiofiles import os as async_os
import os
from fastapi import APIRouter
from fastapi.responses import FileResponse

from api.v1.models import Log
from config.settings import app_settings
Expand All @@ -14,8 +15,21 @@
logs_router = APIRouter(prefix="/logs", tags=["Logs"])


@logs_router.get("/download")
def download_file():
# Read logs from file and send it back
logs_dir = os.path.abspath(os.path.join(app_settings.app_data_dir, "logs"))
file_location = f"{logs_dir}/trailarr.log"
if not os.path.exists(file_location):
return {"message": "Logs file not found"}
file_name = f"trailarr_logs_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.log"
return FileResponse(
file_location, media_type="application/octet-stream", filename=file_name
)


@logs_router.get("/")
async def get_logs(page: int = 1, limit: int = 100) -> list[Log]:
async def get_logs(page: int = 0, limit: int = 1000) -> list[Log]:
# Read logs from file and send it back
logs_dir = os.path.abspath(os.path.join(app_settings.app_data_dir, "logs"))
# logs: list[str] = []
Expand All @@ -33,8 +47,12 @@ async def get_logs(page: int = 1, limit: int = 100) -> list[Log]:
raw_log="No Logs Found",
)
]
log_ext = ".log"
if page > 0:
# If page is greater than 0, then read logs from the log file with page number
log_ext = f".log.{page}"
for log_file in await async_os.listdir(logs_dir):
if log_file.endswith(".log"):
if log_file.endswith(log_ext):
# logging.info(f"Reading logs from {log_file}")
# with open(f"{logs_dir}/{log_file}", "r") as f:
# for line in f:
Expand Down
1 change: 1 addition & 0 deletions backend/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Settings(BaseModel):
update_available: bool
wait_for_media: bool
yt_cookies_path: str
trailer_remove_silence: bool


class UpdateSetting(BaseModel):
Expand Down
18 changes: 18 additions & 0 deletions backend/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def __init__(self):
self.trailer_search_query = os.getenv(
"TRAILER_SEARCH_QUERY", self._DEFAULT_SEARCH_QUERY
)
# Experimental settings
self.trailer_remove_silence = os.getenv(
"TRAILER_REMOVE_SILENCE",
"False",
).lower() in ["true", "1"]

def as_dict(self):
return {
Expand Down Expand Up @@ -171,6 +176,7 @@ def as_dict(self):
"wait_for_media": self.wait_for_media,
"trailer_file_name": self.trailer_file_name,
"yt_cookies_path": self.yt_cookies_path,
"trailer_remove_silence": self.trailer_remove_silence,
}

@property
Expand Down Expand Up @@ -581,6 +587,18 @@ def exclude_words(self):
def exclude_words(self, value: str):
self._exclude_words = value
self._save_to_env("EXCLUDE_WORDS", self._exclude_words)

@property
def trailer_remove_silence(self):
"""Remove silence from the trailers. \n
Default is False. \n
Valid values are True/False."""
return self._trailer_remove_silence

@trailer_remove_silence.setter
def trailer_remove_silence(self, value: bool):
self._trailer_remove_silence = value
self._save_to_env("TRAILER_REMOVE_SILENCE", self._trailer_remove_silence)

def _save_to_env(self, key: str, value: str | int | bool):
"""Save the given key-value pair to the environment variables."""
Expand Down
Loading

0 comments on commit 124583d

Please sign in to comment.