Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1208420a0 | |||
| 575d1a7008 | |||
| 4d3bb6cfd8 | |||
| 0629ffc3bc | |||
| a6f0d1c73c | |||
| a7c3b544fa | |||
| 5c6b0b0444 | |||
| b1c9fa5f8e | |||
| cae08acab3 | |||
| 2fc8a32b5f | |||
| a745adc1ab | |||
| aa95c6bb3b | |||
| 2520c2b248 | |||
| 7e0baebc20 | |||
| fcbf534f5d | |||
| 06f4c0683a | |||
| 588c84c2c8 | |||
| b483edae74 | |||
| df4f5dde17 | |||
| 7b14445387 | |||
| 1bb07d7f68 | |||
| 0667fac940 | |||
| 28b68fa9eb | |||
| bc155d781a | |||
| 9f1fe20c16 | |||
| dffcaca668 | |||
| 86d0adebda | |||
| 304e973db1 | |||
| 6c84112d29 | |||
| 1131b81454 | |||
| 6a1780bcee | |||
| fbafe75fae | |||
| fbb5bb55c7 | |||
| f9dbe733c3 | |||
| 3f43662c1f | |||
| aa4517aaf5 | |||
| 350f1d97e6 | |||
| c18ff5b2ef | |||
| f791798206 | |||
| 15e7636a92 | |||
| 3719cda819 | |||
| 2718d817d9 | |||
| 5f62040611 | |||
| fda9f01da1 | |||
| c879c4c0d9 | |||
| 559342fae7 | |||
| d1a4273fb2 | |||
| 432eee153e | |||
| fe4061d1a1 | |||
| 22697fdc1d | |||
| c982fb930f | |||
| 305743d752 | |||
| 6f234ebc48 | |||
| 7dae8647e6 | |||
| 06e49be1f9 | |||
| 40f818bd2c | |||
| 6b14847598 | |||
| 0ede137170 |
@@ -0,0 +1,8 @@
|
||||
# Normalize line endings to avoid CRLF issues in Linux containers
|
||||
* text=auto
|
||||
|
||||
# Shell scripts must be LF for correct shebang parsing
|
||||
*.sh text eol=lf
|
||||
|
||||
# PowerShell scripts are typically CRLF on Windows
|
||||
*.ps1 text eol=crlf
|
||||
+7
-1
@@ -6,9 +6,13 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends build-essential \
|
||||
&& apt-get install -y --no-install-recommends build-essential tzdata \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN sed -i 's/\r$//' /usr/local/bin/docker-entrypoint.sh \
|
||||
&& chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
@@ -17,4 +21,6 @@ COPY frontend ./frontend
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||||
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
|
||||
|
||||
@@ -26,6 +26,22 @@ PlexPlaylistSync 是一个用于同步 Plex 播放列表和本地 `.m3u`/`.m3u8`
|
||||
docker compose up --build
|
||||
```
|
||||
|
||||
### 配置容器时区
|
||||
|
||||
本项目支持通过 `docker-compose.yml` 的环境变量 `TZ` 配置容器运行时区(需要使用有效的 IANA 时区名,例如 `Asia/Shanghai`、`UTC`、`America/New_York`)。
|
||||
|
||||
- 临时指定(当前终端会话生效):
|
||||
|
||||
```bash
|
||||
TZ=UTC docker compose up --build
|
||||
```
|
||||
|
||||
- 或在项目根目录创建 `.env`:
|
||||
|
||||
```env
|
||||
TZ=Asia/Shanghai
|
||||
```
|
||||
|
||||
- 默认会以 `--reload` 模式启动,监听本地 8080 端口,可在浏览器访问 `http://localhost:8080`。
|
||||
- 通过 `./app/config.json` 保存的 Plex 配置信息会在主机和容器间共享,便于调试时保留登录 token 等数据。
|
||||
- 如需自定义端口或其他参数,可在 `docker-compose.yml` 中调整。
|
||||
|
||||
+22
-5
@@ -2,10 +2,27 @@
|
||||
"theme": "auto",
|
||||
"token": "",
|
||||
"server_url": "",
|
||||
"server_scheme": "http",
|
||||
"server_port": "32400",
|
||||
"server_scheme": "https",
|
||||
"timeout": 9,
|
||||
"library_name": "",
|
||||
"sync_mode": "merge_local_primary",
|
||||
"local_path": "playlist",
|
||||
"path_rules": []
|
||||
}
|
||||
"sync_mode": "local_force",
|
||||
"local_path": "playlists",
|
||||
"path_rules": [],
|
||||
"path_mapping": {
|
||||
"mode": "SIMPLE",
|
||||
"simple": [],
|
||||
"regex": {
|
||||
"local_pre": [],
|
||||
"local_post": [],
|
||||
"remote_pre": [],
|
||||
"remote_post": []
|
||||
}
|
||||
},
|
||||
"schedule_mode": "DISABLED",
|
||||
"schedule_cron": "",
|
||||
"schedule_daily_time": "00:00",
|
||||
"schedule_weekly_days": [0],
|
||||
"schedule_weekly_time": "00:00",
|
||||
"schedule_auto_watch": false
|
||||
}
|
||||
|
||||
+163
-3
@@ -4,7 +4,8 @@ from typing import Sequence
|
||||
|
||||
from fastapi import FastAPI, Form, HTTPException, Query, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse
|
||||
import asyncio
|
||||
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from pydantic import BaseModel, Field
|
||||
@@ -14,9 +15,16 @@ from app.utils.local_playlist import load_local_playlist, scan_local_playlists
|
||||
from app.utils.logger import logger
|
||||
from app.utils.playlist_merge import SyncMode, TEST_PLAYLIST_DIR, sync_all_playlists
|
||||
from app.utils.plex_client import plex_client
|
||||
from app.utils.scheduler import start_scheduler, update_scheduler_job, get_next_run_time, validate_cron_expression
|
||||
from app.utils.sync_manager import sync_manager
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
sync_manager.set_event_loop(asyncio.get_running_loop())
|
||||
start_scheduler()
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
@@ -84,14 +92,35 @@ class RegexRule(BaseModel):
|
||||
replacement: str = ""
|
||||
|
||||
|
||||
class ReplacementRule(BaseModel):
|
||||
id: str = ""
|
||||
search: str
|
||||
replace: str = ""
|
||||
|
||||
|
||||
class RegexRulesGroup(BaseModel):
|
||||
local_pre: list[ReplacementRule] = []
|
||||
local_post: list[ReplacementRule] = []
|
||||
remote_pre: list[ReplacementRule] = []
|
||||
remote_post: list[ReplacementRule] = []
|
||||
|
||||
|
||||
class PathMappingPayload(BaseModel):
|
||||
mode: str = "SIMPLE"
|
||||
simple: list[ReplacementRule] = []
|
||||
regex: RegexRulesGroup = RegexRulesGroup()
|
||||
|
||||
|
||||
class SyncSettingsResponse(BaseModel):
|
||||
sync_mode: str
|
||||
path_rules: list[RegexRule]
|
||||
path_mapping: dict | None = None
|
||||
local_path: str
|
||||
library_name: str | None = None
|
||||
server_url: str | None = None
|
||||
scheme: str | None = None
|
||||
port: str | None = None
|
||||
timeout: int | None = None
|
||||
token: str | None = None
|
||||
|
||||
|
||||
@@ -106,6 +135,75 @@ class ConnectRequest(BaseModel):
|
||||
library_name: str | None = None
|
||||
|
||||
|
||||
class ScheduleSettings(BaseModel):
|
||||
mode: str
|
||||
cronExpression: str
|
||||
dailyTime: str
|
||||
weeklyDays: list[int]
|
||||
weeklyTime: str
|
||||
autoWatch: bool
|
||||
|
||||
|
||||
class BackupSettingsPayload(BaseModel):
|
||||
enabled: bool
|
||||
retention_count: int
|
||||
|
||||
|
||||
@app.get("/api/backup/settings")
|
||||
async def get_backup_settings():
|
||||
server_config.load()
|
||||
return {
|
||||
"enabled": server_config.backup_enabled,
|
||||
"retention_count": server_config.backup_retention_count
|
||||
}
|
||||
|
||||
|
||||
@app.put("/api/backup/settings")
|
||||
async def save_backup_settings(settings: BackupSettingsPayload):
|
||||
server_config.set_backup(
|
||||
enabled=settings.enabled,
|
||||
retention_count=settings.retention_count
|
||||
)
|
||||
logger.info(f"Backup settings updated. Enabled: {settings.enabled}, Retention: {settings.retention_count}")
|
||||
return {"status": "success", "message": "Backup settings saved"}
|
||||
|
||||
|
||||
@app.get("/api/schedule")
|
||||
async def get_schedule():
|
||||
next_run = get_next_run_time()
|
||||
next_run_str = next_run.strftime("%Y-%m-%d %H:%M:%S") if next_run else None
|
||||
|
||||
return {
|
||||
"mode": server_config.schedule_mode,
|
||||
"cronExpression": server_config.schedule_cron,
|
||||
"dailyTime": server_config.schedule_daily_time,
|
||||
"weeklyDays": server_config.schedule_weekly_days,
|
||||
"weeklyTime": server_config.schedule_weekly_time,
|
||||
"autoWatch": server_config.schedule_auto_watch,
|
||||
"nextRun": next_run_str
|
||||
}
|
||||
|
||||
|
||||
@app.put("/api/schedule")
|
||||
async def save_schedule(settings: ScheduleSettings):
|
||||
# Validate Cron if mode is CRON
|
||||
if settings.mode == "CRON" and settings.cronExpression.strip():
|
||||
if not validate_cron_expression(settings.cronExpression):
|
||||
raise HTTPException(status_code=400, detail="Invalid Cron expression format")
|
||||
|
||||
server_config.set_schedule(
|
||||
mode=settings.mode,
|
||||
cron=settings.cronExpression,
|
||||
daily_time=settings.dailyTime,
|
||||
weekly_days=settings.weeklyDays,
|
||||
weekly_time=settings.weeklyTime,
|
||||
auto_watch=settings.autoWatch
|
||||
)
|
||||
update_scheduler_job()
|
||||
logger.info(f"Schedule settings updated via API. Mode: {settings.mode}")
|
||||
return {"status": "success", "message": "Schedule updated"}
|
||||
|
||||
|
||||
class ConnectResponse(BaseModel):
|
||||
token: str
|
||||
serverInfo: dict
|
||||
@@ -135,6 +233,7 @@ def _get_cloud_playlists() -> tuple[list[dict], str, dict, str, list[str]]:
|
||||
scheme=server_config.scheme,
|
||||
url=server_config.url,
|
||||
port=server_config.port,
|
||||
timeout=server_config.timeout,
|
||||
)
|
||||
status = "connected" if plex_client.connected else "failed"
|
||||
server_info.update(
|
||||
@@ -245,6 +344,7 @@ def _get_server_status() -> tuple[dict, str, list[dict]]:
|
||||
scheme=server_config.scheme,
|
||||
url=server_config.url,
|
||||
port=server_config.port,
|
||||
timeout=server_config.timeout,
|
||||
)
|
||||
connection_status = "connected" if plex_client.connected else "failed"
|
||||
server_info.update(
|
||||
@@ -296,11 +396,13 @@ async def get_settings():
|
||||
return SyncSettingsResponse(
|
||||
sync_mode=server_config.sync_mode,
|
||||
path_rules=rules,
|
||||
path_mapping=server_config.path_mapping,
|
||||
local_path=server_config.local_path,
|
||||
library_name=server_config.library_name,
|
||||
server_url=server_config.url,
|
||||
scheme=server_config.scheme,
|
||||
port=server_config.port,
|
||||
timeout=server_config.timeout,
|
||||
token=server_config.token,
|
||||
)
|
||||
|
||||
@@ -323,6 +425,22 @@ async def update_regex_rules(payload: RegexRulePayload):
|
||||
return {"rules": payload.rules}
|
||||
|
||||
|
||||
@app.put("/api/settings/path-mapping")
|
||||
async def update_path_mapping(payload: PathMappingPayload):
|
||||
path_mapping_dict = {
|
||||
"mode": payload.mode,
|
||||
"simple": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.simple],
|
||||
"regex": {
|
||||
"local_pre": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.local_pre],
|
||||
"local_post": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.local_post],
|
||||
"remote_pre": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_pre],
|
||||
"remote_post": [{"id": rule.id, "search": rule.search, "replace": rule.replace} for rule in payload.regex.remote_post],
|
||||
}
|
||||
}
|
||||
server_config.set_and_save_config(path_mapping=path_mapping_dict)
|
||||
return {"path_mapping": server_config.path_mapping}
|
||||
|
||||
|
||||
@app.put("/api/settings/library")
|
||||
async def update_library(payload: LibrarySelection):
|
||||
server_config.set_and_save_config(library_name=payload.library_name)
|
||||
@@ -345,6 +463,7 @@ async def api_connect(payload: ConnectRequest):
|
||||
scheme=payload.protocol,
|
||||
url=payload.address,
|
||||
port=payload.port,
|
||||
timeout=payload.timeout,
|
||||
)
|
||||
libraries = []
|
||||
selected_library = payload.library_name or server_config.library_name
|
||||
@@ -359,6 +478,7 @@ async def api_connect(payload: ConnectRequest):
|
||||
scheme=payload.protocol,
|
||||
url=payload.address,
|
||||
port=payload.port,
|
||||
timeout=payload.timeout,
|
||||
library_name=selected_library or "",
|
||||
)
|
||||
server_info = {
|
||||
@@ -395,6 +515,25 @@ async def api_playlists(server: str = Query(..., pattern="(?i)^(local|cloud)$"),
|
||||
}
|
||||
|
||||
|
||||
@app.get("/api/sync/status")
|
||||
async def get_sync_status():
|
||||
return sync_manager.status
|
||||
|
||||
@app.get("/api/sync/events")
|
||||
async def sync_events(request: Request):
|
||||
async def event_generator():
|
||||
q = await sync_manager.subscribe()
|
||||
try:
|
||||
while True:
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
data = await q.get()
|
||||
yield f"data: {data}\n\n"
|
||||
finally:
|
||||
sync_manager.unsubscribe(q)
|
||||
|
||||
return StreamingResponse(event_generator(), media_type="text/event-stream")
|
||||
|
||||
@app.post("/api/sync")
|
||||
async def api_sync(payload: SyncRequest):
|
||||
server_config.load()
|
||||
@@ -404,7 +543,20 @@ async def api_sync(payload: SyncRequest):
|
||||
raise HTTPException(status_code=400, detail=str(exc))
|
||||
|
||||
local_dir = payload.local_path or server_config.local_path
|
||||
results = sync_all_playlists(local_dir=local_dir, mode=sync_mode, test_folder=TEST_PLAYLIST_DIR)
|
||||
|
||||
# Use sync_manager to execute sync, ensuring state is updated
|
||||
try:
|
||||
results = sync_manager.run_sync(
|
||||
trigger_source="api",
|
||||
wait=True,
|
||||
# We need to pass these to _perform_sync
|
||||
sync_kwargs={"local_dir": local_dir, "mode": sync_mode}
|
||||
)
|
||||
except Exception as e:
|
||||
if str(e) == "Sync already in progress":
|
||||
raise HTTPException(status_code=409, detail="Sync already in progress")
|
||||
raise e
|
||||
|
||||
merged_count = sum(len(item.merged_paths) for item in results)
|
||||
conflict_count = sum(len(item.conflicts) for item in results)
|
||||
deleted_count = sum(1 for item in results if item.action == "deleted")
|
||||
@@ -565,6 +717,7 @@ async def login_page(request: Request):
|
||||
scheme=server_config.scheme,
|
||||
url=server_config.url,
|
||||
port=server_config.port,
|
||||
timeout=server_config.timeout,
|
||||
)
|
||||
music_libraries = plex_client.get_libs_name_list()
|
||||
if music_libraries:
|
||||
@@ -612,6 +765,7 @@ async def login(
|
||||
scheme=scheme,
|
||||
url=url,
|
||||
port=port,
|
||||
timeout=server_config.timeout,
|
||||
)
|
||||
# 成功连接后保存配置到配置文件
|
||||
music_libraries: list[str] = []
|
||||
@@ -632,12 +786,18 @@ async def login(
|
||||
scheme=scheme,
|
||||
url=url,
|
||||
port=port,
|
||||
timeout=server_config.timeout,
|
||||
library_name=selected_library,
|
||||
)
|
||||
else:
|
||||
music_libraries = []
|
||||
server_config.set_and_save_config(
|
||||
token=token_success, scheme=scheme, url=url, port=port, library_name=""
|
||||
token=token_success,
|
||||
scheme=scheme,
|
||||
url=url,
|
||||
port=port,
|
||||
timeout=server_config.timeout,
|
||||
library_name="",
|
||||
)
|
||||
return templates.TemplateResponse(
|
||||
"login.html",
|
||||
|
||||
@@ -0,0 +1,270 @@
|
||||
import os
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from app.utils.logger import logger
|
||||
from app.utils.config import server_config
|
||||
from app.utils.local_playlist import load_local_playlist
|
||||
from app.utils.plex_client import plex_client
|
||||
|
||||
# Default backup directory
|
||||
BACKUP_DIR = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "..", "backups")
|
||||
)
|
||||
|
||||
|
||||
def ensure_backup_dir():
|
||||
"""Ensure the backup directory exists."""
|
||||
if not os.path.exists(BACKUP_DIR):
|
||||
os.makedirs(BACKUP_DIR, exist_ok=True)
|
||||
logger.info(f"Created backup directory: {BACKUP_DIR}")
|
||||
|
||||
|
||||
def get_timestamp() -> str:
|
||||
"""Generate a timestamp string for backup filenames."""
|
||||
return datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
|
||||
def get_sorted_backup_files(prefix: str) -> List[str]:
|
||||
"""Get backup files sorted by modification time (oldest first).
|
||||
|
||||
Args:
|
||||
prefix: The prefix to filter backup files (e.g., 'local_backup_' or 'cloud_backup_')
|
||||
|
||||
Returns:
|
||||
List of backup file paths sorted by modification time (oldest first)
|
||||
"""
|
||||
ensure_backup_dir()
|
||||
backup_files = []
|
||||
for filename in os.listdir(BACKUP_DIR):
|
||||
if filename.startswith(prefix) and filename.endswith('.zip'):
|
||||
filepath = os.path.join(BACKUP_DIR, filename)
|
||||
backup_files.append(filepath)
|
||||
|
||||
# Sort by modification time (oldest first)
|
||||
backup_files.sort(key=lambda x: os.path.getmtime(x))
|
||||
return backup_files
|
||||
|
||||
|
||||
def cleanup_old_backups(prefix: str, retention_count: int):
|
||||
"""Delete old backup files exceeding the retention count.
|
||||
|
||||
Args:
|
||||
prefix: The prefix to filter backup files (e.g., 'local_backup_' or 'cloud_backup_')
|
||||
retention_count: Maximum number of backups to keep (0 means no auto-delete)
|
||||
"""
|
||||
if retention_count <= 0:
|
||||
logger.debug(f"Backup retention count is {retention_count}, skipping cleanup for {prefix}")
|
||||
return
|
||||
|
||||
backup_files = get_sorted_backup_files(prefix)
|
||||
|
||||
# Delete oldest files if we exceed retention count
|
||||
files_to_delete = len(backup_files) - retention_count
|
||||
if files_to_delete > 0:
|
||||
for filepath in backup_files[:files_to_delete]:
|
||||
try:
|
||||
os.remove(filepath)
|
||||
logger.info(f"Deleted old backup: {filepath}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to delete backup {filepath}: {e}")
|
||||
|
||||
|
||||
def backup_local_playlists(local_path: str) -> str | None:
|
||||
"""Create a backup of local playlists.
|
||||
|
||||
Reads all playlist files from the local path and writes them to a zip file
|
||||
without any modifications.
|
||||
|
||||
Args:
|
||||
local_path: Path to the local playlist directory
|
||||
|
||||
Returns:
|
||||
Path to the created backup file, or None if backup failed
|
||||
"""
|
||||
ensure_backup_dir()
|
||||
|
||||
if not local_path or not os.path.isdir(local_path):
|
||||
logger.warning(f"Local path does not exist or is not a directory: {local_path}")
|
||||
return None
|
||||
|
||||
timestamp = get_timestamp()
|
||||
backup_filename = f"local_backup_{timestamp}.zip"
|
||||
backup_path = os.path.join(BACKUP_DIR, backup_filename)
|
||||
|
||||
try:
|
||||
playlist_count = 0
|
||||
with zipfile.ZipFile(backup_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
for entry in os.scandir(local_path):
|
||||
if not entry.is_file():
|
||||
continue
|
||||
if not entry.name.lower().endswith((".m3u", ".m3u8")):
|
||||
continue
|
||||
|
||||
# Read the original file content
|
||||
try:
|
||||
with open(entry.path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
except UnicodeDecodeError:
|
||||
# Try with different encoding
|
||||
with open(entry.path, 'r', encoding='latin-1') as f:
|
||||
content = f.read()
|
||||
|
||||
# Get the playlist name without extension and add .m3u8 extension
|
||||
playlist_name = os.path.splitext(entry.name)[0]
|
||||
archive_name = f"{playlist_name}.m3u8"
|
||||
|
||||
# Write to zip
|
||||
zipf.writestr(archive_name, content)
|
||||
playlist_count += 1
|
||||
|
||||
if playlist_count == 0:
|
||||
# Remove empty zip file
|
||||
os.remove(backup_path)
|
||||
logger.info("No playlists found for local backup")
|
||||
return None
|
||||
|
||||
logger.info(f"Created local backup with {playlist_count} playlists: {backup_path}")
|
||||
return backup_path
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create local backup: {e}")
|
||||
# Clean up partial backup file if it exists
|
||||
if os.path.exists(backup_path):
|
||||
try:
|
||||
os.remove(backup_path)
|
||||
except OSError:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def backup_cloud_playlists(library_name: str) -> str | None:
|
||||
"""Create a backup of cloud playlists.
|
||||
|
||||
Fetches all playlists from the Plex server and writes them to a zip file
|
||||
without any modifications.
|
||||
|
||||
Args:
|
||||
library_name: Name of the Plex library to backup playlists from
|
||||
|
||||
Returns:
|
||||
Path to the created backup file, or None if backup failed
|
||||
"""
|
||||
ensure_backup_dir()
|
||||
|
||||
if not plex_client.connected:
|
||||
logger.warning("Plex client not connected, cannot backup cloud playlists")
|
||||
return None
|
||||
|
||||
if not library_name:
|
||||
logger.warning("No library name specified for cloud backup")
|
||||
return None
|
||||
|
||||
timestamp = get_timestamp()
|
||||
backup_filename = f"cloud_backup_{timestamp}.zip"
|
||||
backup_path = os.path.join(BACKUP_DIR, backup_filename)
|
||||
|
||||
try:
|
||||
playlists = plex_client.get_lib_playlists(library_name)
|
||||
if not playlists:
|
||||
logger.info("No playlists found for cloud backup")
|
||||
return None
|
||||
|
||||
playlist_count = 0
|
||||
with zipfile.ZipFile(backup_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
for playlist in playlists:
|
||||
try:
|
||||
# Get playlist items
|
||||
items = playlist.items()
|
||||
|
||||
# Build m3u8 content
|
||||
lines = ["#EXTM3U"]
|
||||
for item in items:
|
||||
# Try to get file path from the track
|
||||
try:
|
||||
if hasattr(item, 'media') and item.media:
|
||||
for media in item.media:
|
||||
if hasattr(media, 'parts') and media.parts:
|
||||
for part in media.parts:
|
||||
if hasattr(part, 'file') and part.file:
|
||||
# Add extended info if available
|
||||
duration = getattr(item, 'duration', 0) or 0
|
||||
duration_seconds = duration // 1000 if duration else -1
|
||||
title = getattr(item, 'title', 'Unknown')
|
||||
artist = ''
|
||||
if hasattr(item, 'grandparentTitle'):
|
||||
artist = item.grandparentTitle
|
||||
elif hasattr(item, 'artist'):
|
||||
artist_attr = getattr(item, 'artist')
|
||||
if callable(artist_attr):
|
||||
artist = str(artist_attr())
|
||||
else:
|
||||
artist = str(artist_attr)
|
||||
|
||||
extinf = f"#EXTINF:{duration_seconds},{artist} - {title}"
|
||||
lines.append(extinf)
|
||||
lines.append(part.file)
|
||||
break
|
||||
except Exception as e:
|
||||
logger.debug(f"Could not get file path for track: {e}")
|
||||
continue
|
||||
|
||||
if len(lines) > 1: # More than just #EXTM3U
|
||||
content = "\n".join(lines)
|
||||
archive_name = f"{playlist.title}.m3u8"
|
||||
zipf.writestr(archive_name, content)
|
||||
playlist_count += 1
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to backup playlist '{playlist.title}': {e}")
|
||||
continue
|
||||
|
||||
if playlist_count == 0:
|
||||
# Remove empty zip file
|
||||
os.remove(backup_path)
|
||||
logger.info("No playlists with valid tracks found for cloud backup")
|
||||
return None
|
||||
|
||||
logger.info(f"Created cloud backup with {playlist_count} playlists: {backup_path}")
|
||||
return backup_path
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to create cloud backup: {e}")
|
||||
# Clean up partial backup file if it exists
|
||||
if os.path.exists(backup_path):
|
||||
try:
|
||||
os.remove(backup_path)
|
||||
except OSError:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def perform_backup_before_sync(local_path: str, library_name: str):
|
||||
"""Perform backup of both local and cloud playlists before sync.
|
||||
|
||||
This function should be called before sync if backup is enabled.
|
||||
It also handles cleanup of old backups based on retention settings.
|
||||
|
||||
Args:
|
||||
local_path: Path to the local playlist directory
|
||||
library_name: Name of the Plex library
|
||||
"""
|
||||
server_config.load()
|
||||
|
||||
if not server_config.backup_enabled:
|
||||
logger.debug("Backup is disabled, skipping pre-sync backup")
|
||||
return
|
||||
|
||||
logger.info("Starting pre-sync backup...")
|
||||
|
||||
# Backup local playlists
|
||||
local_backup = backup_local_playlists(local_path)
|
||||
if local_backup:
|
||||
cleanup_old_backups("local_backup_", server_config.backup_retention_count)
|
||||
|
||||
# Backup cloud playlists
|
||||
cloud_backup = backup_cloud_playlists(library_name)
|
||||
if cloud_backup:
|
||||
cleanup_old_backups("cloud_backup_", server_config.backup_retention_count)
|
||||
|
||||
logger.info("Pre-sync backup completed")
|
||||
+111
-3
@@ -3,6 +3,16 @@ import os
|
||||
from app.utils.logger import logger
|
||||
|
||||
DEFAULT_SYNC_MODE = "merge_local_primary"
|
||||
DEFAULT_PATH_MAPPING = {
|
||||
"mode": "SIMPLE",
|
||||
"simple": [],
|
||||
"regex": {
|
||||
"local_pre": [],
|
||||
"local_post": [],
|
||||
"remote_pre": [],
|
||||
"remote_post": []
|
||||
}
|
||||
}
|
||||
|
||||
CONFIG_PATH = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "config.json")
|
||||
@@ -17,10 +27,20 @@ class ServerConfig:
|
||||
self.url = ""
|
||||
self.scheme = "https"
|
||||
self.port = "32400"
|
||||
self.timeout = 9
|
||||
self.library_name = ""
|
||||
self.sync_mode = DEFAULT_SYNC_MODE
|
||||
self.local_path = "playlist"
|
||||
self.path_rules: list[dict[str, str]] = []
|
||||
self.path_rules: list[dict[str, str]] = [] # Legacy field for backward compatibility
|
||||
self.path_mapping: dict = DEFAULT_PATH_MAPPING.copy()
|
||||
self.schedule_mode = "DISABLED"
|
||||
self.schedule_cron = ""
|
||||
self.schedule_daily_time = "02:00"
|
||||
self.schedule_weekly_days = [0]
|
||||
self.schedule_weekly_time = "03:00"
|
||||
self.schedule_auto_watch = False
|
||||
self.backup_enabled = False
|
||||
self.backup_retention_count = 5
|
||||
self.load()
|
||||
|
||||
def load(self) -> None:
|
||||
@@ -43,11 +63,38 @@ class ServerConfig:
|
||||
self.url = config.get("server_url", "")
|
||||
self.scheme = config.get("server_scheme", "https")
|
||||
self.port = config.get("server_port", "32400")
|
||||
self.timeout = config.get("timeout", 9)
|
||||
self.library_name = config.get("library_name", "")
|
||||
self.sync_mode = config.get("sync_mode", DEFAULT_SYNC_MODE)
|
||||
self.local_path = config.get("local_path", "playlist")
|
||||
self.path_rules = config.get("path_rules", []) or []
|
||||
logger.info(f"Server config loaded: {self.__dict__}")
|
||||
|
||||
# Load path_mapping with default fallback
|
||||
path_mapping_config = config.get("path_mapping")
|
||||
if path_mapping_config:
|
||||
self.path_mapping = {
|
||||
"mode": path_mapping_config.get("mode", "SIMPLE"),
|
||||
"simple": path_mapping_config.get("simple", []),
|
||||
"regex": {
|
||||
"local_pre": path_mapping_config.get("regex", {}).get("local_pre", []),
|
||||
"local_post": path_mapping_config.get("regex", {}).get("local_post", []),
|
||||
"remote_pre": path_mapping_config.get("regex", {}).get("remote_pre", []),
|
||||
"remote_post": path_mapping_config.get("regex", {}).get("remote_post", [])
|
||||
}
|
||||
}
|
||||
else:
|
||||
self.path_mapping = DEFAULT_PATH_MAPPING.copy()
|
||||
|
||||
self.schedule_mode = config.get("schedule_mode", "DISABLED")
|
||||
self.schedule_cron = config.get("schedule_cron", "")
|
||||
self.schedule_daily_time = config.get("schedule_daily_time", "02:00")
|
||||
self.schedule_weekly_days = config.get("schedule_weekly_days", [0])
|
||||
self.schedule_weekly_time = config.get("schedule_weekly_time", "03:00")
|
||||
self.schedule_auto_watch = config.get("schedule_auto_watch", False)
|
||||
self.backup_enabled = config.get("backup_enabled", False)
|
||||
self.backup_retention_count = config.get("backup_retention_count", 5)
|
||||
logger.info(f"Server config loaded.")
|
||||
logger.debug(f"Current server config: {self.__dict__}")
|
||||
|
||||
def save(self):
|
||||
config = {
|
||||
@@ -56,14 +103,25 @@ class ServerConfig:
|
||||
"server_url": self.url,
|
||||
"server_scheme": self.scheme,
|
||||
"server_port": self.port,
|
||||
"timeout": self.timeout,
|
||||
"library_name": self.library_name,
|
||||
"sync_mode": self.sync_mode,
|
||||
"local_path": self.local_path,
|
||||
"path_rules": self.path_rules,
|
||||
"path_mapping": self.path_mapping,
|
||||
"schedule_mode": self.schedule_mode,
|
||||
"schedule_cron": self.schedule_cron,
|
||||
"schedule_daily_time": self.schedule_daily_time,
|
||||
"schedule_weekly_days": self.schedule_weekly_days,
|
||||
"schedule_weekly_time": self.schedule_weekly_time,
|
||||
"schedule_auto_watch": self.schedule_auto_watch,
|
||||
"backup_enabled": self.backup_enabled,
|
||||
"backup_retention_count": self.backup_retention_count,
|
||||
}
|
||||
with open(CONFIG_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=4, ensure_ascii=False)
|
||||
logger.info(f"Server config saved: {config}")
|
||||
logger.info(f"Server config saved.")
|
||||
logger.debug(f"Saved server config: {config}")
|
||||
|
||||
def set_url(self, url: str) -> None:
|
||||
self.url = url
|
||||
@@ -74,6 +132,9 @@ class ServerConfig:
|
||||
def set_port(self, port: str) -> None:
|
||||
self.port = port
|
||||
|
||||
def set_timeout(self, timeout: int) -> None:
|
||||
self.timeout = timeout if timeout and timeout > 0 else 9
|
||||
|
||||
def set_token(self, token: str) -> None:
|
||||
self.token = token
|
||||
|
||||
@@ -96,6 +157,47 @@ class ServerConfig:
|
||||
def set_path_rules(self, path_rules: list[dict[str, str]]) -> None:
|
||||
self.path_rules = path_rules or []
|
||||
|
||||
def set_path_mapping(self, path_mapping: dict) -> None:
|
||||
if path_mapping:
|
||||
self.path_mapping = {
|
||||
"mode": path_mapping.get("mode", "SIMPLE"),
|
||||
"simple": path_mapping.get("simple", []),
|
||||
"regex": {
|
||||
"local_pre": path_mapping.get("regex", {}).get("local_pre", []),
|
||||
"local_post": path_mapping.get("regex", {}).get("local_post", []),
|
||||
"remote_pre": path_mapping.get("regex", {}).get("remote_pre", []),
|
||||
"remote_post": path_mapping.get("regex", {}).get("remote_post", [])
|
||||
}
|
||||
}
|
||||
else:
|
||||
self.path_mapping = DEFAULT_PATH_MAPPING.copy()
|
||||
|
||||
def set_schedule(
|
||||
self,
|
||||
mode: str,
|
||||
cron: str,
|
||||
daily_time: str,
|
||||
weekly_days: list[int],
|
||||
weekly_time: str,
|
||||
auto_watch: bool,
|
||||
) -> None:
|
||||
self.schedule_mode = mode
|
||||
self.schedule_cron = cron
|
||||
self.schedule_daily_time = daily_time
|
||||
self.schedule_weekly_days = weekly_days
|
||||
self.schedule_weekly_time = weekly_time
|
||||
self.schedule_auto_watch = auto_watch
|
||||
self.save()
|
||||
|
||||
def set_backup(
|
||||
self,
|
||||
enabled: bool,
|
||||
retention_count: int,
|
||||
) -> None:
|
||||
self.backup_enabled = enabled
|
||||
self.backup_retention_count = retention_count
|
||||
self.save()
|
||||
|
||||
def set_and_save_config(
|
||||
self,
|
||||
theme: str = None,
|
||||
@@ -103,10 +205,12 @@ class ServerConfig:
|
||||
url: str = None,
|
||||
scheme: str = None,
|
||||
port: str = None,
|
||||
timeout: int | None = None,
|
||||
library_name: str | None = None,
|
||||
sync_mode: str | None = None,
|
||||
local_path: str | None = None,
|
||||
path_rules: list[dict[str, str]] | None = None,
|
||||
path_mapping: dict | None = None,
|
||||
) -> None:
|
||||
if theme is not None:
|
||||
self.set_theme(theme)
|
||||
@@ -118,6 +222,8 @@ class ServerConfig:
|
||||
self.set_scheme(scheme)
|
||||
if port is not None:
|
||||
self.set_port(port)
|
||||
if timeout is not None:
|
||||
self.set_timeout(timeout)
|
||||
if library_name is not None:
|
||||
self.set_library(library_name)
|
||||
if sync_mode is not None:
|
||||
@@ -126,6 +232,8 @@ class ServerConfig:
|
||||
self.set_local_path(local_path)
|
||||
if path_rules is not None:
|
||||
self.set_path_rules(path_rules)
|
||||
if path_mapping is not None:
|
||||
self.set_path_mapping(path_mapping)
|
||||
self.save()
|
||||
|
||||
|
||||
|
||||
@@ -65,4 +65,48 @@ def scan_local_playlists(base_path: str) -> list[dict]:
|
||||
|
||||
playlists.sort(key=lambda item: item["name"].lower())
|
||||
logger.info(f"Found {len(playlists)} playlists under {absolute_path}.")
|
||||
return playlists
|
||||
return playlists
|
||||
def write_local_playlist(playlist_path: str, tracks: List[str]) -> bool:
|
||||
"""
|
||||
Write a list of tracks to a local playlist file.
|
||||
|
||||
Args:
|
||||
playlist_path (str): The path to the playlist file.
|
||||
tracks (list): A list of songs to write to the playlist.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, False otherwise.
|
||||
"""
|
||||
try:
|
||||
with open(playlist_path, 'w', encoding="utf-8") as file:
|
||||
file.write("#EXTM3U\n")
|
||||
for track in tracks:
|
||||
file.write(f"{track}\n")
|
||||
logger.info(f"Written {len(tracks)} songs to the playlist: {playlist_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while writing the playlist {playlist_path}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
def delete_local_playlist(playlist_path: str) -> bool:
|
||||
"""
|
||||
Delete a local playlist file.
|
||||
|
||||
Args:
|
||||
playlist_path (str): The path to the playlist file.
|
||||
|
||||
Returns:
|
||||
bool: True if successful, False otherwise.
|
||||
"""
|
||||
try:
|
||||
if os.path.exists(playlist_path):
|
||||
os.remove(playlist_path)
|
||||
logger.info(f"Deleted playlist: {playlist_path}")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Playlist not found for deletion: {playlist_path}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred while deleting the playlist {playlist_path}: {e}")
|
||||
return False
|
||||
|
||||
+23
-1
@@ -4,7 +4,29 @@ import os
|
||||
LOG_PATH = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), "..", "logs", "app.log"))
|
||||
|
||||
LOG_LEVEL = logging.DEBUG
|
||||
def _get_log_level():
|
||||
"""Get log level from environment variable."""
|
||||
level_str = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
|
||||
# Try to convert to integer
|
||||
if level_str.isdigit():
|
||||
return int(level_str)
|
||||
|
||||
# Map string to logging level
|
||||
levels = {
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
"FATAL": logging.FATAL,
|
||||
"ERROR": logging.ERROR,
|
||||
"WARN": logging.WARNING,
|
||||
"WARNING": logging.WARNING,
|
||||
"INFO": logging.INFO,
|
||||
"DEBUG": logging.DEBUG,
|
||||
"NOTSET": logging.NOTSET,
|
||||
}
|
||||
|
||||
return levels.get(level_str, logging.INFO)
|
||||
|
||||
LOG_LEVEL = _get_log_level()
|
||||
|
||||
def logger_initialize() -> logging.Logger:
|
||||
"""Initialize the logger for the application. Return a logger that logs to console and a app.log."""
|
||||
|
||||
+265
-20
@@ -40,6 +40,15 @@ class PlaylistSyncResult:
|
||||
output_dir: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class CompiledRegexRules:
|
||||
"""Holds compiled regex rules for all four processing stages."""
|
||||
local_pre: list[tuple[re.Pattern[str], str]]
|
||||
local_post: list[tuple[re.Pattern[str], str]]
|
||||
remote_pre: list[tuple[re.Pattern[str], str]]
|
||||
remote_post: list[tuple[re.Pattern[str], str]]
|
||||
|
||||
|
||||
def load_paths(text: str) -> list[str]:
|
||||
"""Normalize playlist text into a list of absolute paths.
|
||||
|
||||
@@ -72,12 +81,21 @@ def save_paths(paths: Sequence[str]) -> str:
|
||||
|
||||
|
||||
def _compile_regex_rules(rules: Sequence[dict[str, str]]) -> list[tuple[re.Pattern[str], str]]:
|
||||
"""Compile regex rules into pattern/replacement pairs.
|
||||
|
||||
Supports both legacy format (pattern/replacement) and new format (search/replace).
|
||||
"""
|
||||
compiled: list[tuple[re.Pattern[str], str]] = []
|
||||
for rule in rules:
|
||||
pattern = rule.get("pattern")
|
||||
# Support both legacy (pattern/replacement) and new (search/replace) field names
|
||||
# Use explicit None checks to allow empty strings as valid values
|
||||
pattern = rule.get("pattern") if rule.get("pattern") is not None else rule.get("search")
|
||||
if not pattern:
|
||||
continue
|
||||
replacement = rule.get("replacement", "")
|
||||
# For replacement, empty string is a valid value (for deletion)
|
||||
replacement = rule.get("replacement") if rule.get("replacement") is not None else rule.get("replace")
|
||||
if replacement is None:
|
||||
replacement = ""
|
||||
try:
|
||||
compiled.append((re.compile(pattern), replacement))
|
||||
except re.error as exc:
|
||||
@@ -159,8 +177,22 @@ def _read_text_if_exists(path: str) -> tuple[str, bool]:
|
||||
def _save_playlist_to_folder(filename: str, paths: Sequence[str], folder: str) -> str:
|
||||
_ensure_test_dir(folder)
|
||||
file_path = os.path.join(folder, filename)
|
||||
logger.info(f"Saving playlist to: {file_path}")
|
||||
|
||||
new_content = save_paths(paths)
|
||||
|
||||
# Check if content has changed before writing to avoid triggering unnecessary file events
|
||||
if os.path.exists(file_path):
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
current_content = f.read()
|
||||
if current_content == new_content:
|
||||
return file_path
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(save_paths(paths))
|
||||
file.write(new_content)
|
||||
return file_path
|
||||
|
||||
|
||||
@@ -220,9 +252,31 @@ def _merge_chunks(
|
||||
return chunks
|
||||
|
||||
|
||||
def _write_results(merged_lines: Sequence[str], folder: str) -> None:
|
||||
_save_playlist_to_folder("local_result.m3u8", merged_lines, folder)
|
||||
_save_playlist_to_folder("remote_result.m3u8", merged_lines, folder)
|
||||
def _write_results(
|
||||
merged_lines: Sequence[str],
|
||||
folder: str,
|
||||
compiled_rules: CompiledRegexRules | None = None
|
||||
) -> None:
|
||||
"""Write sync results to the test folder.
|
||||
|
||||
If compiled_rules is provided with post-processing rules:
|
||||
- local_result.m3u8: merged_lines processed with local_post rules
|
||||
- remote_result.m3u8: merged_lines processed with remote_post rules
|
||||
- base_next.m3u8: unprocessed merged_lines (normalized sync result)
|
||||
"""
|
||||
# Apply post-processing regex rules if provided
|
||||
if compiled_rules and compiled_rules.local_post:
|
||||
local_lines = _apply_compiled_rules_to_paths(merged_lines, compiled_rules.local_post)
|
||||
else:
|
||||
local_lines = list(merged_lines)
|
||||
|
||||
if compiled_rules and compiled_rules.remote_post:
|
||||
remote_lines = _apply_compiled_rules_to_paths(merged_lines, compiled_rules.remote_post)
|
||||
else:
|
||||
remote_lines = list(merged_lines)
|
||||
|
||||
_save_playlist_to_folder("local_result.m3u8", local_lines, folder)
|
||||
_save_playlist_to_folder("remote_result.m3u8", remote_lines, folder)
|
||||
_save_playlist_to_folder("base_next.m3u8", merged_lines, folder)
|
||||
|
||||
|
||||
@@ -365,12 +419,16 @@ def merge_playlists(
|
||||
remote_text: str,
|
||||
strategy: ConflictResolutionStrategy = ConflictResolutionStrategy.LOCAL_PRIORITY,
|
||||
test_folder: str = TEST_PLAYLIST_DIR,
|
||||
compiled_rules: CompiledRegexRules | None = None,
|
||||
) -> MergeResult:
|
||||
"""Merge playlists using diff3 and resolve conflicts per strategy.
|
||||
|
||||
The base, local, and remote normalized playlists are saved into ``test_folder``
|
||||
for inspection. The merged playlist is also stored twice to simulate the
|
||||
versions intended for local save and cloud upload.
|
||||
|
||||
If compiled_rules is provided, post-processing regex rules will be applied
|
||||
to the results before writing.
|
||||
"""
|
||||
|
||||
base_paths, local_paths, remote_paths = _normalize_inputs(
|
||||
@@ -406,7 +464,7 @@ def merge_playlists(
|
||||
merged_lines, base_paths, local_paths, remote_paths
|
||||
)
|
||||
|
||||
_write_results(merged_lines, test_folder)
|
||||
_write_results(merged_lines, test_folder, compiled_rules)
|
||||
|
||||
return MergeResult(merged_paths=merged_lines, conflicts=conflicts)
|
||||
|
||||
@@ -503,6 +561,7 @@ def _sync_single_playlist(
|
||||
remote_text: str,
|
||||
playlist_folder: str,
|
||||
remote_present: bool,
|
||||
compiled_rules: CompiledRegexRules | None = None,
|
||||
) -> PlaylistSyncResult:
|
||||
local_present = local_text is not None
|
||||
local_text = local_text or ""
|
||||
@@ -521,7 +580,7 @@ def _sync_single_playlist(
|
||||
base_text, local_text, remote_text, playlist_folder
|
||||
)
|
||||
merged_lines = list(local_paths)
|
||||
_write_results(merged_lines, playlist_folder)
|
||||
_write_results(merged_lines, playlist_folder, compiled_rules)
|
||||
return PlaylistSyncResult(playlist, merged_lines, [], "synced", playlist_folder)
|
||||
|
||||
if mode == SyncMode.REMOTE_FORCE:
|
||||
@@ -533,7 +592,7 @@ def _sync_single_playlist(
|
||||
base_text, local_text, remote_text, playlist_folder
|
||||
)
|
||||
merged_lines = list(remote_paths)
|
||||
_write_results(merged_lines, playlist_folder)
|
||||
_write_results(merged_lines, playlist_folder, compiled_rules)
|
||||
return PlaylistSyncResult(playlist, merged_lines, [], "synced", playlist_folder)
|
||||
|
||||
if mode not in (SyncMode.MERGE_LOCAL_PRIMARY, SyncMode.MERGE_REMOTE_PRIMARY):
|
||||
@@ -551,6 +610,7 @@ def _sync_single_playlist(
|
||||
remote_text=remote_text,
|
||||
strategy=merge_strategy,
|
||||
test_folder=playlist_folder,
|
||||
compiled_rules=compiled_rules,
|
||||
)
|
||||
|
||||
if not merge_result.merged_paths and (not local_present or not remote_present):
|
||||
@@ -564,14 +624,179 @@ def _sync_single_playlist(
|
||||
)
|
||||
|
||||
|
||||
def _compile_path_mapping_rules(path_mapping: dict) -> CompiledRegexRules:
|
||||
"""Compile regex rules from path_mapping config for all four processing stages."""
|
||||
regex_config = path_mapping.get("regex", {})
|
||||
return CompiledRegexRules(
|
||||
local_pre=_compile_regex_rules(regex_config.get("local_pre", [])),
|
||||
local_post=_compile_regex_rules(regex_config.get("local_post", [])),
|
||||
remote_pre=_compile_regex_rules(regex_config.get("remote_pre", [])),
|
||||
remote_post=_compile_regex_rules(regex_config.get("remote_post", [])),
|
||||
)
|
||||
|
||||
|
||||
def _compile_simple_mapping_rules(simple_mappings: list[dict]) -> CompiledRegexRules:
|
||||
"""Compile simple mapping pairs into four rule groups using UUID-based mapping_ids.
|
||||
|
||||
Each simple mapping has:
|
||||
- id: UUID used as the mapping_id (unique identifier to prevent conflicts)
|
||||
- search: Local path prefix
|
||||
- replace: Cloud path prefix
|
||||
|
||||
This generates four rule sets:
|
||||
- local_pre: Replace local path (search) with mapping_id
|
||||
- remote_pre: Replace cloud path (replace) with mapping_id
|
||||
- local_post: Replace mapping_id with local path (search)
|
||||
- remote_post: Replace mapping_id with cloud path (replace)
|
||||
|
||||
The mapping_id is wrapped with special markers to prevent conflicts with actual paths.
|
||||
"""
|
||||
local_pre_rules: list[dict[str, str]] = []
|
||||
local_post_rules: list[dict[str, str]] = []
|
||||
remote_pre_rules: list[dict[str, str]] = []
|
||||
remote_post_rules: list[dict[str, str]] = []
|
||||
|
||||
# UUID pattern for validation (accepts standard UUID format with or without hyphens)
|
||||
uuid_pattern = re.compile(r'^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{4}-?[a-fA-F0-9]{12}$')
|
||||
|
||||
for mapping in simple_mappings:
|
||||
# Get the mapping values
|
||||
mapping_id = mapping.get("id")
|
||||
local_path = mapping.get("search", "") # Local path is stored in 'search' field
|
||||
cloud_path = mapping.get("replace", "") # Cloud path is stored in 'replace' field
|
||||
|
||||
# Validate mapping_id is a proper UUID to prevent injection attacks
|
||||
if not mapping_id or not isinstance(mapping_id, str):
|
||||
logger.warning(f"Skipping mapping with missing or invalid id: {mapping}")
|
||||
continue
|
||||
|
||||
if not uuid_pattern.match(mapping_id):
|
||||
logger.warning(f"Skipping mapping with non-UUID id format: {mapping_id}")
|
||||
continue
|
||||
|
||||
# Paths must be non-empty strings
|
||||
if not local_path or not isinstance(local_path, str):
|
||||
logger.warning(f"Skipping mapping with missing local path: {mapping}")
|
||||
continue
|
||||
|
||||
if not cloud_path or not isinstance(cloud_path, str):
|
||||
logger.warning(f"Skipping mapping with missing cloud path: {mapping}")
|
||||
continue
|
||||
|
||||
# Normalize Windows paths: Replace double backslashes with single backslashes
|
||||
# This handles cases where users enter escaped paths like \\Koha9-Main\\Music
|
||||
# when the actual playlist content uses \Koha9-Main\Music
|
||||
original_local = local_path
|
||||
original_cloud = cloud_path
|
||||
local_path = local_path.replace("\\\\", "\\")
|
||||
cloud_path = cloud_path.replace("\\\\", "\\")
|
||||
|
||||
if local_path != original_local or cloud_path != original_cloud:
|
||||
logger.info(f"Normalized Windows paths:")
|
||||
logger.info(f" Local: {repr(original_local)} -> {repr(local_path)}")
|
||||
logger.info(f" Cloud: {repr(original_cloud)} -> {repr(cloud_path)}")
|
||||
|
||||
# Create a unique placeholder using the validated UUID
|
||||
# Using special markers to prevent conflicts with actual paths
|
||||
placeholder = f"__MAPPING__{mapping_id}__"
|
||||
|
||||
# Debug logging for path mapping
|
||||
logger.debug(f"Simple mapping pair:")
|
||||
logger.debug(f" Local path (search): {repr(local_path)}")
|
||||
logger.debug(f" Cloud path (replace): {repr(cloud_path)}")
|
||||
logger.debug(f" Placeholder: {placeholder}")
|
||||
|
||||
# Pre-processing rules (use re.escape to treat paths as literal strings)
|
||||
# local_pre: Replace local path with placeholder
|
||||
local_pattern = re.escape(local_path)
|
||||
logger.debug(f" Local pre pattern: {repr(local_pattern)}")
|
||||
local_pre_rules.append({
|
||||
"pattern": local_pattern,
|
||||
"replacement": placeholder
|
||||
})
|
||||
|
||||
# remote_pre: Replace cloud path with placeholder
|
||||
remote_pattern = re.escape(cloud_path)
|
||||
logger.debug(f" Remote pre pattern: {repr(remote_pattern)}")
|
||||
remote_pre_rules.append({
|
||||
"pattern": remote_pattern,
|
||||
"replacement": placeholder
|
||||
})
|
||||
|
||||
# Post-processing rules
|
||||
# local_post: Replace placeholder with local path
|
||||
# Note: In regex replacement, backslashes need to be escaped
|
||||
local_post_rules.append({
|
||||
"pattern": re.escape(placeholder),
|
||||
"replacement": local_path.replace("\\", "\\\\")
|
||||
})
|
||||
|
||||
# remote_post: Replace placeholder with cloud path
|
||||
remote_post_rules.append({
|
||||
"pattern": re.escape(placeholder),
|
||||
"replacement": cloud_path.replace("\\", "\\\\")
|
||||
})
|
||||
|
||||
logger.info(f"Compiled {len(local_pre_rules)} simple mapping pairs into rules")
|
||||
|
||||
return CompiledRegexRules(
|
||||
local_pre=_compile_regex_rules(local_pre_rules),
|
||||
local_post=_compile_regex_rules(local_post_rules),
|
||||
remote_pre=_compile_regex_rules(remote_pre_rules),
|
||||
remote_post=_compile_regex_rules(remote_post_rules),
|
||||
)
|
||||
|
||||
|
||||
def sync_all_playlists(
|
||||
local_dir: str, mode: SyncMode, test_folder: str = TEST_PLAYLIST_DIR
|
||||
) -> list[PlaylistSyncResult]:
|
||||
"""Synchronize all playlists that can be matched by name."""
|
||||
"""Synchronize all playlists that can be matched by name.
|
||||
|
||||
Path mapping modes:
|
||||
- SIMPLE: Uses UUID-based mapping_ids to convert between local and cloud paths
|
||||
- local_pre: local_path -> mapping_id
|
||||
- remote_pre: cloud_path -> mapping_id
|
||||
- local_post: mapping_id -> local_path
|
||||
- remote_post: mapping_id -> cloud_path
|
||||
|
||||
- REGEX: Uses custom regex rules for each processing stage
|
||||
- local_pre, local_post, remote_pre, remote_post rules are applied directly
|
||||
|
||||
Processing flow:
|
||||
1. local_pre rules are applied to local playlists before sync
|
||||
2. remote_pre rules are applied to remote playlists before sync
|
||||
3. Sync/merge is performed
|
||||
4. local_post rules are applied to results before writing to local_result.m3u8
|
||||
5. remote_post rules are applied to results before writing to remote_result.m3u8
|
||||
"""
|
||||
|
||||
server_config.load()
|
||||
compiled_rules = _compile_regex_rules(server_config.path_rules)
|
||||
|
||||
# Get path_mapping configuration
|
||||
path_mapping = server_config.path_mapping
|
||||
mapping_mode = path_mapping.get("mode", "SIMPLE")
|
||||
|
||||
# Compile rules based on the mode
|
||||
compiled_rules: CompiledRegexRules | None = None
|
||||
legacy_compiled_rules: list[tuple[re.Pattern[str], str]] = []
|
||||
|
||||
if mapping_mode == "REGEX":
|
||||
compiled_rules = _compile_path_mapping_rules(path_mapping)
|
||||
logger.info("Using REGEX mode for path mapping with 4 rule groups")
|
||||
elif mapping_mode == "SIMPLE":
|
||||
simple_mappings = path_mapping.get("simple", [])
|
||||
if simple_mappings:
|
||||
compiled_rules = _compile_simple_mapping_rules(simple_mappings)
|
||||
logger.info(f"Using SIMPLE mode for path mapping with {len(simple_mappings)} mapping pairs")
|
||||
else:
|
||||
logger.info("SIMPLE mode with no mappings - no path transformations will be applied")
|
||||
else:
|
||||
# Use legacy path_rules for backward compatibility
|
||||
legacy_compiled_rules = _compile_regex_rules(server_config.path_rules)
|
||||
logger.info("Using legacy path_rules for preprocessing")
|
||||
|
||||
_ensure_test_dir(test_folder)
|
||||
logger.info(f"Syncing playlists to test folder: {test_folder}")
|
||||
local_playlists = _load_local_playlists(local_dir)
|
||||
remote_playlists = _fetch_remote_playlists()
|
||||
playlist_names: set[str] = set(local_playlists.keys())
|
||||
@@ -598,16 +823,35 @@ def sync_all_playlists(
|
||||
remote_text = snapshot_remote_text
|
||||
remote_present = bool(remote_text.strip()) or remote_exists
|
||||
|
||||
base_text = preprocess_playlist_text(
|
||||
base_text, server_config.path_rules, compiled_rules
|
||||
)
|
||||
remote_text = preprocess_playlist_text(
|
||||
remote_text, server_config.path_rules, compiled_rules
|
||||
)
|
||||
if local_text is not None:
|
||||
local_text = preprocess_playlist_text(
|
||||
local_text, server_config.path_rules, compiled_rules
|
||||
if compiled_rules:
|
||||
# Apply pre-processing rules for REGEX or SIMPLE mode
|
||||
# base_text doesn't need pre-processing as it's the normalized state
|
||||
if local_text is not None and compiled_rules.local_pre:
|
||||
logger.debug(f"Applying local_pre rules to playlist: {playlist}")
|
||||
logger.debug(f" Before preprocessing (first 200 chars): {repr(local_text[:200])}")
|
||||
local_text = preprocess_playlist_text(
|
||||
local_text, [], compiled_rules.local_pre
|
||||
)
|
||||
logger.debug(f" After preprocessing (first 200 chars): {repr(local_text[:200])}")
|
||||
if remote_text and compiled_rules.remote_pre:
|
||||
logger.debug(f"Applying remote_pre rules to playlist: {playlist}")
|
||||
logger.debug(f" Before preprocessing (first 200 chars): {repr(remote_text[:200])}")
|
||||
remote_text = preprocess_playlist_text(
|
||||
remote_text, [], compiled_rules.remote_pre
|
||||
)
|
||||
logger.debug(f" After preprocessing (first 200 chars): {repr(remote_text[:200])}")
|
||||
elif legacy_compiled_rules:
|
||||
# Use legacy preprocessing for all texts
|
||||
base_text = preprocess_playlist_text(
|
||||
base_text, server_config.path_rules, legacy_compiled_rules
|
||||
)
|
||||
remote_text = preprocess_playlist_text(
|
||||
remote_text, server_config.path_rules, legacy_compiled_rules
|
||||
)
|
||||
if local_text is not None:
|
||||
local_text = preprocess_playlist_text(
|
||||
local_text, server_config.path_rules, legacy_compiled_rules
|
||||
)
|
||||
|
||||
# Treat missing remote text as absent playlist.
|
||||
result = _sync_single_playlist(
|
||||
@@ -618,6 +862,7 @@ def sync_all_playlists(
|
||||
remote_text=remote_text,
|
||||
playlist_folder=playlist_folder,
|
||||
remote_present=remote_present,
|
||||
compiled_rules=compiled_rules,
|
||||
)
|
||||
results.append(result)
|
||||
|
||||
|
||||
+109
-7
@@ -50,6 +50,7 @@ class PlexClient:
|
||||
scheme: str = "https",
|
||||
url: str = "",
|
||||
port: str = "32400",
|
||||
timeout: int | None = None,
|
||||
) -> tuple[PlexServer, str]:
|
||||
"""Connect to the Plex server using username/password or token.
|
||||
|
||||
@@ -69,11 +70,11 @@ class PlexClient:
|
||||
try:
|
||||
if not str_is_empty(token):
|
||||
self.server, self.token = self._connect_with_token(
|
||||
token, scheme, url, port
|
||||
token, scheme, url, port, timeout
|
||||
)
|
||||
else:
|
||||
self.server, self.token = self._connect_with_pw(
|
||||
username, password, scheme, url, port
|
||||
username, password, scheme, url, port, timeout
|
||||
)
|
||||
# Update the base URL and connection status
|
||||
self.base_url = build_plex_url(scheme, url, port)
|
||||
@@ -88,30 +89,41 @@ class PlexClient:
|
||||
raise
|
||||
|
||||
def _connect_with_pw(
|
||||
self, username: str, password: str, scheme: str, url: str, port: str = "32400"
|
||||
self,
|
||||
username: str,
|
||||
password: str,
|
||||
scheme: str,
|
||||
url: str,
|
||||
port: str = "32400",
|
||||
timeout: int | None = None,
|
||||
):
|
||||
"""Return a connected PlexServer instance and update config with token and server info."""
|
||||
# url 初始化
|
||||
self.base_url = build_plex_url(scheme, url, port)
|
||||
# account 初始化
|
||||
account = MyPlexAccount(username, password)
|
||||
account = MyPlexAccount(username, password, timeout=timeout)
|
||||
# token 获取
|
||||
self.token = account.authenticationToken
|
||||
|
||||
self.server = PlexServer(self.base_url, self.token)
|
||||
self.server = PlexServer(self.base_url, self.token, timeout=timeout)
|
||||
logger.debug(
|
||||
f"Connected to Plex server with username: {username}, token: {self.token}"
|
||||
)
|
||||
return self.server, self.token
|
||||
|
||||
def _connect_with_token(
|
||||
self, token: str, scheme: str, url: str, port: str = "32400"
|
||||
self,
|
||||
token: str,
|
||||
scheme: str,
|
||||
url: str,
|
||||
port: str = "32400",
|
||||
timeout: int | None = None,
|
||||
):
|
||||
"""Return a connected PlexServer instance using a token."""
|
||||
# URL 初始化
|
||||
self.base_url = build_plex_url(scheme, url, port)
|
||||
|
||||
self.server = PlexServer(self.base_url, token)
|
||||
self.server = PlexServer(self.base_url, token, timeout=timeout)
|
||||
logger.debug(f"Connected to Plex server with token: {token}")
|
||||
return self.server, token
|
||||
|
||||
@@ -299,4 +311,94 @@ class PlexClient:
|
||||
)
|
||||
return local_2_plex
|
||||
|
||||
def get_playlist(self, title: str):
|
||||
"""Get a playlist by title."""
|
||||
self._connect_check()
|
||||
try:
|
||||
# Exact match search for playlist
|
||||
playlists = self.server.playlists(title=title)
|
||||
if playlists:
|
||||
return playlists[0]
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.error(f"Error fetching playlist {title}: {e}")
|
||||
return None
|
||||
|
||||
def create_playlist(self, title: str, items: list):
|
||||
"""Create a new playlist with the given items."""
|
||||
self._connect_check()
|
||||
try:
|
||||
self.server.createPlaylist(title, items=items)
|
||||
logger.info(f"Created playlist {title} with {len(items)} items.")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating playlist {title}: {e}")
|
||||
return False
|
||||
|
||||
def delete_playlist(self, title: str):
|
||||
"""Delete a playlist by title."""
|
||||
self._connect_check()
|
||||
try:
|
||||
playlist = self.get_playlist(title)
|
||||
if playlist:
|
||||
playlist.delete()
|
||||
logger.info(f"Deleted playlist {title}.")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Playlist {title} not found for deletion.")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Error deleting playlist {title}: {e}")
|
||||
return False
|
||||
|
||||
def update_playlist(self, title: str, items: list):
|
||||
"""
|
||||
Update a playlist with a new list of items.
|
||||
This implementation replaces the existing items with the new ones.
|
||||
"""
|
||||
self._connect_check()
|
||||
try:
|
||||
playlist = self.get_playlist(title)
|
||||
if not playlist:
|
||||
return self.create_playlist(title, items)
|
||||
|
||||
# Remove all items and add new ones
|
||||
playlist.removeItems(playlist.items())
|
||||
if items:
|
||||
playlist.addItems(items)
|
||||
logger.info(f"Updated playlist {title} with {len(items)} items.")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating playlist {title}: {e}")
|
||||
return False
|
||||
|
||||
def get_items_by_paths(self, library_name: str, paths: list[str]) -> list:
|
||||
"""
|
||||
Find Plex items (tracks) by their file paths.
|
||||
"""
|
||||
self._connect_check()
|
||||
if not paths:
|
||||
return []
|
||||
|
||||
try:
|
||||
path_map = self.match_tracks(library_name, paths)
|
||||
except FileNotFoundError:
|
||||
logger.info(f"Cache not found for {library_name}, creating it...")
|
||||
self.cache_lib_tracks(library_name)
|
||||
path_map = self.match_tracks(library_name, paths)
|
||||
|
||||
items = []
|
||||
for path in paths:
|
||||
rating_key = path_map.get(path)
|
||||
if rating_key and rating_key != UNMATCHED_TRACK_RATING_KEY:
|
||||
try:
|
||||
item = self.server.fetchItem(rating_key)
|
||||
items.append(item)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to fetch item for ratingKey {rating_key}: {e}")
|
||||
else:
|
||||
logger.warning(f"Track not found in Plex library (or unmatched): {path}")
|
||||
|
||||
return items
|
||||
|
||||
plex_client = PlexClient()
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
from typing import Optional
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
from apscheduler.triggers.base import BaseTrigger
|
||||
from app.utils.config import server_config
|
||||
from app.utils.logger import logger
|
||||
from app.utils.watcher import watcher_manager
|
||||
from app.utils.sync_manager import sync_manager
|
||||
import os
|
||||
|
||||
# Initialize the scheduler
|
||||
scheduler = BackgroundScheduler()
|
||||
|
||||
def validate_cron_expression(expression: str) -> bool:
|
||||
"""
|
||||
Validates a cron expression.
|
||||
Expected format: "minute hour day month day_of_week"
|
||||
"""
|
||||
try:
|
||||
parts = expression.split()
|
||||
if len(parts) != 5:
|
||||
return False
|
||||
# Try to create a trigger to validate
|
||||
CronTrigger(
|
||||
minute=parts[0],
|
||||
hour=parts[1],
|
||||
day=parts[2],
|
||||
month=parts[3],
|
||||
day_of_week=parts[4]
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def job_function():
|
||||
"""
|
||||
The function to be executed by the scheduler.
|
||||
Triggers the sync process.
|
||||
"""
|
||||
logger.info("Executing scheduled sync job...")
|
||||
try:
|
||||
sync_manager.run_sync(trigger_source="scheduler", wait=False)
|
||||
except Exception as e:
|
||||
logger.error(f"Error during scheduled sync job: {e}", exc_info=True)
|
||||
|
||||
def start_scheduler():
|
||||
"""
|
||||
Starts the background scheduler if it's not already running.
|
||||
"""
|
||||
if not scheduler.running:
|
||||
scheduler.start()
|
||||
logger.info("Scheduler started.")
|
||||
update_scheduler_job()
|
||||
|
||||
def _create_cron_trigger(cron_exp: str) -> Optional[CronTrigger]:
|
||||
"""Helper to create a CronTrigger from a cron expression string."""
|
||||
try:
|
||||
# 5 parts: minute hour day month day_of_week
|
||||
parts = cron_exp.split()
|
||||
if len(parts) == 5:
|
||||
return CronTrigger(
|
||||
minute=parts[0],
|
||||
hour=parts[1],
|
||||
day=parts[2],
|
||||
month=parts[3],
|
||||
day_of_week=parts[4]
|
||||
)
|
||||
else:
|
||||
logger.error(f"Invalid cron expression format (needs 5 parts): {cron_exp}")
|
||||
except Exception as e:
|
||||
logger.error(f"Invalid cron expression: {cron_exp}, error: {e}")
|
||||
return None
|
||||
|
||||
def _create_daily_trigger(time_str: str) -> Optional[CronTrigger]:
|
||||
"""Helper to create a CronTrigger for daily execution at a specific time."""
|
||||
try:
|
||||
hour, minute = map(int, time_str.split(':'))
|
||||
return CronTrigger(hour=hour, minute=minute)
|
||||
except ValueError:
|
||||
logger.error(f"Invalid daily time format: {time_str}")
|
||||
return None
|
||||
|
||||
def _create_weekly_trigger(days: list[int], time_str: str) -> Optional[CronTrigger]:
|
||||
"""
|
||||
Helper to create a CronTrigger for weekly execution.
|
||||
days: List of integers 0-6 where 0 is Sunday, 1 is Monday, ..., 6 is Saturday.
|
||||
APScheduler expects: 0 = Monday, ..., 6 = Sunday.
|
||||
"""
|
||||
# Convert Frontend days (0=Sun...6=Sat) to APScheduler days (0=Mon...6=Sun)
|
||||
aps_days = []
|
||||
for d in days:
|
||||
if d == 0:
|
||||
aps_days.append(6) # Sunday
|
||||
else:
|
||||
aps_days.append(d - 1) # Mon(1)->0, ..., Sat(6)->5
|
||||
|
||||
days_str = ",".join(map(str, aps_days))
|
||||
|
||||
try:
|
||||
hour, minute = map(int, time_str.split(':'))
|
||||
return CronTrigger(day_of_week=days_str, hour=hour, minute=minute)
|
||||
except ValueError:
|
||||
logger.error(f"Invalid weekly time format: {time_str}")
|
||||
return None
|
||||
|
||||
def update_scheduler_job():
|
||||
"""
|
||||
Updates the scheduler jobs based on the current configuration.
|
||||
Reloads configuration, handles auto-watch, and sets up the sync job trigger.
|
||||
"""
|
||||
scheduler.remove_all_jobs()
|
||||
|
||||
# Reload config to get latest schedule settings
|
||||
server_config.load()
|
||||
logger.info("Configuration reloaded for scheduler update.")
|
||||
|
||||
# Handle Auto Watch
|
||||
if server_config.schedule_auto_watch:
|
||||
# Ensure we have an absolute path
|
||||
local_path = os.path.abspath(server_config.local_path)
|
||||
watcher_manager.start(local_path)
|
||||
logger.info(f"Auto-watch started for path: {local_path}")
|
||||
else:
|
||||
watcher_manager.stop()
|
||||
logger.info("Auto-watch stopped.")
|
||||
|
||||
mode = server_config.schedule_mode
|
||||
logger.info(f"Updating scheduler with mode: {mode}")
|
||||
|
||||
if mode == "DISABLED":
|
||||
logger.info("Schedule is disabled. No jobs added.")
|
||||
return
|
||||
|
||||
trigger: Optional[BaseTrigger] = None
|
||||
|
||||
if mode == "CRON":
|
||||
trigger = _create_cron_trigger(server_config.schedule_cron)
|
||||
|
||||
elif mode == "DAILY":
|
||||
trigger = _create_daily_trigger(server_config.schedule_daily_time)
|
||||
|
||||
elif mode == "WEEKLY":
|
||||
trigger = _create_weekly_trigger(server_config.schedule_weekly_days, server_config.schedule_weekly_time)
|
||||
|
||||
if trigger:
|
||||
scheduler.add_job(job_function, trigger, misfire_grace_time=60, coalesce=True)
|
||||
logger.info(f"Added scheduled job with mode '{mode}' and trigger: {trigger}")
|
||||
else:
|
||||
logger.warning(f"Failed to create trigger for mode '{mode}'. No job added.")
|
||||
|
||||
def get_next_run_time():
|
||||
"""
|
||||
Returns the next run time of the scheduled job, if any.
|
||||
"""
|
||||
jobs = scheduler.get_jobs()
|
||||
if not jobs:
|
||||
return None
|
||||
# Assuming only one job is scheduled for sync
|
||||
job = jobs[0]
|
||||
return job.next_run_time
|
||||
@@ -0,0 +1,178 @@
|
||||
import threading
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from app.utils.logger import logger
|
||||
from app.utils.playlist_merge import sync_all_playlists, SyncMode
|
||||
from app.utils.config import server_config
|
||||
from app.utils.backup import perform_backup_before_sync
|
||||
from app.utils.local_playlist import load_local_playlist, write_local_playlist, delete_local_playlist
|
||||
from app.utils.plex_client import plex_client
|
||||
|
||||
class SyncManager:
|
||||
def __init__(self):
|
||||
self._lock = threading.Lock()
|
||||
self._is_syncing = False
|
||||
self._last_sync_time = None
|
||||
self._last_status = "idle" # idle, syncing, success, error
|
||||
self._last_error = None
|
||||
self._listeners = [] # List of asyncio.Queue
|
||||
self._loop = None
|
||||
|
||||
def set_event_loop(self, loop):
|
||||
self._loop = loop
|
||||
|
||||
async def subscribe(self):
|
||||
q = asyncio.Queue()
|
||||
self._listeners.append(q)
|
||||
# Send current status immediately
|
||||
await q.put(json.dumps(self.status))
|
||||
return q
|
||||
|
||||
def unsubscribe(self, q):
|
||||
if q in self._listeners:
|
||||
self._listeners.remove(q)
|
||||
|
||||
def _notify_listeners(self):
|
||||
if not self._loop or not self._listeners:
|
||||
return
|
||||
|
||||
status_json = json.dumps(self.status)
|
||||
|
||||
for q in self._listeners:
|
||||
try:
|
||||
self._loop.call_soon_threadsafe(q.put_nowait, status_json)
|
||||
except Exception as e:
|
||||
logger.error(f"Error notifying listener: {e}")
|
||||
|
||||
@property
|
||||
def is_syncing(self):
|
||||
with self._lock:
|
||||
return self._is_syncing
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
with self._lock:
|
||||
return {
|
||||
"is_syncing": self._is_syncing,
|
||||
"last_sync_time": self._last_sync_time.isoformat() if self._last_sync_time else None,
|
||||
"status": self._last_status,
|
||||
"error": str(self._last_error) if self._last_error else None
|
||||
}
|
||||
|
||||
def run_sync(self, trigger_source="manual", wait=False, sync_kwargs=None):
|
||||
"""
|
||||
Thread-safe sync execution.
|
||||
If wait=True, blocks until sync completes and returns result.
|
||||
If wait=False, runs in background and returns True if started.
|
||||
"""
|
||||
with self._lock:
|
||||
if self._is_syncing:
|
||||
logger.warning(f"Sync requested ({trigger_source}) but already in progress.")
|
||||
if wait:
|
||||
raise Exception("Sync already in progress")
|
||||
return False
|
||||
self._is_syncing = True
|
||||
self._last_status = "syncing"
|
||||
self._last_error = None
|
||||
|
||||
self._notify_listeners()
|
||||
logger.info(f"Starting sync (Source: {trigger_source})...")
|
||||
|
||||
if wait:
|
||||
try:
|
||||
result = self._perform_sync(sync_kwargs)
|
||||
self._complete_sync("success")
|
||||
return result
|
||||
except Exception as e:
|
||||
self._complete_sync("error", e)
|
||||
raise e
|
||||
else:
|
||||
thread = threading.Thread(target=self._sync_worker, args=(trigger_source, sync_kwargs))
|
||||
thread.start()
|
||||
return True
|
||||
|
||||
def _sync_worker(self, trigger_source, sync_kwargs=None):
|
||||
try:
|
||||
self._perform_sync(sync_kwargs)
|
||||
self._complete_sync("success")
|
||||
logger.info(f"Sync completed successfully (Source: {trigger_source}).")
|
||||
except Exception as e:
|
||||
logger.error(f"Sync failed (Source: {trigger_source}): {e}")
|
||||
self._complete_sync("error", e)
|
||||
|
||||
def _perform_sync(self, sync_kwargs=None):
|
||||
# Reload config to ensure latest values
|
||||
server_config.load()
|
||||
|
||||
kwargs = {
|
||||
"local_dir": server_config.local_path,
|
||||
"mode": SyncMode(server_config.sync_mode)
|
||||
}
|
||||
|
||||
if sync_kwargs:
|
||||
kwargs.update(sync_kwargs)
|
||||
|
||||
# Perform backup before sync if enabled
|
||||
local_dir = kwargs.get("local_dir", server_config.local_path)
|
||||
perform_backup_before_sync(local_dir, server_config.library_name)
|
||||
|
||||
# Execute sync
|
||||
results = sync_all_playlists(**kwargs)
|
||||
|
||||
# Apply results (write to local and remote)
|
||||
self._apply_sync_results(results)
|
||||
|
||||
return results
|
||||
|
||||
def _apply_sync_results(self, results):
|
||||
logger.info("Applying sync results to local and remote...")
|
||||
for result in results:
|
||||
playlist_name = result.name
|
||||
action = result.action
|
||||
output_dir = result.output_dir
|
||||
|
||||
try:
|
||||
if action == "synced":
|
||||
# 1. Write Local
|
||||
local_result_path = os.path.join(output_dir, "local_result.m3u8")
|
||||
if os.path.exists(local_result_path):
|
||||
tracks = load_local_playlist(local_result_path)
|
||||
dest_path = os.path.join(server_config.local_path, f"{playlist_name}.m3u8")
|
||||
# Ensure directory exists
|
||||
os.makedirs(os.path.dirname(dest_path), exist_ok=True)
|
||||
write_local_playlist(dest_path, tracks)
|
||||
|
||||
# 2. Write Remote (Plex)
|
||||
remote_result_path = os.path.join(output_dir, "remote_result.m3u8")
|
||||
if os.path.exists(remote_result_path):
|
||||
tracks = load_local_playlist(remote_result_path)
|
||||
if server_config.library_name:
|
||||
items = plex_client.get_items_by_paths(server_config.library_name, tracks)
|
||||
plex_client.update_playlist(playlist_name, items)
|
||||
else:
|
||||
logger.warning("Library name not configured, skipping Plex update.")
|
||||
|
||||
elif action == "deleted":
|
||||
# Delete Local
|
||||
dest_path = os.path.join(server_config.local_path, f"{playlist_name}.m3u8")
|
||||
delete_local_playlist(dest_path)
|
||||
# Also check for .m3u
|
||||
dest_path_m3u = os.path.join(server_config.local_path, f"{playlist_name}.m3u")
|
||||
delete_local_playlist(dest_path_m3u)
|
||||
|
||||
# Delete Remote
|
||||
plex_client.delete_playlist(playlist_name)
|
||||
except Exception as e:
|
||||
logger.error(f"Error applying sync result for playlist {playlist_name}: {e}")
|
||||
|
||||
def _complete_sync(self, status, error=None):
|
||||
with self._lock:
|
||||
self._last_status = status
|
||||
self._last_error = error
|
||||
self._last_sync_time = datetime.now()
|
||||
self._is_syncing = False
|
||||
self._notify_listeners()
|
||||
|
||||
sync_manager = SyncManager()
|
||||
@@ -0,0 +1,115 @@
|
||||
import os
|
||||
import threading
|
||||
from typing import Optional
|
||||
from watchdog.observers.polling import PollingObserver as Observer
|
||||
from watchdog.events import FileSystemEventHandler, FileSystemEvent
|
||||
from app.utils.logger import logger
|
||||
from app.utils.sync_manager import sync_manager
|
||||
|
||||
class PlaylistEventHandler(FileSystemEventHandler):
|
||||
"""
|
||||
Handles file system events for the playlist directory.
|
||||
Triggers a sync operation when changes are detected, with debouncing.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.debounce_timer: Optional[threading.Timer] = None
|
||||
self.debounce_interval = 5.0 # Seconds
|
||||
|
||||
def on_any_event(self, event: FileSystemEvent):
|
||||
# Log all events at DEBUG level to avoid cluttering INFO logs
|
||||
logger.debug(f"[Watcher] Event detected: {event.event_type} {event.src_path}")
|
||||
|
||||
if event.is_directory:
|
||||
return
|
||||
|
||||
# Filter out noisy events. Only listen to actual changes.
|
||||
# 'opened' and 'closed' (without write) are read events and should be ignored.
|
||||
if event.event_type not in ['created', 'modified', 'deleted', 'moved']:
|
||||
return
|
||||
|
||||
# Ignore temporary files or hidden files
|
||||
filename = os.path.basename(event.src_path)
|
||||
if filename.startswith('.'):
|
||||
return
|
||||
|
||||
# Prevent feedback loops: if sync is in progress, ignore events
|
||||
if sync_manager.is_syncing:
|
||||
logger.debug(f"[Watcher] Ignoring event {event.event_type} on {event.src_path} because sync is in progress.")
|
||||
return
|
||||
|
||||
logger.info(f"[Watcher] Accepted file change: {event.event_type} {event.src_path}")
|
||||
self.trigger_sync()
|
||||
|
||||
def trigger_sync(self):
|
||||
"""
|
||||
Triggers the sync process after a debounce interval.
|
||||
"""
|
||||
if self.debounce_timer:
|
||||
self.debounce_timer.cancel()
|
||||
|
||||
logger.debug(f"[Watcher] Debouncing sync for {self.debounce_interval} seconds...")
|
||||
self.debounce_timer = threading.Timer(self.debounce_interval, self.run_sync)
|
||||
self.debounce_timer.start()
|
||||
|
||||
def run_sync(self):
|
||||
"""
|
||||
Executes the sync via SyncManager.
|
||||
"""
|
||||
logger.info("[Watcher] Debounce timer expired. Triggering sync due to file changes.")
|
||||
try:
|
||||
sync_manager.run_sync(trigger_source="watcher", wait=False)
|
||||
except Exception as e:
|
||||
logger.error(f"[Watcher] Failed to trigger sync: {e}", exc_info=True)
|
||||
|
||||
class WatcherManager:
|
||||
"""
|
||||
Manages the lifecycle of the file watcher.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.observer: Optional[Observer] = None
|
||||
self.handler: Optional[PlaylistEventHandler] = None
|
||||
self.current_path: Optional[str] = None
|
||||
|
||||
def start(self, path: str):
|
||||
"""
|
||||
Starts watching the specified directory.
|
||||
"""
|
||||
# If already watching the same path, do nothing
|
||||
if self.observer and self.observer.is_alive() and self.current_path == path:
|
||||
logger.info(f"[Watcher] Already running on {path}")
|
||||
return
|
||||
|
||||
self.stop()
|
||||
|
||||
if not os.path.exists(path):
|
||||
logger.warning(f"[Watcher] Cannot watch path {path}: Directory does not exist.")
|
||||
return
|
||||
|
||||
logger.info(f"[Watcher] Starting file watcher on: {path}")
|
||||
try:
|
||||
files = os.listdir(path)
|
||||
logger.debug(f"[Watcher] Initial files in watch directory: {files}")
|
||||
except Exception as e:
|
||||
logger.error(f"[Watcher] Failed to list files in watch directory: {e}")
|
||||
|
||||
self.handler = PlaylistEventHandler()
|
||||
# Explicitly set timeout for PollingObserver
|
||||
self.observer = Observer(timeout=1.0)
|
||||
self.observer.schedule(self.handler, path, recursive=True)
|
||||
self.observer.start()
|
||||
self.current_path = path
|
||||
logger.info("[Watcher] Watcher started successfully.")
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
Stops the file watcher.
|
||||
"""
|
||||
if self.observer:
|
||||
logger.info("[Watcher] Stopping file watcher...")
|
||||
self.observer.stop()
|
||||
self.observer.join()
|
||||
self.observer = None
|
||||
self.current_path = None
|
||||
logger.info("[Watcher] Watcher stopped.")
|
||||
|
||||
watcher_manager = WatcherManager()
|
||||
+4
-1
@@ -5,8 +5,11 @@ services:
|
||||
ports:
|
||||
- "8888:8080"
|
||||
volumes:
|
||||
- path_to_your_playlist:/app/playlist
|
||||
- PATH_TO_YOUR_PLAYLISTS:/app/playlists
|
||||
- PATH_TO_YOUR_BACKUP:/app/backup
|
||||
environment:
|
||||
- PYTHONUNBUFFERED=1
|
||||
- PYTHONDONTWRITEBYTECODE=1
|
||||
- LOG_LEVEL=INFO
|
||||
- TZ=${TZ:-Asia/Tokyo}
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
# Configure timezone inside the container if TZ is provided.
|
||||
# This avoids relying on host mounts like /etc/localtime, which are awkward on Windows.
|
||||
if [ "${TZ:-}" != "" ]; then
|
||||
ZONEINFO="/usr/share/zoneinfo/${TZ}"
|
||||
if [ -e "$ZONEINFO" ]; then
|
||||
ln -snf "$ZONEINFO" /etc/localtime
|
||||
echo "$TZ" > /etc/timezone
|
||||
else
|
||||
echo "[entrypoint] Warning: TZ='$TZ' not found at $ZONEINFO; keeping existing timezone." >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -0,0 +1,6 @@
|
||||
Write-Output "Starting PlexPlaylistSync Docker Container..."
|
||||
Set-Location ./frontend
|
||||
npm run build
|
||||
Set-Location ..
|
||||
docker compose down
|
||||
docker compose up --build
|
||||
+380
-45
@@ -1,8 +1,7 @@
|
||||
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { Playlist, ServerType, SyncStrategy, PlexServerConnection, RegexReplacement, PlexConnectionSettings, SyncState } from './types';
|
||||
import { Playlist, ServerType, SyncStrategy, PlexServerConnection, PathMappingConfig, PathMappingMode, PlexConnectionSettings, SyncState, ScheduleSettings, ScheduleMode, BackupSettings } from './types';
|
||||
import { apiService } from './services/api';
|
||||
import {
|
||||
import {
|
||||
STRIPE_BASE_SPEED,
|
||||
STRIPE_DECEL_DURATION_MS,
|
||||
STRIPE_TILE_SIZE,
|
||||
@@ -10,15 +9,15 @@ import {
|
||||
SYNC_SUCCESS_TOTAL_MS,
|
||||
SYNC_ERROR_RESET_MS,
|
||||
TOAST_AUTO_DISMISS_MS,
|
||||
TOAST_EXIT_DURATION_MS,
|
||||
SYNC_BANNER_PADDING_X,
|
||||
SYNC_BANNER_PADDING_Y,
|
||||
SYNC_BANNER_MIN_WIDTH,
|
||||
TOAST_EXIT_DURATION_MS
|
||||
} from './Config';
|
||||
import { SYNC_BANNER_PADDING_X, SYNC_BANNER_PADDING_Y, SYNC_BANNER_MIN_WIDTH } from './Config';
|
||||
import ServerPanel from './components/ServerPanel';
|
||||
import StrategySelector from './components/StrategySelector';
|
||||
import ConnectionModal from './components/ConnectionModal';
|
||||
import { ArrowLeftRight, ShieldCheck, X, Server, ServerOff } from 'lucide-react';
|
||||
import OverflowMarquee from './components/OverflowMarquee';
|
||||
import { ArrowLeftRight, ShieldCheck, X, Server, ServerOff, Clock, Eye, EyeOff, Type, Code2, Archive, Languages } from 'lucide-react';
|
||||
import { useLanguage } from './LanguageContext';
|
||||
|
||||
interface Toast {
|
||||
id: number;
|
||||
@@ -115,6 +114,7 @@ const useStripeAnimation = (syncState: SyncState) => {
|
||||
};
|
||||
|
||||
const App: React.FC = () => {
|
||||
const { t, language, setLanguage } = useLanguage();
|
||||
const [localPlaylists, setLocalPlaylists] = useState<Playlist[]>([]);
|
||||
const [cloudPlaylists, setCloudPlaylists] = useState<Playlist[]>([]);
|
||||
const [cloudServerInfo, setCloudServerInfo] = useState<PlexServerConnection | undefined>(undefined);
|
||||
@@ -125,6 +125,8 @@ const App: React.FC = () => {
|
||||
const [loadingCloud, setLoadingCloud] = useState(false);
|
||||
|
||||
const [syncState, setSyncState] = useState<SyncState>(SyncState.IDLE);
|
||||
const manualSyncInProgress = useRef(false);
|
||||
const lastKnownSyncTimeRef = useRef<string | null | undefined>(undefined);
|
||||
|
||||
// Animation Refs
|
||||
const { leftYellowRef, leftGreenRef, rightYellowRef, rightGreenRef } = useStripeAnimation(syncState);
|
||||
@@ -135,12 +137,39 @@ const App: React.FC = () => {
|
||||
|
||||
// Connection Modal State
|
||||
const [isConnectionModalOpen, setIsConnectionModalOpen] = useState(false);
|
||||
const [isLangMenuOpen, setIsLangMenuOpen] = useState(false);
|
||||
|
||||
// Strategy State
|
||||
const [currentStrategy, setCurrentStrategy] = useState<SyncStrategy>(SyncStrategy.LOCAL_OVERWRITE);
|
||||
|
||||
// Regex State
|
||||
const [regexReplacements, setRegexReplacements] = useState<RegexReplacement[]>([]);
|
||||
// Path Mapping State (Includes Simple and Regex Rules)
|
||||
const [pathMappingConfig, setPathMappingConfig] = useState<PathMappingConfig>({
|
||||
mode: PathMappingMode.SIMPLE,
|
||||
simple: [],
|
||||
regex: {
|
||||
localPre: [],
|
||||
localPost: [],
|
||||
remotePre: [],
|
||||
remotePost: []
|
||||
}
|
||||
});
|
||||
|
||||
// Schedule State
|
||||
const [scheduleSettings, setScheduleSettings] = useState<ScheduleSettings>({
|
||||
mode: ScheduleMode.DISABLED,
|
||||
cronExpression: '',
|
||||
dailyTime: '02:00',
|
||||
weeklyDays: [0], // Sunday
|
||||
weeklyTime: '03:00',
|
||||
autoWatch: false
|
||||
});
|
||||
const [nextRunTime, setNextRunTime] = useState<string | undefined>(undefined);
|
||||
|
||||
// Backup State
|
||||
const [backupSettings, setBackupSettings] = useState<BackupSettings>({
|
||||
enabled: false,
|
||||
retentionCount: 5
|
||||
});
|
||||
|
||||
// Toast Notification System
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
@@ -154,7 +183,7 @@ const App: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const addToast = (message: string) => {
|
||||
const addToast = useCallback((message: string) => {
|
||||
const id = Date.now();
|
||||
// Start with entering: true to position it above
|
||||
const newToast: Toast = { id, message, exiting: false, entering: true };
|
||||
@@ -171,7 +200,7 @@ const App: React.FC = () => {
|
||||
}, TOAST_AUTO_DISMISS_MS);
|
||||
|
||||
timeoutsRef.current[id] = dismissTimer;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Effect to trigger the "slide down" animation
|
||||
useEffect(() => {
|
||||
@@ -213,12 +242,61 @@ const App: React.FC = () => {
|
||||
const result = await apiService.getSettings();
|
||||
if (result.status === 'success') {
|
||||
setCurrentStrategy(result.data.strategy);
|
||||
setRegexReplacements(result.data.regex);
|
||||
setPathMappingConfig(result.data.pathMapping);
|
||||
setLocalPath(result.data.localPath || 'playlist');
|
||||
setConnectionSettings(result.data.connection);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const loadSchedule = useCallback(async () => {
|
||||
const result = await apiService.getScheduleSettings();
|
||||
if (result.status === 'success') {
|
||||
setScheduleSettings(result.data);
|
||||
setNextRunTime(result.data.nextRun);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const loadBackupSettings = useCallback(async () => {
|
||||
const result = await apiService.getBackupSettings();
|
||||
if (result.status === 'success') {
|
||||
setBackupSettings(result.data);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Handle Schedule Save
|
||||
const handleSaveSchedule = async (settings: ScheduleSettings): Promise<boolean> => {
|
||||
const result = await apiService.saveScheduleSettings(settings);
|
||||
|
||||
if (result.status === 'success') {
|
||||
setScheduleSettings(settings);
|
||||
// Refresh schedule info to get next run time
|
||||
loadSchedule();
|
||||
|
||||
if (settings.mode === ScheduleMode.DISABLED) {
|
||||
addToast(t('toasts.scheduleDisabled'));
|
||||
} else if (settings.mode === ScheduleMode.CRON && settings.cronExpression.trim() === '') {
|
||||
addToast(t('toasts.scheduleEmpty'));
|
||||
} else {
|
||||
addToast(t('toasts.scheduleStarted'));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
addToast(result.message || t('toasts.scheduleFailed'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Handle Backup Settings Save
|
||||
const handleSaveBackupSettings = async (settings: BackupSettings) => {
|
||||
const result = await apiService.saveBackupSettings(settings);
|
||||
if (result.status === 'success') {
|
||||
setBackupSettings(settings);
|
||||
addToast(t('toasts.backupSaved'));
|
||||
} else {
|
||||
addToast(result.message || t('toasts.backupFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
// Fetch Local Playlists
|
||||
const refreshLocal = useCallback(async () => {
|
||||
if (localAbortRef.current) localAbortRef.current.abort();
|
||||
@@ -239,7 +317,7 @@ const App: React.FC = () => {
|
||||
localAbortRef.current.abort();
|
||||
localAbortRef.current = null;
|
||||
setLoadingLocal(false);
|
||||
addToast("Local refresh cancelled.");
|
||||
addToast(t('toasts.localRefreshCancelled'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -273,14 +351,16 @@ const App: React.FC = () => {
|
||||
cloudAbortRef.current.abort();
|
||||
cloudAbortRef.current = null;
|
||||
setLoadingCloud(false);
|
||||
addToast("Cloud refresh cancelled.");
|
||||
addToast(t('toasts.cloudRefreshCancelled'));
|
||||
}
|
||||
};
|
||||
|
||||
// Load persisted configuration
|
||||
useEffect(() => {
|
||||
loadSettings();
|
||||
}, [loadSettings]);
|
||||
loadSchedule();
|
||||
loadBackupSettings();
|
||||
}, [loadSettings, loadSchedule, loadBackupSettings]);
|
||||
|
||||
// Initial Load
|
||||
useEffect(() => {
|
||||
@@ -298,20 +378,20 @@ const App: React.FC = () => {
|
||||
setCurrentStrategy(strategy);
|
||||
const result = await apiService.updateSyncStrategy(strategy);
|
||||
if (result.status === 'success') {
|
||||
addToast(`Selected strategy "${label}" has been saved.`);
|
||||
addToast(t('toasts.strategySaved', { strategy: label }));
|
||||
} else {
|
||||
addToast(result.message || 'Failed to save sync strategy.');
|
||||
addToast(result.message || t('toasts.strategySaveFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
// Handle Regex Save
|
||||
const handleSaveRegex = async (replacements: RegexReplacement[]) => {
|
||||
setRegexReplacements(replacements);
|
||||
const result = await apiService.saveRegexRules(replacements);
|
||||
// Handle Path Mapping Save
|
||||
const handleSavePathMapping = async (config: PathMappingConfig) => {
|
||||
setPathMappingConfig(config);
|
||||
const result = await apiService.savePathMapping(config);
|
||||
if (result.status === 'success') {
|
||||
addToast('Regex preprocessing rules have been saved.');
|
||||
addToast(t('toasts.mappingSaved'));
|
||||
} else {
|
||||
addToast(result.message || 'Failed to save regex rules.');
|
||||
addToast(result.message || t('toasts.mappingSaveFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -320,8 +400,11 @@ const App: React.FC = () => {
|
||||
if (syncState !== SyncState.IDLE) return;
|
||||
|
||||
setSyncState(SyncState.SYNCING);
|
||||
manualSyncInProgress.current = true;
|
||||
|
||||
const result = await apiService.syncPlaylists(currentStrategy, regexReplacements, localPath || undefined);
|
||||
const result = await apiService.syncPlaylists(currentStrategy, pathMappingConfig, localPath || undefined);
|
||||
|
||||
manualSyncInProgress.current = false;
|
||||
|
||||
if (result.status === 'success') {
|
||||
setSyncState(SyncState.SUCCESS);
|
||||
@@ -333,17 +416,90 @@ const App: React.FC = () => {
|
||||
}, SYNC_SUCCESS_TOTAL_MS);
|
||||
} else {
|
||||
setSyncState(SyncState.ERROR);
|
||||
addToast(result.message || 'Sync failed. Please check connection.');
|
||||
addToast(result.message || t('toasts.syncFailed'));
|
||||
setTimeout(() => setSyncState(SyncState.IDLE), SYNC_ERROR_RESET_MS);
|
||||
}
|
||||
};
|
||||
|
||||
// SSE for sync status
|
||||
useEffect(() => {
|
||||
const eventSource = new EventSource(`${import.meta.env.VITE_API_BASE_URL || ''}/api/sync/events`);
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
try {
|
||||
const data = JSON.parse(event.data);
|
||||
const { is_syncing, status, error, last_sync_time } = data;
|
||||
|
||||
// Initialize lastKnownSyncTime if it's the first event
|
||||
if (lastKnownSyncTimeRef.current === undefined) {
|
||||
lastKnownSyncTimeRef.current = last_sync_time;
|
||||
// If we are currently syncing on load, show it
|
||||
if (is_syncing && !manualSyncInProgress.current) {
|
||||
setSyncState(SyncState.SYNCING);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If manual sync is in progress, we ignore background updates to avoid state conflict
|
||||
if (manualSyncInProgress.current) {
|
||||
if (last_sync_time !== lastKnownSyncTimeRef.current) {
|
||||
lastKnownSyncTimeRef.current = last_sync_time;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle Syncing State
|
||||
if (is_syncing) {
|
||||
if (syncState !== SyncState.SYNCING) {
|
||||
setSyncState(SyncState.SYNCING);
|
||||
}
|
||||
} else {
|
||||
// Check for completion by comparing timestamps
|
||||
if (last_sync_time !== lastKnownSyncTimeRef.current) {
|
||||
lastKnownSyncTimeRef.current = last_sync_time;
|
||||
|
||||
// A sync has completed since our last check
|
||||
if (status === 'success') {
|
||||
setSyncState(SyncState.SUCCESS);
|
||||
refreshLocal();
|
||||
refreshCloud();
|
||||
addToast(t('toasts.backgroundSyncSuccess'));
|
||||
setTimeout(() => setSyncState(SyncState.IDLE), SYNC_SUCCESS_TOTAL_MS);
|
||||
} else if (status === 'error') {
|
||||
setSyncState(SyncState.ERROR);
|
||||
addToast(t('toasts.backgroundSyncFailed', { error: error || '' }));
|
||||
setTimeout(() => setSyncState(SyncState.IDLE), SYNC_ERROR_RESET_MS);
|
||||
}
|
||||
} else {
|
||||
// Edge case: We are in SYNCING state but backend says not syncing, and time hasn't changed.
|
||||
if (syncState === SyncState.SYNCING) {
|
||||
setSyncState(SyncState.IDLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to parse SSE event", e);
|
||||
}
|
||||
};
|
||||
|
||||
eventSource.onerror = (err) => {
|
||||
console.error("EventSource failed:", err);
|
||||
eventSource.close();
|
||||
};
|
||||
|
||||
return () => {
|
||||
eventSource.close();
|
||||
};
|
||||
}, [syncState, refreshLocal, refreshCloud, addToast]);
|
||||
|
||||
const handleConnectSuccess = async (serverInfo: PlexServerConnection) => {
|
||||
setCloudServerInfo(serverInfo);
|
||||
if (serverInfo.libraryName) {
|
||||
await apiService.updateLibrary(serverInfo.libraryName);
|
||||
setConnectionSettings(prev => prev ? { ...prev, libraryName: serverInfo.libraryName } : prev);
|
||||
}
|
||||
// Reload settings to ensure we have the latest connection details (protocol, etc.)
|
||||
await loadSettings();
|
||||
|
||||
// Refresh playlists after new connection
|
||||
refreshCloud();
|
||||
};
|
||||
@@ -367,6 +523,87 @@ const App: React.FC = () => {
|
||||
|
||||
const isConnected = cloudServerInfo?.isConnected;
|
||||
|
||||
const getScheduleDisplayInfo = () => {
|
||||
const result = {
|
||||
label: t('dashboard.autoSync'),
|
||||
value: t('schedule.notConfigured'),
|
||||
active: false,
|
||||
autoWatch: scheduleSettings.autoWatch,
|
||||
};
|
||||
|
||||
if (scheduleSettings.mode === ScheduleMode.DISABLED) {
|
||||
result.value = t('common.disabled');
|
||||
return result;
|
||||
}
|
||||
|
||||
if (scheduleSettings.mode === ScheduleMode.CRON && scheduleSettings.cronExpression.trim() === '') {
|
||||
result.value = t('dashboard.notSet');
|
||||
} else {
|
||||
result.value = nextRunTime ? `${nextRunTime}` : t('common.loading');
|
||||
}
|
||||
|
||||
result.active = true;
|
||||
return result;
|
||||
};
|
||||
|
||||
const scheduleInfo = getScheduleDisplayInfo();
|
||||
|
||||
// Helper: Calculate Path Mapping Info
|
||||
const getPathMappingDisplayInfo = (config: PathMappingConfig) => {
|
||||
let count = 0;
|
||||
let Icon = Type;
|
||||
|
||||
if (config.mode === PathMappingMode.SIMPLE) {
|
||||
count = config.simple.length;
|
||||
Icon = Type;
|
||||
} else {
|
||||
count =
|
||||
config.regex.localPre.length +
|
||||
config.regex.localPost.length +
|
||||
config.regex.remotePre.length +
|
||||
config.regex.remotePost.length;
|
||||
Icon = Code2;
|
||||
}
|
||||
|
||||
if (count === 0) {
|
||||
return {
|
||||
label: t('dashboard.mapping'),
|
||||
value: t('dashboard.notSet'),
|
||||
active: false,
|
||||
Icon,
|
||||
};
|
||||
}
|
||||
|
||||
const modeLabel = config.mode === PathMappingMode.SIMPLE ? t('mapping.simple') : t('mapping.regex');
|
||||
|
||||
return {
|
||||
label: t('dashboard.mapping'),
|
||||
value: `${modeLabel} (${count})`,
|
||||
active: true,
|
||||
Icon,
|
||||
};
|
||||
};
|
||||
|
||||
const pathMappingInfo = getPathMappingDisplayInfo(pathMappingConfig);
|
||||
|
||||
// Helper: Calculate Backup Info
|
||||
const getBackupDisplayInfo = (settings: BackupSettings) => {
|
||||
if (!settings.enabled) {
|
||||
return {
|
||||
label: t('dashboard.backup'),
|
||||
value: t('common.disabled'),
|
||||
active: false,
|
||||
};
|
||||
}
|
||||
return {
|
||||
label: t('dashboard.backup'),
|
||||
value: t('dashboard.keep', { count: settings.retentionCount }),
|
||||
active: true,
|
||||
};
|
||||
};
|
||||
|
||||
const backupInfo = getBackupDisplayInfo(backupSettings);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-gray-900 text-gray-100 font-sans overflow-hidden bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-gray-800 via-gray-900 to-black">
|
||||
|
||||
@@ -428,7 +665,7 @@ const App: React.FC = () => {
|
||||
|
||||
{syncState === SyncState.IDLE ? (
|
||||
<>
|
||||
{/* Normal Toolbar */}
|
||||
{/* Normal Toolbar Left */}
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="p-1.5 rounded-lg shadow-lg bg-gradient-to-br from-plex-orange to-yellow-600 text-gray-900 shadow-plex-orange/20">
|
||||
<ArrowLeftRight size={24} strokeWidth={2.5} />
|
||||
@@ -437,21 +674,115 @@ const App: React.FC = () => {
|
||||
Plex<span className="text-plex-orange">Sync</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Normal Toolbar Right */}
|
||||
<div className="flex items-center gap-4">
|
||||
|
||||
{/* Unified Status Dock */}
|
||||
<div className="hidden md:flex items-center bg-gray-900/40 border border-gray-700/50 rounded-lg p-1 mr-2 backdrop-blur-sm shadow-sm transition-all hover:bg-gray-900/60 hover:border-gray-600/50">
|
||||
|
||||
{/* Path Mapping Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 border-r border-gray-700/30 w-[120px] group/item">
|
||||
<span className={`text-[9px] font-bold uppercase tracking-widest transition-colors ${pathMappingInfo.active ? 'text-plex-orange' : 'text-gray-500 group-hover/item:text-gray-400'}`}>{pathMappingInfo.label}</span>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium ${pathMappingInfo.active ? 'text-blue-400' : 'text-gray-600'}`}>
|
||||
<pathMappingInfo.Icon size={12} strokeWidth={2.5} className="flex-shrink-0" />
|
||||
<OverflowMarquee>
|
||||
{pathMappingInfo.active ? pathMappingInfo.value : t('common.none')}
|
||||
</OverflowMarquee>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Connection Status Button */}
|
||||
<button
|
||||
onClick={() => setIsConnectionModalOpen(true)}
|
||||
className={`flex items-center justify-center w-9 h-9 rounded-full border transition-all duration-300 hover:scale-105 active:scale-95 shadow-md ${
|
||||
isConnected
|
||||
? "bg-green-500/10 border-green-500/50 text-green-400 hover:bg-green-500/20 hover:shadow-green-500/20"
|
||||
: "bg-red-500/10 border-red-500/50 text-red-400 hover:bg-red-500/20 hover:shadow-red-500/20"
|
||||
}`}
|
||||
title={isConnected ? "Connected to Plex" : "Disconnected"}
|
||||
>
|
||||
{isConnected ? <Server size={18} /> : <ServerOff size={18} />}
|
||||
</button>
|
||||
{/* Backup Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 border-r border-gray-700/30 w-[100px] group/item">
|
||||
<span className={`text-[9px] font-bold uppercase tracking-widest transition-colors ${backupInfo.active ? 'text-plex-orange' : 'text-gray-500 group-hover/item:text-gray-400'}`}>{backupInfo.label}</span>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium ${backupInfo.active ? 'text-indigo-400' : 'text-gray-600'}`}>
|
||||
<Archive size={12} strokeWidth={2.5} className="flex-shrink-0" />
|
||||
<OverflowMarquee>
|
||||
{backupInfo.active ? t('dashboard.retain', { count: backupSettings.retentionCount }) : backupInfo.value}
|
||||
</OverflowMarquee>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Schedule Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 w-[180px] group/item">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className={`text-[9px] font-bold uppercase tracking-widest transition-colors ${scheduleInfo.active ? 'text-plex-orange' : 'text-gray-500 group-hover/item:text-gray-400'}`}>{scheduleInfo.label}</span>
|
||||
{/* Watch Indicator Badge */}
|
||||
<div
|
||||
className={`flex items-center gap-1 px-1 rounded-[2px] transition-colors ${scheduleInfo.autoWatch ? 'text-plex-orange bg-plex-orange/10' : 'text-gray-700 bg-gray-800'}`}
|
||||
title={scheduleInfo.autoWatch ? t('dashboard.watchModeActive') : t('dashboard.watchModeDisabled')}
|
||||
>
|
||||
{scheduleInfo.autoWatch ? <Eye size={9} /> : <EyeOff size={9} />}
|
||||
<span className="text-[8px] font-bold uppercase">{t('dashboard.watch')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium mt-0.5 ${scheduleInfo.active ? 'text-green-400' : 'text-gray-600'}`}>
|
||||
<Clock size={12} strokeWidth={2.5} className="flex-shrink-0" />
|
||||
<OverflowMarquee>
|
||||
{scheduleInfo.active ? scheduleInfo.value : t('common.disabled')}
|
||||
</OverflowMarquee>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Language Switcher */}
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setIsLangMenuOpen(!isLangMenuOpen)}
|
||||
className="flex items-center justify-center w-9 h-9 rounded-full border border-gray-700 bg-gray-800/50 text-gray-400 hover:text-white hover:bg-gray-700 transition-all"
|
||||
title={t('common.switchLanguage')}
|
||||
>
|
||||
<Languages size={18} />
|
||||
</button>
|
||||
{isLangMenuOpen && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setIsLangMenuOpen(false)}></div>
|
||||
<div className="absolute right-0 top-full mt-2 w-32 bg-gray-800 border border-gray-700 rounded-lg shadow-xl z-50 overflow-hidden">
|
||||
<button
|
||||
onClick={() => { setLanguage('en'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'en' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
English
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setLanguage('es'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'es' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
Español
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setLanguage('chs'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'chs' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
简体中文
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setLanguage('cht'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'cht' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
繁體中文
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Connection Status Button */}
|
||||
<button
|
||||
onClick={() => setIsConnectionModalOpen(true)}
|
||||
className={`flex items-center justify-center w-9 h-9 rounded-full border transition-all duration-300 hover:scale-105 active:scale-95 shadow-md
|
||||
${isConnected
|
||||
? "bg-green-500/10 border-green-500/50 text-green-400 hover:bg-green-500/20 hover:shadow-green-500/20"
|
||||
: "bg-red-500/10 border-red-500/50 text-red-400 hover:bg-red-500/20 hover:shadow-red-500/20"
|
||||
}`}
|
||||
title={isConnected ? t('dashboard.connected') : t('dashboard.disconnected')}
|
||||
>
|
||||
{isConnected ? <Server size={18} /> : <ServerOff size={18} />}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
/* Syncing / Success Text Banner */
|
||||
<div className="absolute inset-0 flex items-center justify-center pointer-events-none z-10">
|
||||
<div
|
||||
className="bg-black shadow-none rounded-none border-none"
|
||||
@@ -461,7 +792,7 @@ const App: React.FC = () => {
|
||||
}}
|
||||
>
|
||||
<h1 className={`text-xl md:text-2xl font-black tracking-[0.2em] uppercase whitespace-nowrap transition-colors duration-300 ${syncState === SyncState.SUCCESS ? 'text-[#22c55e]' : 'text-[#F59E0B]'}`}>
|
||||
{syncState === SyncState.SYNCING ? 'SYNCHRONIZING' : 'SYNC COMPLETE'}
|
||||
{syncState === SyncState.SYNCING ? t('dashboard.synchronizing') : t('dashboard.syncComplete')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
@@ -515,11 +846,15 @@ const App: React.FC = () => {
|
||||
/* Desktop Positioning: Center Horizontally, Anchored Top */
|
||||
md:top-[64px] md:right-auto md:left-1/2 md:transform md:-translate-x-1/2 md:-translate-y-1/2"
|
||||
>
|
||||
<StrategySelector
|
||||
<StrategySelector
|
||||
currentStrategy={currentStrategy}
|
||||
onSelect={handleStrategyChange}
|
||||
savedRegexReplacements={regexReplacements}
|
||||
onSaveRegex={handleSaveRegex}
|
||||
savedPathMapping={pathMappingConfig}
|
||||
onSavePathMapping={handleSavePathMapping}
|
||||
savedBackup={backupSettings}
|
||||
onSaveBackup={handleSaveBackupSettings}
|
||||
savedSchedule={scheduleSettings}
|
||||
onSaveSchedule={handleSaveSchedule}
|
||||
syncState={syncState}
|
||||
onSync={handleSyncTrigger}
|
||||
/>
|
||||
@@ -542,7 +877,7 @@ const App: React.FC = () => {
|
||||
|
||||
{/* Footer */}
|
||||
<footer className="flex-none py-4 text-center text-xs text-gray-600 border-t border-white/5 bg-gray-900/50 backdrop-blur">
|
||||
<p>© {new Date().getFullYear()} PlexSync Manager. Connected to Docker backend.</p>
|
||||
<p>{t('app.footer', { year: new Date().getFullYear() })}</p>
|
||||
</footer>
|
||||
|
||||
{/* Modals */}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import React, { createContext, useContext, useEffect, useState, ReactNode } from 'react';
|
||||
import { translations, Language } from './translations';
|
||||
|
||||
interface LanguageContextProps {
|
||||
language: Language;
|
||||
setLanguage: (lang: Language) => void;
|
||||
t: (path: string, params?: Record<string, string | number>) => string;
|
||||
}
|
||||
|
||||
const LanguageContext = createContext<LanguageContextProps | undefined>(undefined);
|
||||
|
||||
export const LanguageProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const [language, setLanguageState] = useState<Language>('en');
|
||||
|
||||
useEffect(() => {
|
||||
const savedLang = localStorage.getItem('plexsync-language') as Language;
|
||||
if (savedLang && translations[savedLang]) {
|
||||
setLanguageState(savedLang);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const setLanguage = (lang: Language) => {
|
||||
setLanguageState(lang);
|
||||
localStorage.setItem('plexsync-language', lang);
|
||||
};
|
||||
|
||||
const t = (path: string, params?: Record<string, string | number>): string => {
|
||||
const keys = path.split('.');
|
||||
let current: any = translations[language];
|
||||
|
||||
for (const key of keys) {
|
||||
if (current[key] === undefined) {
|
||||
console.warn(`Missing translation for key: ${path} in language: ${language}`);
|
||||
return path;
|
||||
}
|
||||
current = current[key];
|
||||
}
|
||||
|
||||
let text = current as string;
|
||||
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
text = text.replace(`{${key}}`, String(value));
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
return (
|
||||
<LanguageContext.Provider value={{ language, setLanguage, t }}>
|
||||
{children}
|
||||
</LanguageContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useLanguage = () => {
|
||||
const context = useContext(LanguageContext);
|
||||
if (!context) {
|
||||
throw new Error('useLanguage must be used within a LanguageProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||
import { PlexConnectionSettings, PlexServerConnection, PlexLibrary } from '../types';
|
||||
import { apiService } from '../services/api';
|
||||
import { X, Server, Lock, User, Key, Globe, Eye, EyeOff, CheckCircle, Library, ChevronDown, ChevronRight, Settings, Loader2 } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
|
||||
interface ConnectionModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -13,6 +14,7 @@ interface ConnectionModalProps {
|
||||
}
|
||||
|
||||
const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onConnectSuccess, onShowMessage, initialSettings }) => {
|
||||
const { t } = useLanguage();
|
||||
const [formData, setFormData] = useState<PlexConnectionSettings>({
|
||||
protocol: 'http',
|
||||
address: '',
|
||||
@@ -35,10 +37,12 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
const [selectedLibraryId, setSelectedLibraryId] = useState<string>('');
|
||||
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const prevIsOpenRef = useRef(isOpen);
|
||||
|
||||
// Reset state when opening
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
// Only execute reset logic when modal opens (isOpen changes from false to true)
|
||||
if (isOpen && !prevIsOpenRef.current) {
|
||||
setError(null);
|
||||
setConnectedServerInfo(null);
|
||||
setLibraries([]);
|
||||
@@ -54,12 +58,15 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
}));
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
// Cleanup any pending request if modal closes
|
||||
|
||||
// Cleanup when closing
|
||||
if (!isOpen && prevIsOpenRef.current) {
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
prevIsOpenRef.current = isOpen;
|
||||
}, [isOpen, initialSettings]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
@@ -85,9 +92,9 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
onConnectSuccess(updatedInfo);
|
||||
const saveResult = await apiService.updateLibrary(lib.title);
|
||||
if (saveResult.status !== 'success') {
|
||||
onShowMessage(saveResult.message || 'Failed to save library selection');
|
||||
onShowMessage(saveResult.message || t('toasts.librarySaveFailed'));
|
||||
} else {
|
||||
onShowMessage(`Library switched to ${lib.title}`);
|
||||
onShowMessage(t('toasts.librarySwitched', { library: lib.title }));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -107,7 +114,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
abortControllerRef.current.abort();
|
||||
abortControllerRef.current = null;
|
||||
setIsConnecting(false);
|
||||
setError("Connection cancelled by user.");
|
||||
setError(t('toasts.connectionCancelled'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -136,13 +143,14 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
const info = result.data.serverInfo;
|
||||
setConnectedServerInfo(info);
|
||||
onShowMessage(`Successfully connected to ${info.name || 'Plex Server'}`);
|
||||
onShowMessage(t('toasts.connectedTo', { name: info.name || 'Plex Server' }));
|
||||
|
||||
const libs = info.libraries || [];
|
||||
setLibraries(libs);
|
||||
if (libs.length > 0) {
|
||||
const musicLibraries = libs.filter((lib) => lib.type === 'artist').sort((a, b) => a.title.localeCompare(b.title));
|
||||
setLibraries(musicLibraries);
|
||||
if (musicLibraries.length > 0) {
|
||||
const preferred = info.libraryName || formData.libraryName;
|
||||
const defaultLib = libs.find(lib => lib.title === preferred) || libs[0];
|
||||
const defaultLib = musicLibraries.find(lib => lib.title === preferred) || musicLibraries[0];
|
||||
setSelectedLibraryId(defaultLib.id);
|
||||
setFormData(prev => ({ ...prev, libraryName: defaultLib.title }));
|
||||
onConnectSuccess({
|
||||
@@ -151,27 +159,33 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
});
|
||||
const saveResult = await apiService.updateLibrary(defaultLib.title);
|
||||
if (saveResult.status !== 'success') {
|
||||
setError(saveResult.message || 'Failed to save library selection');
|
||||
setError(saveResult.message || t('toasts.librarySaveFailed'));
|
||||
}
|
||||
} else {
|
||||
onConnectSuccess(info);
|
||||
}
|
||||
} else {
|
||||
setError(result.message || "Connection failed");
|
||||
setError(result.message || t('server.connectionFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const isConnected = !!connectedServerInfo;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
|
||||
<div className="bg-gray-900 border border-gray-700 rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200 flex flex-col max-h-[90vh]">
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="bg-gray-900 border border-gray-700 rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200 flex flex-col max-h-[90vh]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
|
||||
{/* Header */}
|
||||
<div className="px-6 py-4 bg-gray-800 border-b border-gray-700 flex items-center justify-between flex-none">
|
||||
<h3 className="text-lg font-semibold text-white flex items-center gap-2">
|
||||
<Server size={18} className={isConnected ? "text-green-400" : "text-plex-orange"} />
|
||||
{isConnected ? 'Server Connected' : 'Connect Plex Server'}
|
||||
{isConnected ? t('connection.titleConnected') : t('connection.titleConnect')}
|
||||
</h3>
|
||||
<button onClick={onClose} className="text-gray-400 hover:text-white transition-colors">
|
||||
<X size={20} />
|
||||
@@ -190,7 +204,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
{/* Server Connection */}
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">Server Details</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">{t('connection.serverDetails')}</label>
|
||||
<div className="grid grid-cols-4 gap-3">
|
||||
<div className="col-span-1">
|
||||
<select
|
||||
@@ -214,7 +228,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
name="address"
|
||||
required
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="IP Address or Domain"
|
||||
placeholder={t('connection.address')}
|
||||
value={formData.address}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -228,7 +242,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="port"
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="Port (e.g. 32400)"
|
||||
placeholder={t('connection.port')}
|
||||
value={formData.port}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 px-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -240,7 +254,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
{/* Authentication */}
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">Authentication</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">{t('connection.authentication')}</label>
|
||||
|
||||
{/* Token */}
|
||||
<div className="relative">
|
||||
@@ -251,7 +265,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="token"
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="X-Plex-Token (Optional)"
|
||||
placeholder={t('connection.token')}
|
||||
value={formData.token}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all font-mono ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -273,7 +287,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="username"
|
||||
disabled={isTokenProvided || isConnecting}
|
||||
placeholder="Username / Email"
|
||||
placeholder={t('connection.username')}
|
||||
value={formData.username}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 rounded-md text-sm transition-all focus:outline-none ${disabledInputClass}`}
|
||||
@@ -289,7 +303,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type={showPassword ? "text" : "password"}
|
||||
name="password"
|
||||
disabled={isTokenProvided || isConnecting}
|
||||
placeholder="Password"
|
||||
placeholder={t('connection.password')}
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-10 rounded-md text-sm transition-all focus:outline-none ${disabledInputClass}`}
|
||||
@@ -317,7 +331,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<Settings size={14} />
|
||||
<span>Advanced Options</span>
|
||||
<span>{t('connection.advanced')}</span>
|
||||
</div>
|
||||
{showAdvanced ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
||||
</button>
|
||||
@@ -325,7 +339,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{showAdvanced && (
|
||||
<div className="p-3 bg-gray-900/50 space-y-3 animate-in slide-in-from-top-2">
|
||||
<div>
|
||||
<label className="text-xs text-gray-500 mb-1 block">Connection Timeout (Seconds)</label>
|
||||
<label className="text-xs text-gray-500 mb-1 block">{t('connection.timeout')}</label>
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
@@ -354,15 +368,15 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{isConnecting ? (
|
||||
<>
|
||||
<Loader2 size={16} className="animate-spin" />
|
||||
<span>Connecting... <span className="opacity-75 font-normal ml-1">(Cancel)</span></span>
|
||||
<span>{t('connection.connecting')} <span className="opacity-75 font-normal ml-1">({t('common.cancel')})</span></span>
|
||||
</>
|
||||
) : 'Connect Server'}
|
||||
) : t('connection.connectBtn')}
|
||||
</button>
|
||||
) : (
|
||||
<div className="mt-2 p-2 bg-green-500/10 border border-green-500/20 rounded-lg text-center">
|
||||
<p className="text-green-400 text-sm font-semibold flex items-center justify-center gap-2">
|
||||
<CheckCircle size={16} />
|
||||
Connected Successfully
|
||||
{t('connection.connectedSuccess')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -371,7 +385,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{/* Library Selection - Appears after connection */}
|
||||
{isConnected && libraries.length > 0 && (
|
||||
<div className="mt-6 pt-5 border-t border-gray-700 animate-in slide-in-from-top-2 fade-in">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider block mb-2">Select Library to Sync</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider block mb-2">{t('connection.selectLibrary')}</label>
|
||||
<div className="relative">
|
||||
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||
<Library size={14} className="text-plex-orange" />
|
||||
@@ -395,7 +409,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
onClick={onClose}
|
||||
className="px-6 py-2 bg-gray-700 hover:bg-gray-600 text-white text-sm font-medium rounded-lg transition-colors border border-gray-600 hover:border-gray-500"
|
||||
>
|
||||
Done
|
||||
{t('common.done')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
type OverflowMarqueeProps = {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
textClassName?: string;
|
||||
title?: string;
|
||||
speedPxPerSec?: number;
|
||||
minDurationSec?: number;
|
||||
};
|
||||
|
||||
type MarqueeMetrics = {
|
||||
isOverflowing: boolean;
|
||||
overflowPx: number;
|
||||
durationSec: number;
|
||||
};
|
||||
|
||||
const DEFAULT_SPEED_PX_PER_SEC = 24;
|
||||
const DEFAULT_MIN_DURATION_SEC = 4;
|
||||
|
||||
const OverflowMarquee: React.FC<OverflowMarqueeProps> = ({
|
||||
children,
|
||||
className,
|
||||
textClassName,
|
||||
title,
|
||||
speedPxPerSec = DEFAULT_SPEED_PX_PER_SEC,
|
||||
minDurationSec = DEFAULT_MIN_DURATION_SEC,
|
||||
}) => {
|
||||
const containerRef = useRef<HTMLSpanElement>(null);
|
||||
const textRef = useRef<HTMLSpanElement>(null);
|
||||
const [metrics, setMetrics] = useState<MarqueeMetrics>({
|
||||
isOverflowing: false,
|
||||
overflowPx: 0,
|
||||
durationSec: minDurationSec,
|
||||
});
|
||||
|
||||
const fallbackTitle = useMemo(() => {
|
||||
if (title) return title;
|
||||
return typeof children === 'string' ? children : undefined;
|
||||
}, [children, title]);
|
||||
|
||||
const recompute = () => {
|
||||
const container = containerRef.current;
|
||||
const text = textRef.current;
|
||||
if (!container || !text) return;
|
||||
|
||||
// Ensure we measure with current layout.
|
||||
const available = container.clientWidth;
|
||||
const content = text.scrollWidth;
|
||||
const overflowPx = Math.ceil(content - available);
|
||||
|
||||
if (overflowPx > 1) {
|
||||
const durationSec = Math.max(minDurationSec, overflowPx / Math.max(1, speedPxPerSec));
|
||||
setMetrics({ isOverflowing: true, overflowPx, durationSec });
|
||||
} else {
|
||||
// Avoid re-render loops if already not overflowing.
|
||||
setMetrics((prev) => (prev.isOverflowing ? { isOverflowing: false, overflowPx: 0, durationSec: minDurationSec } : prev));
|
||||
}
|
||||
};
|
||||
|
||||
useLayoutEffect(() => {
|
||||
recompute();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [children]);
|
||||
|
||||
useEffect(() => {
|
||||
recompute();
|
||||
|
||||
const container = containerRef.current;
|
||||
const text = textRef.current;
|
||||
if (!container || !text) return;
|
||||
|
||||
const ro = new ResizeObserver(() => recompute());
|
||||
ro.observe(container);
|
||||
ro.observe(text);
|
||||
|
||||
const onResize = () => recompute();
|
||||
window.addEventListener('resize', onResize);
|
||||
|
||||
return () => {
|
||||
ro.disconnect();
|
||||
window.removeEventListener('resize', onResize);
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const textStyle: React.CSSProperties | undefined = metrics.isOverflowing
|
||||
? ({
|
||||
['--marquee-distance' as any]: `${metrics.overflowPx}px`,
|
||||
['--marquee-duration' as any]: `${metrics.durationSec}s`,
|
||||
} satisfies React.CSSProperties)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<span
|
||||
ref={containerRef}
|
||||
className={['overflow-marquee', className].filter(Boolean).join(' ')}
|
||||
title={fallbackTitle}
|
||||
>
|
||||
<span
|
||||
ref={textRef}
|
||||
className={[
|
||||
'overflow-marquee__text',
|
||||
metrics.isOverflowing ? 'overflow-marquee__text--animate' : '',
|
||||
textClassName,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ')}
|
||||
style={textStyle}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default OverflowMarquee;
|
||||
@@ -1,26 +1,31 @@
|
||||
import React from 'react';
|
||||
import { Playlist } from '../types';
|
||||
import { Disc3, Clock } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
import OverflowMarquee from './OverflowMarquee';
|
||||
|
||||
interface PlaylistCardProps {
|
||||
playlist: Playlist;
|
||||
}
|
||||
|
||||
const PlaylistCard: React.FC<PlaylistCardProps> = ({ playlist }) => {
|
||||
const { t } = useLanguage();
|
||||
return (
|
||||
<div className="group flex flex-col w-full p-2.5 bg-gray-800/60 rounded-md border border-gray-700/50 hover:bg-gray-700 hover:border-plex-orange/50 transition-all duration-200 cursor-pointer shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<h4 className="text-sm font-medium text-gray-200 truncate flex-1 mr-2 group-hover:text-white transition-colors">
|
||||
{playlist.title}
|
||||
<h4 className="text-sm font-medium text-gray-200 flex-1 mr-2 group-hover:text-white transition-colors min-w-0">
|
||||
<OverflowMarquee>
|
||||
{playlist.title}
|
||||
</OverflowMarquee>
|
||||
</h4>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center mt-1.5 space-x-4 text-xs text-gray-500 group-hover:text-gray-400">
|
||||
<span className="flex items-center" title="Track Count">
|
||||
<span className="flex items-center" title={t('playlist.trackCount')}>
|
||||
<Disc3 size={12} className="mr-1.5 opacity-70" />
|
||||
{playlist.trackCount}
|
||||
</span>
|
||||
<span className="flex items-center" title="Last Updated">
|
||||
<span className="flex items-center" title={t('playlist.lastUpdated')}>
|
||||
<Clock size={12} className="mr-1.5 opacity-70" />
|
||||
{new Date(playlist.lastUpdated).toLocaleDateString()}
|
||||
</span>
|
||||
|
||||
@@ -3,6 +3,8 @@ import React from 'react';
|
||||
import { Playlist, ServerType, PlexServerConnection } from '../types';
|
||||
import PlaylistCard from './PlaylistCard';
|
||||
import { RefreshCw, Server, Cloud, WifiOff, X } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
import OverflowMarquee from './OverflowMarquee';
|
||||
|
||||
interface ServerPanelProps {
|
||||
type: ServerType;
|
||||
@@ -14,6 +16,7 @@ interface ServerPanelProps {
|
||||
}
|
||||
|
||||
const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, onRefresh, onCancel, serverInfo }) => {
|
||||
const { t } = useLanguage();
|
||||
const isLocal = type === ServerType.LOCAL;
|
||||
|
||||
let Icon = isLocal ? Server : Cloud;
|
||||
@@ -28,39 +31,44 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
let displaySubtitle: React.ReactNode = null;
|
||||
|
||||
if (isLocal) {
|
||||
displayTitle = 'Local Server';
|
||||
displayTitle = t('server.local');
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-400 font-medium mt-0.5 md:mt-0 md:ml-0">
|
||||
{playlists.length} Playlists
|
||||
{t('server.playlists', { count: playlists.length })}
|
||||
</p>
|
||||
);
|
||||
} else {
|
||||
// Cloud Logic
|
||||
if (serverInfo) {
|
||||
if (serverInfo.isConnected) {
|
||||
displayTitle = serverInfo.name || 'Cloud Server';
|
||||
displayTitle = serverInfo.name || t('server.cloud');
|
||||
displaySubtitle = (
|
||||
<div className="flex items-center text-xs text-gray-300 font-medium space-x-1.5 truncate mt-0.5 md:mt-0">
|
||||
<span className="text-plex-orange truncate font-semibold">{serverInfo.libraryName}</span>
|
||||
<span className="text-plex-orange font-semibold min-w-0 max-w-full">
|
||||
<span className="block md:hidden truncate">{serverInfo.libraryName}</span>
|
||||
<OverflowMarquee className="hidden md:inline-block">
|
||||
{serverInfo.libraryName}
|
||||
</OverflowMarquee>
|
||||
</span>
|
||||
<span className="text-gray-600 hidden md:inline">•</span>
|
||||
<span className="text-gray-500 font-mono text-[10px] hidden md:inline">{serverInfo.ip}:{serverInfo.port}</span>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
displayTitle = 'Not Connected';
|
||||
displayTitle = t('server.notConnected');
|
||||
Icon = WifiOff;
|
||||
headerColor = 'text-red-400';
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-500 font-medium mt-0.5">
|
||||
Connection failed
|
||||
{t('server.connectionFailed')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
displayTitle = 'Cloud Server';
|
||||
displayTitle = t('server.cloud');
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-500 font-medium mt-0.5">
|
||||
{isLoading ? 'Connecting...' : 'Waiting...'}
|
||||
{isLoading ? t('server.connecting') : t('server.waiting')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -121,7 +129,7 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
: 'text-gray-400 hover:text-white hover:bg-white/10'
|
||||
}
|
||||
`}
|
||||
title={isLoading ? "Cancel Refresh" : "Refresh Playlists"}
|
||||
title={isLoading ? t('server.cancelRefresh') : t('server.refreshPlaylists')}
|
||||
>
|
||||
{isLoading ? (
|
||||
<div className="relative flex items-center justify-center">
|
||||
@@ -141,11 +149,11 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
{isLoading && playlists.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-full text-gray-500 space-y-3">
|
||||
<RefreshCw size={24} className="animate-spin text-plex-orange/50" />
|
||||
<p className="text-xs font-medium tracking-wide uppercase">Syncing...</p>
|
||||
<p className="text-xs font-medium tracking-wide uppercase">{t('server.syncing')}</p>
|
||||
</div>
|
||||
) : playlists.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-full text-gray-500">
|
||||
<p className="text-sm">No playlists found.</p>
|
||||
<p className="text-sm">{t('server.noPlaylists')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2.5 md:space-y-3">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,41 @@
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: #6b7280;
|
||||
}
|
||||
|
||||
/* Overflow marquee (auto-scroll when truncated) */
|
||||
.overflow-marquee {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.overflow-marquee__text {
|
||||
display: inline-block;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.overflow-marquee__text--animate {
|
||||
animation: overflow-marquee-scroll var(--marquee-duration, 6s) linear infinite;
|
||||
}
|
||||
|
||||
@keyframes overflow-marquee-scroll {
|
||||
0%, 12% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
70%, 86% {
|
||||
transform: translateX(calc(var(--marquee-distance, 0px) * -1));
|
||||
}
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.overflow-marquee__text--animate {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script type="importmap">
|
||||
{
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
import { LanguageProvider } from './LanguageContext';
|
||||
|
||||
const rootElement = document.getElementById('root');
|
||||
if (!rootElement) {
|
||||
@@ -10,6 +11,8 @@ if (!rootElement) {
|
||||
const root = ReactDOM.createRoot(rootElement);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<LanguageProvider>
|
||||
<App />
|
||||
</LanguageProvider>
|
||||
</React.StrictMode>
|
||||
);
|
||||
@@ -0,0 +1,161 @@
|
||||
export const cht = {
|
||||
app: {
|
||||
title: 'PlexSync',
|
||||
manager: '管理',
|
||||
footer: '© {year} PMS Playlist Sync。已連線至 Docker 後端。',
|
||||
},
|
||||
common: {
|
||||
save: '儲存',
|
||||
cancel: '取消',
|
||||
revert: '還原',
|
||||
delete: '刪除',
|
||||
done: '完成',
|
||||
loading: '載入中…',
|
||||
refresh: '重新整理',
|
||||
close: '關閉',
|
||||
none: '無',
|
||||
disabled: '已停用',
|
||||
add: '新增',
|
||||
switchLanguage: '切換語言',
|
||||
},
|
||||
server: {
|
||||
local: '本機伺服器',
|
||||
cloud: '雲端伺服器',
|
||||
playlists: '{count} 個播放清單',
|
||||
notConnected: '未連線',
|
||||
connectionFailed: '連線失敗',
|
||||
connecting: '連線中…',
|
||||
waiting: '等待中…',
|
||||
syncing: '同步中…',
|
||||
noPlaylists: '找不到播放清單。',
|
||||
cancelRefresh: '取消重新整理',
|
||||
refreshPlaylists: '重新整理播放清單',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: '曲目數',
|
||||
lastUpdated: '上次更新',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: '路徑對應',
|
||||
backup: '備份',
|
||||
autoSync: '自動同步',
|
||||
watch: '監看',
|
||||
watchModeActive: '監看模式:啟用',
|
||||
watchModeDisabled: '監看模式:停用',
|
||||
notSet: '未設定',
|
||||
retain: '保留:{count}',
|
||||
keep: '保留 {count}',
|
||||
connected: '已連線至 Plex',
|
||||
disconnected: '未連線',
|
||||
synchronizing: 'SYNCHRONIZING',
|
||||
syncComplete: 'SYNC COMPLETE',
|
||||
},
|
||||
strategies: {
|
||||
title: '同步策略',
|
||||
localOverwrite: {
|
||||
label: '本機覆寫',
|
||||
desc: '本機播放清單完全覆寫雲端。(無 Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: '雲端覆寫',
|
||||
desc: '雲端播放清單完全覆寫本機。(無 Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: '雙向合併(本機優先)',
|
||||
desc: '合併兩端。衝突以本機版本為準。',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: '雙向合併(雲端優先)',
|
||||
desc: '合併兩端。衝突以雲端版本為準。',
|
||||
},
|
||||
syncNow: '立即同步',
|
||||
syncing: '同步進行中…',
|
||||
saveWarning: '同步前請先儲存待處理的變更(備份/路徑對應)。',
|
||||
},
|
||||
mapping: {
|
||||
title: '路徑對應',
|
||||
simple: '簡易對應',
|
||||
regex: 'Regex 規則',
|
||||
simpleTitle: '路徑對應',
|
||||
simpleSubtitle: '使用簡單字串比對將本機路徑對應到雲端路徑',
|
||||
regexPre: '前處理(同步前)',
|
||||
regexPost: '後處理(同步後 / 結果)',
|
||||
localPath: '本機路徑',
|
||||
cloudPath: '雲端路徑',
|
||||
pattern: '模式',
|
||||
replace: '取代',
|
||||
saveRules: '儲存規則',
|
||||
noRules: '尚未定義規則。',
|
||||
},
|
||||
backup: {
|
||||
title: '備份保留',
|
||||
enable: '啟用備份',
|
||||
enableDesc: '變更前建立副本',
|
||||
maxVersions: '保留的最大版本數:',
|
||||
noAutoDelete: '不自動刪除',
|
||||
autoDelete: '自動刪除最舊版本',
|
||||
},
|
||||
schedule: {
|
||||
title: '排程任務',
|
||||
cron: 'Cron',
|
||||
daily: '每日',
|
||||
weekly: '每週',
|
||||
weekdaysNarrow: {
|
||||
0: '日',
|
||||
1: '一',
|
||||
2: '二',
|
||||
3: '三',
|
||||
4: '四',
|
||||
5: '五',
|
||||
6: '六',
|
||||
},
|
||||
enableCron: '啟用 Cron 排程',
|
||||
enableDaily: '啟用每日執行',
|
||||
enableWeekly: '啟用每週執行',
|
||||
watchLocal: '監看本機變更',
|
||||
watchDesc: '本機播放清單更新時自動同步',
|
||||
schedule: '排程',
|
||||
notConfigured: '尚未設定',
|
||||
today: '今天',
|
||||
tomorrow: '明天',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: '伺服器已連線',
|
||||
titleConnect: '連線 Plex 伺服器',
|
||||
serverDetails: '伺服器詳細資訊',
|
||||
authentication: '驗證',
|
||||
protocol: '通訊協定',
|
||||
address: 'IP 位址或網域',
|
||||
port: '連接埠',
|
||||
token: 'X-Plex-Token(選填)',
|
||||
username: '使用者名稱 / 電子郵件',
|
||||
password: '密碼',
|
||||
advanced: '進階選項',
|
||||
timeout: '連線逾時(秒)',
|
||||
connectBtn: '連線伺服器',
|
||||
connecting: '連線中…',
|
||||
connectedSuccess: '連線成功',
|
||||
selectLibrary: '選擇要同步的媒體庫',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: '已取消本機重新整理。',
|
||||
cloudRefreshCancelled: '已取消雲端重新整理。',
|
||||
strategySaved: '已儲存選擇的策略「{strategy}」。',
|
||||
strategySaveFailed: '儲存同步策略失敗。',
|
||||
mappingSaved: '已儲存路徑對應規則。',
|
||||
mappingSaveFailed: '儲存路徑對應規則失敗。',
|
||||
backupSaved: '已儲存備份設定。',
|
||||
backupFailed: '儲存備份設定失敗。',
|
||||
scheduleDisabled: '已停用排程任務。',
|
||||
scheduleEmpty: '已停用排程任務(Cron 為空)。',
|
||||
scheduleStarted: '排程任務更新成功。',
|
||||
scheduleFailed: '更新排程失敗。',
|
||||
syncFailed: '同步失敗。請檢查連線。',
|
||||
backgroundSyncSuccess: '背景同步已成功完成。',
|
||||
backgroundSyncFailed: '背景同步失敗:{error}',
|
||||
librarySwitched: '媒體庫已切換為 {library}',
|
||||
connectedTo: '已成功連線到 {name}',
|
||||
connectionCancelled: '使用者已取消連線。',
|
||||
librarySaveFailed: '儲存媒體庫選擇失敗。',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,161 @@
|
||||
export const en = {
|
||||
app: {
|
||||
title: 'PlexSync',
|
||||
manager: 'Manager',
|
||||
footer: '© {year} PMS Playlist Sync. Connected to Docker backend.',
|
||||
},
|
||||
common: {
|
||||
save: 'Save',
|
||||
cancel: 'Cancel',
|
||||
revert: 'Revert',
|
||||
delete: 'Delete',
|
||||
done: 'Done',
|
||||
loading: 'Loading...',
|
||||
refresh: 'Refresh',
|
||||
close: 'Close',
|
||||
none: 'None',
|
||||
disabled: 'Disabled',
|
||||
add: 'Add',
|
||||
switchLanguage: 'Switch Language',
|
||||
},
|
||||
server: {
|
||||
local: 'Local Server',
|
||||
cloud: 'Cloud Server',
|
||||
playlists: '{count} Playlists',
|
||||
notConnected: 'Not Connected',
|
||||
connectionFailed: 'Connection failed',
|
||||
connecting: 'Connecting...',
|
||||
waiting: 'Waiting...',
|
||||
syncing: 'Syncing...',
|
||||
noPlaylists: 'No playlists found.',
|
||||
cancelRefresh: 'Cancel Refresh',
|
||||
refreshPlaylists: 'Refresh Playlists',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: 'Track Count',
|
||||
lastUpdated: 'Last Updated',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: 'Mapping',
|
||||
backup: 'Backup',
|
||||
autoSync: 'Auto-Sync',
|
||||
watch: 'Watch',
|
||||
watchModeActive: 'Watch Mode: Active',
|
||||
watchModeDisabled: 'Watch Mode: Disabled',
|
||||
notSet: 'Not Set',
|
||||
retain: 'Retain: {count}',
|
||||
keep: 'Keep {count}',
|
||||
connected: 'Connected to Plex',
|
||||
disconnected: 'Disconnected',
|
||||
synchronizing: 'SYNCHRONIZING',
|
||||
syncComplete: 'SYNC COMPLETE',
|
||||
},
|
||||
strategies: {
|
||||
title: 'Sync Strategy',
|
||||
localOverwrite: {
|
||||
label: 'Local Overwrite',
|
||||
desc: 'Local playlist completely overwrites Cloud. (No Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: 'Cloud Overwrite',
|
||||
desc: 'Cloud playlist completely overwrites Local. (No Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: 'Two-way Merge (Local Priority)',
|
||||
desc: 'Merge both. Conflicts resolve to Local version.',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: 'Two-way Merge (Cloud Priority)',
|
||||
desc: 'Merge both. Conflicts resolve to Cloud version.',
|
||||
},
|
||||
syncNow: 'Sync Now',
|
||||
syncing: 'Sync in Progress...',
|
||||
saveWarning: 'Please save pending changes (Backups/Path Mapping) before syncing.',
|
||||
},
|
||||
mapping: {
|
||||
title: 'Path Mapping',
|
||||
simple: 'Simple Mapping',
|
||||
regex: 'Regex Rules',
|
||||
simpleTitle: 'Path Mapping',
|
||||
simpleSubtitle: 'Map Local paths to Cloud paths using simple string matching',
|
||||
regexPre: 'Pre-Processing (Before Sync)',
|
||||
regexPost: 'Post-Processing (After Sync / Result)',
|
||||
localPath: 'Local Path',
|
||||
cloudPath: 'Cloud Path',
|
||||
pattern: 'Pattern',
|
||||
replace: 'Replace',
|
||||
saveRules: 'Save Rules',
|
||||
noRules: 'No rules defined.',
|
||||
},
|
||||
backup: {
|
||||
title: 'Backup Retention',
|
||||
enable: 'Enable Backups',
|
||||
enableDesc: 'Create a copy before changes',
|
||||
maxVersions: 'Max versions to keep:',
|
||||
noAutoDelete: 'No auto-delete',
|
||||
autoDelete: 'Oldest deleted automatically',
|
||||
},
|
||||
schedule: {
|
||||
title: 'Scheduled Tasks',
|
||||
cron: 'Cron',
|
||||
daily: 'Daily',
|
||||
weekly: 'Weekly',
|
||||
weekdaysNarrow: {
|
||||
0: 'S',
|
||||
1: 'M',
|
||||
2: 'T',
|
||||
3: 'W',
|
||||
4: 'T',
|
||||
5: 'F',
|
||||
6: 'S',
|
||||
},
|
||||
enableCron: 'Enable Cron Schedule',
|
||||
enableDaily: 'Enable Daily Run',
|
||||
enableWeekly: 'Enable Weekly Run',
|
||||
watchLocal: 'Watch Local Changes',
|
||||
watchDesc: 'Auto-sync when local playlist updates',
|
||||
schedule: 'Schedule',
|
||||
notConfigured: 'Not configured',
|
||||
today: 'Today',
|
||||
tomorrow: 'Tomorrow',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: 'Server Connected',
|
||||
titleConnect: 'Connect Plex Server',
|
||||
serverDetails: 'Server Details',
|
||||
authentication: 'Authentication',
|
||||
protocol: 'Protocol',
|
||||
address: 'IP Address or Domain',
|
||||
port: 'Port',
|
||||
token: 'X-Plex-Token (Optional)',
|
||||
username: 'Username / Email',
|
||||
password: 'Password',
|
||||
advanced: 'Advanced Options',
|
||||
timeout: 'Connection Timeout (Seconds)',
|
||||
connectBtn: 'Connect Server',
|
||||
connecting: 'Connecting...',
|
||||
connectedSuccess: 'Connected Successfully',
|
||||
selectLibrary: 'Select Library to Sync',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: 'Local refresh cancelled.',
|
||||
cloudRefreshCancelled: 'Cloud refresh cancelled.',
|
||||
strategySaved: 'Selected strategy "{strategy}" has been saved.',
|
||||
strategySaveFailed: 'Failed to save sync strategy.',
|
||||
mappingSaved: 'Path mapping rules have been saved.',
|
||||
mappingSaveFailed: 'Failed to save path mapping rules.',
|
||||
backupSaved: 'Backup settings have been saved.',
|
||||
backupFailed: 'Failed to save backup settings.',
|
||||
scheduleDisabled: 'Scheduled tasks disabled.',
|
||||
scheduleEmpty: 'Scheduled tasks disabled (Empty Cron).',
|
||||
scheduleStarted: 'Scheduled task updated successfully.',
|
||||
scheduleFailed: 'Failed to update schedule.',
|
||||
syncFailed: 'Sync failed. Please check connection.',
|
||||
backgroundSyncSuccess: 'Background sync completed successfully.',
|
||||
backgroundSyncFailed: 'Background sync failed: {error}',
|
||||
librarySwitched: 'Library switched to {library}',
|
||||
connectedTo: 'Successfully connected to {name}',
|
||||
connectionCancelled: 'Connection cancelled by user.',
|
||||
librarySaveFailed: 'Failed to save library selection.',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,161 @@
|
||||
export const es = {
|
||||
app: {
|
||||
title: 'PlexSync',
|
||||
manager: 'Gestor',
|
||||
footer: '© {year} PMS Playlist Sync. Conectado al backend Docker.',
|
||||
},
|
||||
common: {
|
||||
save: 'Guardar',
|
||||
cancel: 'Cancelar',
|
||||
revert: 'Revertir',
|
||||
delete: 'Eliminar',
|
||||
done: 'Hecho',
|
||||
loading: 'Cargando...',
|
||||
refresh: 'Actualizar',
|
||||
close: 'Cerrar',
|
||||
none: 'Ninguno',
|
||||
disabled: 'Deshabilitado',
|
||||
add: 'Añadir',
|
||||
switchLanguage: 'Cambiar idioma',
|
||||
},
|
||||
server: {
|
||||
local: 'Servidor Local',
|
||||
cloud: 'Servidor Nube',
|
||||
playlists: '{count} Listas',
|
||||
notConnected: 'No Conectado',
|
||||
connectionFailed: 'Conexión fallida',
|
||||
connecting: 'Conectando...',
|
||||
waiting: 'Esperando...',
|
||||
syncing: 'Sincronizando...',
|
||||
noPlaylists: 'No se encontraron listas.',
|
||||
cancelRefresh: 'Cancelar',
|
||||
refreshPlaylists: 'Actualizar Listas',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: 'Pistas',
|
||||
lastUpdated: 'Actualizado',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: 'Mapeo',
|
||||
backup: 'Respaldo',
|
||||
autoSync: 'Auto-Sync',
|
||||
watch: 'Vigilar',
|
||||
watchModeActive: 'Modo Vigía: Activo',
|
||||
watchModeDisabled: 'Modo Vigía: Desactivado',
|
||||
notSet: 'No Def.',
|
||||
retain: 'Retener: {count}',
|
||||
keep: 'Guardar {count}',
|
||||
connected: 'Conectado a Plex',
|
||||
disconnected: 'Desconectado',
|
||||
synchronizing: 'SINCRONIZANDO',
|
||||
syncComplete: 'SINCRONIZACIÓN COMPLETA',
|
||||
},
|
||||
strategies: {
|
||||
title: 'Estrategia de Sync',
|
||||
localOverwrite: {
|
||||
label: 'Sobreescribir Local',
|
||||
desc: 'La lista local sobreescribe la nube. (Sin Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: 'Sobreescribir Nube',
|
||||
desc: 'La lista de la nube sobreescribe la local. (Sin Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: 'Fusión (Prioridad Local)',
|
||||
desc: 'Fusionar ambas. Conflictos resueltos a versión Local.',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: 'Fusión (Prioridad Nube)',
|
||||
desc: 'Fusionar ambas. Conflictos resueltos a versión Nube.',
|
||||
},
|
||||
syncNow: 'Sincronizar Ahora',
|
||||
syncing: 'Sincronizando...',
|
||||
saveWarning: 'Guarde los cambios pendientes (Respaldos/Mapeo) antes de sincronizar.',
|
||||
},
|
||||
mapping: {
|
||||
title: 'Mapeo de Rutas',
|
||||
simple: 'Mapeo Simple',
|
||||
regex: 'Reglas Regex',
|
||||
simpleTitle: 'Mapeo de Rutas',
|
||||
simpleSubtitle: 'Mapear rutas locales a la nube usando coincidencia simple',
|
||||
regexPre: 'Pre-Procesamiento (Antes de Sync)',
|
||||
regexPost: 'Post-Procesamiento (Después de Sync)',
|
||||
localPath: 'Ruta Local',
|
||||
cloudPath: 'Ruta Nube',
|
||||
pattern: 'Patrón',
|
||||
replace: 'Reemplazo',
|
||||
saveRules: 'Guardar Reglas',
|
||||
noRules: 'No hay reglas definidas.',
|
||||
},
|
||||
backup: {
|
||||
title: 'Retención de Respaldo',
|
||||
enable: 'Habilitar Respaldos',
|
||||
enableDesc: 'Crear copia antes de cambios',
|
||||
maxVersions: 'Máx versiones a guardar:',
|
||||
noAutoDelete: 'Sin auto-borrado',
|
||||
autoDelete: 'El más antiguo se borra automáticamente',
|
||||
},
|
||||
schedule: {
|
||||
title: 'Tareas Programadas',
|
||||
cron: 'Cron',
|
||||
daily: 'Diario',
|
||||
weekly: 'Semanal',
|
||||
weekdaysNarrow: {
|
||||
0: 'D',
|
||||
1: 'L',
|
||||
2: 'M',
|
||||
3: 'X',
|
||||
4: 'J',
|
||||
5: 'V',
|
||||
6: 'S',
|
||||
},
|
||||
enableCron: 'Habilitar Cron',
|
||||
enableDaily: 'Habilitar Ejecución Diaria',
|
||||
enableWeekly: 'Habilitar Ejecución Semanal',
|
||||
watchLocal: 'Vigilar Cambios Locales',
|
||||
watchDesc: 'Auto-sync cuando la lista local se actualiza',
|
||||
schedule: 'Horario',
|
||||
notConfigured: 'No configurado',
|
||||
today: 'Hoy',
|
||||
tomorrow: 'Mañana',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: 'Servidor Conectado',
|
||||
titleConnect: 'Conectar Servidor Plex',
|
||||
serverDetails: 'Detalles del Servidor',
|
||||
authentication: 'Autenticación',
|
||||
protocol: 'Protocolo',
|
||||
address: 'Dirección IP o Dominio',
|
||||
port: 'Puerto',
|
||||
token: 'X-Plex-Token (Opcional)',
|
||||
username: 'Usuario / Email',
|
||||
password: 'Password',
|
||||
advanced: 'Opciones Avanzadas',
|
||||
timeout: 'Tiempo de espera (Segundos)',
|
||||
connectBtn: 'Conectar Servidor',
|
||||
connecting: 'Conectando...',
|
||||
connectedSuccess: 'Conectado Exitosamente',
|
||||
selectLibrary: 'Seleccionar Librería',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: 'Actualización local cancelada.',
|
||||
cloudRefreshCancelled: 'Actualización nube cancelada.',
|
||||
strategySaved: 'Estrategia seleccionada "{strategy}" guardada.',
|
||||
strategySaveFailed: 'Error al guardar estrategia de sync.',
|
||||
mappingSaved: 'Reglas de mapeo guardadas.',
|
||||
mappingSaveFailed: 'Error al guardar reglas de mapeo.',
|
||||
backupSaved: 'Configuración de respaldo guardada.',
|
||||
backupFailed: 'Error al guardar configuración de respaldo.',
|
||||
scheduleDisabled: 'Tareas programadas deshabilitadas.',
|
||||
scheduleEmpty: 'Tareas programadas deshabilitadas (Cron Vacío).',
|
||||
scheduleStarted: 'Tarea programada actualizada exitosamente.',
|
||||
scheduleFailed: 'Error al actualizar horario.',
|
||||
syncFailed: 'Fallo en sync. Revise conexión.',
|
||||
backgroundSyncSuccess: 'Sync en segundo plano completado.',
|
||||
backgroundSyncFailed: 'Sync en segundo plano falló: {error}',
|
||||
librarySwitched: 'Librería cambiada a {library}',
|
||||
connectedTo: 'Conectado exitosamente a {name}',
|
||||
connectionCancelled: 'Conexión cancelada por usuario.',
|
||||
librarySaveFailed: 'Error al guardar selección de librería.',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,161 @@
|
||||
export const zh = {
|
||||
app: {
|
||||
title: 'PlexSync',
|
||||
manager: '管理',
|
||||
footer: '© {year} PMS Playlist Sync。已连接到 Docker 后端。',
|
||||
},
|
||||
common: {
|
||||
save: '保存',
|
||||
cancel: '取消',
|
||||
revert: '恢复',
|
||||
delete: '删除',
|
||||
done: '完成',
|
||||
loading: '加载中...',
|
||||
refresh: '刷新',
|
||||
close: '关闭',
|
||||
none: '无',
|
||||
disabled: '已禁用',
|
||||
add: '添加',
|
||||
switchLanguage: '切换语言',
|
||||
},
|
||||
server: {
|
||||
local: '本地服务器',
|
||||
cloud: '云端服务器',
|
||||
playlists: '{count} 个播放列表',
|
||||
notConnected: '未连接',
|
||||
connectionFailed: '连接失败',
|
||||
connecting: '正在连接...',
|
||||
waiting: '等待中...',
|
||||
syncing: '同步中...',
|
||||
noPlaylists: '未找到播放列表。',
|
||||
cancelRefresh: '取消刷新',
|
||||
refreshPlaylists: '刷新播放列表',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: '曲目数',
|
||||
lastUpdated: '最近更新',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: '路径映射',
|
||||
backup: '备份',
|
||||
autoSync: '自动同步',
|
||||
watch: '监听',
|
||||
watchModeActive: '监听模式:启用',
|
||||
watchModeDisabled: '监听模式:禁用',
|
||||
notSet: '未设置',
|
||||
retain: '保留:{count}',
|
||||
keep: '保留 {count}',
|
||||
connected: '已连接 Plex',
|
||||
disconnected: '未连接',
|
||||
synchronizing: 'SYNCHRONIZING',
|
||||
syncComplete: 'SYNC COMPLETE',
|
||||
},
|
||||
strategies: {
|
||||
title: '同步策略',
|
||||
localOverwrite: {
|
||||
label: '本地覆盖',
|
||||
desc: '本地播放列表完全覆盖云端。(无 Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: '云端覆盖',
|
||||
desc: '云端播放列表完全覆盖本地。(无 Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: '双向合并(本地优先)',
|
||||
desc: '合并两端。冲突以本地版本为准。',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: '双向合并(云端优先)',
|
||||
desc: '合并两端。冲突以云端版本为准。',
|
||||
},
|
||||
syncNow: '立即同步',
|
||||
syncing: '同步进行中...',
|
||||
saveWarning: '同步前请先保存待处理的更改(备份/路径映射)。',
|
||||
},
|
||||
mapping: {
|
||||
title: '路径映射',
|
||||
simple: '简单映射',
|
||||
regex: '正则规则',
|
||||
simpleTitle: '路径映射',
|
||||
simpleSubtitle: '使用简单字符串匹配将本地路径映射到云端路径',
|
||||
regexPre: '预处理(同步前)',
|
||||
regexPost: '后处理(同步后 / 结果)',
|
||||
localPath: '本地路径',
|
||||
cloudPath: '云端路径',
|
||||
pattern: '模式',
|
||||
replace: '替换',
|
||||
saveRules: '保存规则',
|
||||
noRules: '尚未定义规则。',
|
||||
},
|
||||
backup: {
|
||||
title: '备份保留',
|
||||
enable: '启用备份',
|
||||
enableDesc: '在更改前创建副本',
|
||||
maxVersions: '保留的最大版本数:',
|
||||
noAutoDelete: '不自动删除',
|
||||
autoDelete: '自动删除最旧版本',
|
||||
},
|
||||
schedule: {
|
||||
title: '定时任务',
|
||||
cron: 'Cron',
|
||||
daily: '每日',
|
||||
weekly: '每周',
|
||||
weekdaysNarrow: {
|
||||
0: '日',
|
||||
1: '一',
|
||||
2: '二',
|
||||
3: '三',
|
||||
4: '四',
|
||||
5: '五',
|
||||
6: '六',
|
||||
},
|
||||
enableCron: '启用 Cron 计划',
|
||||
enableDaily: '启用每日运行',
|
||||
enableWeekly: '启用每周运行',
|
||||
watchLocal: '监听本地更改',
|
||||
watchDesc: '本地播放列表更新时自动同步',
|
||||
schedule: '计划',
|
||||
notConfigured: '未配置',
|
||||
today: '今天',
|
||||
tomorrow: '明天',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: '服务器已连接',
|
||||
titleConnect: '连接 Plex 服务器',
|
||||
serverDetails: '服务器详情',
|
||||
authentication: '认证',
|
||||
protocol: '协议',
|
||||
address: 'IP 地址或域名',
|
||||
port: '端口',
|
||||
token: 'X-Plex-Token(可选)',
|
||||
username: '用户名 / 邮箱',
|
||||
password: '密码',
|
||||
advanced: '高级选项',
|
||||
timeout: '连接超时(秒)',
|
||||
connectBtn: '连接服务器',
|
||||
connecting: '连接中...',
|
||||
connectedSuccess: '连接成功',
|
||||
selectLibrary: '选择要同步的媒体库',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: '本地刷新已取消。',
|
||||
cloudRefreshCancelled: '云端刷新已取消。',
|
||||
strategySaved: '已保存选择的策略“{strategy}”。',
|
||||
strategySaveFailed: '保存同步策略失败。',
|
||||
mappingSaved: '已保存路径映射规则。',
|
||||
mappingSaveFailed: '保存路径映射规则失败。',
|
||||
backupSaved: '已保存备份设置。',
|
||||
backupFailed: '保存备份设置失败。',
|
||||
scheduleDisabled: '已禁用定时任务。',
|
||||
scheduleEmpty: '已禁用定时任务(Cron 为空)。',
|
||||
scheduleStarted: '定时任务更新成功。',
|
||||
scheduleFailed: '更新定时任务失败。',
|
||||
syncFailed: '同步失败。请检查连接。',
|
||||
backgroundSyncSuccess: '后台同步已成功完成。',
|
||||
backgroundSyncFailed: '后台同步失败:{error}',
|
||||
librarySwitched: '媒体库已切换为 {library}',
|
||||
connectedTo: '已成功连接到 {name}',
|
||||
connectionCancelled: '用户已取消连接。',
|
||||
librarySaveFailed: '保存媒体库选择失败。',
|
||||
},
|
||||
};
|
||||
+108
-14
@@ -1,4 +1,4 @@
|
||||
import { Playlist, ServerType, ApiResponse, PlexServerConnection, PlexConnectionSettings, PlexLibrary, RegexReplacement, SyncStrategy } from '../types';
|
||||
import { Playlist, ServerType, ApiResponse, PlexServerConnection, PlexConnectionSettings, PlexLibrary, ReplacementRule, PathMappingConfig, PathMappingMode, PathMappingRules, SyncStrategy, ScheduleSettings, BackupSettings } from '../types';
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE_URL || '';
|
||||
|
||||
@@ -38,24 +38,72 @@ const mapPlaylist = (item: any): Playlist => ({
|
||||
const mapLibrary = (item: any): PlexLibrary => ({
|
||||
id: item.id ?? item.title,
|
||||
title: item.title ?? item.id,
|
||||
type: item.type ?? 'artist',
|
||||
type: item.type || item.libraryType || item.library_type || item.section?.type || '',
|
||||
});
|
||||
|
||||
const mapRegexRules = (rules: any[]): RegexReplacement[] =>
|
||||
// Helper function to map raw rules array to ReplacementRule[]
|
||||
const mapReplacementRules = (rules: any[]): ReplacementRule[] =>
|
||||
(rules || []).map((rule, index) => ({
|
||||
id: rule.id || `${rule.pattern || 'rule'}-${index}`,
|
||||
pattern: rule.pattern || '',
|
||||
replacement: rule.replacement || '',
|
||||
id: rule.id || `${rule.search || 'rule'}-${index}-${Date.now()}`,
|
||||
search: rule.search || rule.pattern || '',
|
||||
replace: rule.replace || rule.replacement || '',
|
||||
}));
|
||||
|
||||
// Helper function to map API path_mapping response to PathMappingConfig
|
||||
const mapPathMappingConfig = (data: any): PathMappingConfig => {
|
||||
const defaultConfig: PathMappingConfig = {
|
||||
mode: PathMappingMode.SIMPLE,
|
||||
simple: [],
|
||||
regex: {
|
||||
localPre: [],
|
||||
localPost: [],
|
||||
remotePre: [],
|
||||
remotePost: []
|
||||
}
|
||||
};
|
||||
|
||||
if (!data || !data.path_mapping) {
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
const pm = data.path_mapping;
|
||||
return {
|
||||
mode: pm.mode === 'REGEX' ? PathMappingMode.REGEX : PathMappingMode.SIMPLE,
|
||||
simple: mapReplacementRules(pm.simple || []),
|
||||
regex: {
|
||||
localPre: mapReplacementRules(pm.regex?.localPre || pm.regex?.local_pre || []),
|
||||
localPost: mapReplacementRules(pm.regex?.localPost || pm.regex?.local_post || []),
|
||||
remotePre: mapReplacementRules(pm.regex?.remotePre || pm.regex?.remote_pre || []),
|
||||
remotePost: mapReplacementRules(pm.regex?.remotePost || pm.regex?.remote_post || [])
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Helper function to convert PathMappingConfig to API format
|
||||
const pathMappingToApi = (config: PathMappingConfig) => {
|
||||
const rulesToApi = (rules: ReplacementRule[]) =>
|
||||
rules.map(({ id, search, replace }) => ({ id, search, replace }));
|
||||
|
||||
return {
|
||||
mode: config.mode,
|
||||
simple: rulesToApi(config.simple),
|
||||
regex: {
|
||||
local_pre: rulesToApi(config.regex.localPre),
|
||||
local_post: rulesToApi(config.regex.localPost),
|
||||
remote_pre: rulesToApi(config.regex.remotePre),
|
||||
remote_post: rulesToApi(config.regex.remotePost)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const apiService = {
|
||||
async getSettings(): Promise<ApiResponse<{ strategy: SyncStrategy; regex: RegexReplacement[]; connection: PlexConnectionSettings; localPath: string }>> {
|
||||
async getSettings(): Promise<ApiResponse<{ strategy: SyncStrategy; pathMapping: PathMappingConfig; connection: PlexConnectionSettings; localPath: string }>> {
|
||||
const response = await fetch(`${API_BASE}/api/settings`);
|
||||
const result = await handleResponse<any>(response);
|
||||
if (result.status === 'success') {
|
||||
const mode = result.data.sync_mode as string;
|
||||
const strategy = MODE_TO_STRATEGY[mode] || SyncStrategy.LOCAL_OVERWRITE;
|
||||
const regex = mapRegexRules(result.data.path_rules || []);
|
||||
const pathMapping = mapPathMappingConfig(result.data);
|
||||
const connection: PlexConnectionSettings = {
|
||||
protocol: (result.data.scheme as 'http' | 'https') || 'https',
|
||||
address: result.data.server_url || '',
|
||||
@@ -63,9 +111,9 @@ export const apiService = {
|
||||
token: result.data.token || '',
|
||||
libraryName: result.data.library_name || '',
|
||||
};
|
||||
return { status: 'success', data: { strategy, regex, connection, localPath: result.data.local_path || '' } };
|
||||
return { status: 'success', data: { strategy, pathMapping, connection, localPath: result.data.local_path || '' } };
|
||||
}
|
||||
return result as ApiResponse<any> as ApiResponse<{ strategy: SyncStrategy; regex: RegexReplacement[]; connection: PlexConnectionSettings; localPath: string }>;
|
||||
return result as ApiResponse<any> as ApiResponse<{ strategy: SyncStrategy; pathMapping: PathMappingConfig; connection: PlexConnectionSettings; localPath: string }>;
|
||||
},
|
||||
|
||||
async updateSyncStrategy(strategy: SyncStrategy): Promise<ApiResponse<{ sync_mode: string }>> {
|
||||
@@ -78,9 +126,9 @@ export const apiService = {
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async saveRegexRules(replacements: RegexReplacement[]): Promise<ApiResponse<{ rules: RegexReplacement[] }>> {
|
||||
const payload = { rules: replacements.map(({ pattern, replacement }) => ({ pattern, replacement })) };
|
||||
const response = await fetch(`${API_BASE}/api/settings/regex-rules`, {
|
||||
async savePathMapping(config: PathMappingConfig): Promise<ApiResponse<null>> {
|
||||
const payload = pathMappingToApi(config);
|
||||
const response = await fetch(`${API_BASE}/api/settings/path-mapping`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
@@ -97,6 +145,20 @@ export const apiService = {
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async getScheduleSettings(): Promise<ApiResponse<ScheduleSettings & { nextRun?: string }>> {
|
||||
const response = await fetch(`${API_BASE}/api/schedule`);
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async saveScheduleSettings(settings: ScheduleSettings): Promise<ApiResponse<null>> {
|
||||
const response = await fetch(`${API_BASE}/api/schedule`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async getPlaylists(serverType: ServerType, signal?: AbortSignal, localPath?: string): Promise<ApiResponse<Playlist[]>> {
|
||||
const params = new URLSearchParams({ server: serverType.toLowerCase() });
|
||||
if (serverType === ServerType.LOCAL && localPath) {
|
||||
@@ -156,7 +218,7 @@ export const apiService = {
|
||||
return result as ApiResponse<{ token: string; serverInfo: PlexServerConnection }>;
|
||||
},
|
||||
|
||||
async syncPlaylists(strategy: SyncStrategy, _regexRules: RegexReplacement[], localPath?: string): Promise<ApiResponse<null>> {
|
||||
async syncPlaylists(strategy: SyncStrategy, _pathMapping: PathMappingConfig, localPath?: string): Promise<ApiResponse<null>> {
|
||||
const response = await fetch(`${API_BASE}/api/sync`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -167,4 +229,36 @@ export const apiService = {
|
||||
});
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async getSyncStatus(): Promise<ApiResponse<{ is_syncing: boolean; last_sync_time: string | null; status: string; error: string | null }>> {
|
||||
const response = await fetch(`${API_BASE}/api/sync/status`);
|
||||
return handleResponse(response);
|
||||
},
|
||||
|
||||
async getBackupSettings(): Promise<ApiResponse<BackupSettings>> {
|
||||
const response = await fetch(`${API_BASE}/api/backup/settings`);
|
||||
const result = await handleResponse<any>(response);
|
||||
if (result.status === 'success') {
|
||||
return {
|
||||
status: 'success',
|
||||
data: {
|
||||
enabled: result.data.enabled ?? false,
|
||||
retentionCount: result.data.retention_count ?? 5,
|
||||
},
|
||||
};
|
||||
}
|
||||
return result as ApiResponse<BackupSettings>;
|
||||
},
|
||||
|
||||
async saveBackupSettings(settings: BackupSettings): Promise<ApiResponse<null>> {
|
||||
const response = await fetch(`${API_BASE}/api/backup/settings`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
enabled: settings.enabled,
|
||||
retention_count: settings.retentionCount,
|
||||
}),
|
||||
});
|
||||
return handleResponse(response);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { en } from './locales/en';
|
||||
import { es } from './locales/es';
|
||||
import { zh as chs } from './locales/zh';
|
||||
import { cht } from './locales/cht';
|
||||
|
||||
export const translations = {
|
||||
en,
|
||||
es,
|
||||
chs,
|
||||
cht,
|
||||
};
|
||||
|
||||
export type Language = keyof typeof translations;
|
||||
export type TranslationStructure = typeof en;
|
||||
@@ -34,12 +34,57 @@ export enum SyncState {
|
||||
ERROR = 'ERROR'
|
||||
}
|
||||
|
||||
export interface ReplacementRule {
|
||||
id: string;
|
||||
search: string;
|
||||
replace: string;
|
||||
}
|
||||
|
||||
export interface PathMappingRules {
|
||||
localPre: ReplacementRule[];
|
||||
localPost: ReplacementRule[];
|
||||
remotePre: ReplacementRule[];
|
||||
remotePost: ReplacementRule[];
|
||||
}
|
||||
|
||||
export enum PathMappingMode {
|
||||
SIMPLE = 'SIMPLE',
|
||||
REGEX = 'REGEX'
|
||||
}
|
||||
|
||||
export interface PathMappingConfig {
|
||||
mode: PathMappingMode;
|
||||
simple: ReplacementRule[];
|
||||
regex: PathMappingRules;
|
||||
}
|
||||
|
||||
export interface BackupSettings {
|
||||
enabled: boolean;
|
||||
retentionCount: number;
|
||||
}
|
||||
|
||||
export interface RegexReplacement {
|
||||
id: string;
|
||||
pattern: string;
|
||||
replacement: string;
|
||||
}
|
||||
|
||||
export enum ScheduleMode {
|
||||
DISABLED = 'DISABLED',
|
||||
CRON = 'CRON',
|
||||
DAILY = 'DAILY',
|
||||
WEEKLY = 'WEEKLY'
|
||||
}
|
||||
|
||||
export interface ScheduleSettings {
|
||||
mode: ScheduleMode;
|
||||
cronExpression: string;
|
||||
dailyTime: string;
|
||||
weeklyDays: number[]; // 0 = Sunday, 1 = Monday, etc.
|
||||
weeklyTime: string;
|
||||
autoWatch: boolean;
|
||||
}
|
||||
|
||||
export interface PlexLibrary {
|
||||
id: string;
|
||||
title: string;
|
||||
|
||||
@@ -4,3 +4,5 @@ jinja2
|
||||
python-multipart
|
||||
plexapi
|
||||
merge3
|
||||
apscheduler
|
||||
watchdog
|
||||
|
||||
+329
-33
@@ -1,5 +1,6 @@
|
||||
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { Playlist, ServerType, SyncStrategy, PlexServerConnection, RegexReplacement, SyncState } from './types';
|
||||
import { Playlist, ServerType, SyncStrategy, PlexServerConnection, PathMappingConfig, PathMappingMode, SyncState, ScheduleSettings, ScheduleMode, BackupSettings } from './types';
|
||||
import { apiService } from './services/api';
|
||||
import {
|
||||
STRIPE_BASE_SPEED,
|
||||
@@ -15,7 +16,8 @@ import { SYNC_BANNER_PADDING_X, SYNC_BANNER_PADDING_Y, SYNC_BANNER_MIN_WIDTH } f
|
||||
import ServerPanel from './components/ServerPanel';
|
||||
import StrategySelector from './components/StrategySelector';
|
||||
import ConnectionModal from './components/ConnectionModal';
|
||||
import { ArrowLeftRight, ShieldCheck, X, Server, ServerOff } from 'lucide-react';
|
||||
import { ArrowLeftRight, ShieldCheck, X, Server, ServerOff, Clock, Eye, EyeOff, Type, Code2, Archive, Languages } from 'lucide-react';
|
||||
import { useLanguage } from './LanguageContext';
|
||||
|
||||
interface Toast {
|
||||
id: number;
|
||||
@@ -31,7 +33,7 @@ const useStripeAnimation = (syncState: SyncState) => {
|
||||
const rightYellowRef = useRef<HTMLDivElement>(null);
|
||||
const rightGreenRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const requestRef = useRef<number>();
|
||||
const requestRef = useRef<number | undefined>(undefined);
|
||||
const lastTimeRef = useRef<number>(0);
|
||||
const offsetRef = useRef<number>(0);
|
||||
|
||||
@@ -112,6 +114,7 @@ const useStripeAnimation = (syncState: SyncState) => {
|
||||
};
|
||||
|
||||
const App: React.FC = () => {
|
||||
const { t, language, setLanguage } = useLanguage();
|
||||
const [localPlaylists, setLocalPlaylists] = useState<Playlist[]>([]);
|
||||
const [cloudPlaylists, setCloudPlaylists] = useState<Playlist[]>([]);
|
||||
const [cloudServerInfo, setCloudServerInfo] = useState<PlexServerConnection | undefined>(undefined);
|
||||
@@ -131,12 +134,38 @@ const App: React.FC = () => {
|
||||
|
||||
// Connection Modal State
|
||||
const [isConnectionModalOpen, setIsConnectionModalOpen] = useState(false);
|
||||
const [isLangMenuOpen, setIsLangMenuOpen] = useState(false);
|
||||
|
||||
// Strategy State
|
||||
const [currentStrategy, setCurrentStrategy] = useState<SyncStrategy>(SyncStrategy.LOCAL_OVERWRITE);
|
||||
|
||||
// Regex State
|
||||
const [regexReplacements, setRegexReplacements] = useState<RegexReplacement[]>([]);
|
||||
// Path Mapping State (Includes Simple and Regex Rules)
|
||||
const [pathMappingConfig, setPathMappingConfig] = useState<PathMappingConfig>({
|
||||
mode: PathMappingMode.SIMPLE,
|
||||
simple: [],
|
||||
regex: {
|
||||
localPre: [],
|
||||
localPost: [],
|
||||
remotePre: [],
|
||||
remotePost: []
|
||||
}
|
||||
});
|
||||
|
||||
// Schedule State
|
||||
const [scheduleSettings, setScheduleSettings] = useState<ScheduleSettings>({
|
||||
mode: ScheduleMode.DISABLED,
|
||||
cronExpression: '',
|
||||
dailyTime: '02:00',
|
||||
weeklyDays: [0], // Sunday
|
||||
weeklyTime: '03:00',
|
||||
autoWatch: false
|
||||
});
|
||||
|
||||
// Backup State
|
||||
const [backupSettings, setBackupSettings] = useState<BackupSettings>({
|
||||
enabled: false,
|
||||
retentionCount: 5
|
||||
});
|
||||
|
||||
// Toast Notification System
|
||||
const [toasts, setToasts] = useState<Toast[]>([]);
|
||||
@@ -225,7 +254,7 @@ const App: React.FC = () => {
|
||||
localAbortRef.current.abort();
|
||||
localAbortRef.current = null;
|
||||
setLoadingLocal(false);
|
||||
addToast("Local refresh cancelled.");
|
||||
addToast(t('toasts.localRefreshCancelled'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -259,7 +288,7 @@ const App: React.FC = () => {
|
||||
cloudAbortRef.current.abort();
|
||||
cloudAbortRef.current = null;
|
||||
setLoadingCloud(false);
|
||||
addToast("Cloud refresh cancelled.");
|
||||
addToast(t('toasts.cloudRefreshCancelled'));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -277,13 +306,47 @@ const App: React.FC = () => {
|
||||
// Handle Strategy Change
|
||||
const handleStrategyChange = (strategy: SyncStrategy, label: string) => {
|
||||
setCurrentStrategy(strategy);
|
||||
addToast(`Selected strategy "${label}" has been saved.`);
|
||||
addToast(t('toasts.strategySaved', { strategy: label }));
|
||||
};
|
||||
|
||||
// Handle Regex Save
|
||||
const handleSaveRegex = (replacements: RegexReplacement[]) => {
|
||||
setRegexReplacements(replacements);
|
||||
addToast('Regex preprocessing rules have been saved.');
|
||||
// Handle Path Mapping Save
|
||||
const handleSavePathMapping = (config: PathMappingConfig) => {
|
||||
setPathMappingConfig(config);
|
||||
addToast(t('toasts.mappingSaved'));
|
||||
};
|
||||
|
||||
// Handle Backup Settings Save
|
||||
const handleSaveBackupSettings = async (settings: BackupSettings) => {
|
||||
const result = await apiService.saveBackupSettings(settings);
|
||||
if (result.status === 'success') {
|
||||
setBackupSettings(settings);
|
||||
addToast(t('toasts.backupSaved'));
|
||||
} else {
|
||||
addToast(t('toasts.backupFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
// Handle Schedule Save
|
||||
const handleSaveSchedule = async (settings: ScheduleSettings): Promise<boolean> => {
|
||||
// Call API (validation happens in Mock)
|
||||
const result = await apiService.saveScheduleSettings(settings);
|
||||
|
||||
if (result.status === 'success') {
|
||||
// Only update local state if successful
|
||||
setScheduleSettings(settings);
|
||||
|
||||
if (settings.mode === ScheduleMode.DISABLED) {
|
||||
addToast(t('toasts.scheduleDisabled'));
|
||||
} else if (settings.mode === ScheduleMode.CRON && settings.cronExpression.trim() === '') {
|
||||
addToast(t('toasts.scheduleEmpty'));
|
||||
} else {
|
||||
addToast(t('toasts.scheduleStarted'));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
addToast(result.message || t('toasts.scheduleFailed'));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Handle Sync Trigger
|
||||
@@ -293,7 +356,7 @@ const App: React.FC = () => {
|
||||
setSyncState(SyncState.SYNCING);
|
||||
|
||||
// Note: We deliberately do not clear playlists here to keep UI populated during sync
|
||||
const result = await apiService.syncPlaylists(currentStrategy, regexReplacements);
|
||||
const result = await apiService.syncPlaylists(currentStrategy, pathMappingConfig);
|
||||
|
||||
if (result.status === 'success') {
|
||||
// Transition to Success state
|
||||
@@ -316,7 +379,7 @@ const App: React.FC = () => {
|
||||
|
||||
} else {
|
||||
setSyncState(SyncState.ERROR);
|
||||
addToast("Sync failed. Please check connection.");
|
||||
addToast(t('toasts.syncFailed'));
|
||||
setTimeout(() => setSyncState(SyncState.IDLE), SYNC_ERROR_RESET_MS);
|
||||
}
|
||||
};
|
||||
@@ -346,6 +409,160 @@ const App: React.FC = () => {
|
||||
|
||||
const isConnected = cloudServerInfo?.isConnected;
|
||||
|
||||
// Helper: Calculate Next Run Info
|
||||
const getScheduleDisplayInfo = (settings: ScheduleSettings) => {
|
||||
const result = {
|
||||
label: t('schedule.schedule'),
|
||||
value: t('schedule.notConfigured'),
|
||||
active: false,
|
||||
autoWatch: settings.autoWatch
|
||||
};
|
||||
|
||||
if (settings.mode === ScheduleMode.DISABLED) {
|
||||
result.label = t('dashboard.autoSync');
|
||||
result.value = t('common.disabled');
|
||||
return result;
|
||||
}
|
||||
|
||||
if (settings.mode === ScheduleMode.CRON) {
|
||||
result.label = t('schedule.cron');
|
||||
result.value = settings.cronExpression || t('server.waiting');
|
||||
result.active = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
let nextRun: Date | null = null;
|
||||
let timeStr = '';
|
||||
|
||||
if (settings.mode === ScheduleMode.DAILY) {
|
||||
const [h, m] = settings.dailyTime.split(':').map(Number);
|
||||
const target = new Date();
|
||||
target.setHours(h, m, 0, 0);
|
||||
timeStr = settings.dailyTime;
|
||||
|
||||
if (now < target) {
|
||||
nextRun = target;
|
||||
} else {
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
tomorrow.setHours(h, m, 0, 0);
|
||||
nextRun = tomorrow;
|
||||
}
|
||||
} else if (settings.mode === ScheduleMode.WEEKLY) {
|
||||
timeStr = settings.weeklyTime;
|
||||
const [h, m] = settings.weeklyTime.split(':').map(Number);
|
||||
const activeDays = [...settings.weeklyDays].sort();
|
||||
|
||||
if (activeDays.length === 0) {
|
||||
result.label = t('schedule.weekly');
|
||||
result.value = t('common.none');
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check rest of today
|
||||
if (activeDays.includes(now.getDay())) {
|
||||
const todayTarget = new Date();
|
||||
todayTarget.setHours(h, m, 0, 0);
|
||||
if (todayTarget > now) {
|
||||
nextRun = todayTarget;
|
||||
}
|
||||
}
|
||||
|
||||
// Check future days
|
||||
if (!nextRun) {
|
||||
for (let i = 1; i <= 7; i++) {
|
||||
const nextDayIndex = (now.getDay() + i) % 7;
|
||||
if (activeDays.includes(nextDayIndex)) {
|
||||
const d = new Date();
|
||||
d.setDate(now.getDate() + i);
|
||||
d.setHours(h, m, 0, 0);
|
||||
nextRun = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nextRun) {
|
||||
// Format logic
|
||||
const isToday = nextRun.getDate() === now.getDate() && nextRun.getMonth() === now.getMonth();
|
||||
const isTomorrow = new Date(now.getTime() + 86400000).getDate() === nextRun.getDate();
|
||||
|
||||
let dateStr = '';
|
||||
if (isToday) dateStr = t('schedule.today');
|
||||
else if (isTomorrow) dateStr = t('schedule.tomorrow');
|
||||
else dateStr = days[nextRun.getDay()];
|
||||
|
||||
result.label = settings.mode === ScheduleMode.DAILY ? t('schedule.daily') : t('schedule.weekly');
|
||||
result.value = `${dateStr} @ ${timeStr}`;
|
||||
result.active = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const scheduleInfo = getScheduleDisplayInfo(scheduleSettings);
|
||||
|
||||
// Helper: Calculate Path Mapping Info
|
||||
const getPathMappingDisplayInfo = (config: PathMappingConfig) => {
|
||||
let count = 0;
|
||||
let modeLabel = '';
|
||||
let Icon = Type;
|
||||
|
||||
if (config.mode === PathMappingMode.SIMPLE) {
|
||||
modeLabel = t('common.none').replace('None', 'Simple'); // Fallback hack if simple not in dict, but it is in mapping
|
||||
modeLabel = 'Simple';
|
||||
count = config.simple.length;
|
||||
Icon = Type;
|
||||
} else {
|
||||
modeLabel = 'Regex';
|
||||
count = config.regex.localPre.length +
|
||||
config.regex.localPost.length +
|
||||
config.regex.remotePre.length +
|
||||
config.regex.remotePost.length;
|
||||
Icon = Code2;
|
||||
}
|
||||
|
||||
if (count === 0) {
|
||||
return {
|
||||
label: t('dashboard.mapping'),
|
||||
value: t('dashboard.notSet'),
|
||||
active: false,
|
||||
Icon: Icon
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
label: t('dashboard.mapping'),
|
||||
value: `${modeLabel} (${count})`,
|
||||
active: true,
|
||||
Icon: Icon
|
||||
};
|
||||
};
|
||||
|
||||
const pathMappingInfo = getPathMappingDisplayInfo(pathMappingConfig);
|
||||
|
||||
// Helper: Calculate Backup Info
|
||||
const getBackupDisplayInfo = (settings: BackupSettings) => {
|
||||
if (!settings.enabled) {
|
||||
return {
|
||||
label: t('dashboard.backup'),
|
||||
value: t('common.disabled'),
|
||||
active: false
|
||||
};
|
||||
}
|
||||
return {
|
||||
label: t('dashboard.backup'),
|
||||
value: t('dashboard.keep', { count: settings.retentionCount }),
|
||||
active: true
|
||||
};
|
||||
};
|
||||
|
||||
const backupInfo = getBackupDisplayInfo(backupSettings);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-gray-900 text-gray-100 font-sans overflow-hidden bg-[radial-gradient(ellipse_at_top,_var(--tw-gradient-stops))] from-gray-800 via-gray-900 to-black">
|
||||
|
||||
@@ -411,28 +628,103 @@ const App: React.FC = () => {
|
||||
|
||||
{syncState === SyncState.IDLE ? (
|
||||
<>
|
||||
{/* Normal Toolbar */}
|
||||
{/* Normal Toolbar Left */}
|
||||
<div className="flex items-center space-x-3">
|
||||
<div className="p-1.5 rounded-lg shadow-lg bg-gradient-to-br from-plex-orange to-yellow-600 text-gray-900 shadow-plex-orange/20">
|
||||
<ArrowLeftRight size={24} strokeWidth={2.5} />
|
||||
</div>
|
||||
<h1 className="text-xl font-bold tracking-tight text-white">
|
||||
Plex<span className="text-plex-orange">Sync</span>
|
||||
<span className="text-plex-orange">PMS</span> Playlist Sync
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Connection Status Button */}
|
||||
<button
|
||||
onClick={() => setIsConnectionModalOpen(true)}
|
||||
className={`flex items-center justify-center w-9 h-9 rounded-full border transition-all duration-300 hover:scale-105 active:scale-95 shadow-md
|
||||
${isConnected
|
||||
? "bg-green-500/10 border-green-500/50 text-green-400 hover:bg-green-500/20 hover:shadow-green-500/20"
|
||||
: "bg-red-500/10 border-red-500/50 text-red-400 hover:bg-red-500/20 hover:shadow-red-500/20"
|
||||
}`}
|
||||
title={isConnected ? "Connected to Plex" : "Disconnected"}
|
||||
>
|
||||
{isConnected ? <Server size={18} /> : <ServerOff size={18} />}
|
||||
</button>
|
||||
{/* Normal Toolbar Right */}
|
||||
<div className="flex items-center gap-4">
|
||||
|
||||
{/* Unified Status Dock */}
|
||||
<div className="hidden md:flex items-center bg-gray-900/40 border border-gray-700/50 rounded-lg p-1 mr-2 backdrop-blur-sm shadow-sm transition-all hover:bg-gray-900/60 hover:border-gray-600/50">
|
||||
|
||||
{/* Path Mapping Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 border-r border-gray-700/30 min-w-[90px] group/item">
|
||||
<span className="text-[9px] font-bold text-gray-500 uppercase tracking-widest group-hover/item:text-gray-400 transition-colors">{pathMappingInfo.label}</span>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium ${pathMappingInfo.active ? 'text-blue-400' : 'text-gray-600'}`}>
|
||||
<pathMappingInfo.Icon size={12} strokeWidth={2.5} />
|
||||
<span className="truncate">{pathMappingInfo.value}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Backup Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 border-r border-gray-700/30 min-w-[90px] group/item">
|
||||
<span className="text-[9px] font-bold text-gray-500 uppercase tracking-widest group-hover/item:text-gray-400 transition-colors">{backupInfo.label}</span>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium ${backupInfo.active ? 'text-indigo-400' : 'text-gray-600'}`}>
|
||||
<Archive size={12} strokeWidth={2.5} />
|
||||
<span>{backupInfo.active ? t('dashboard.retain', { count: backupSettings.retentionCount }) : backupInfo.value}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Schedule Section */}
|
||||
<div className="flex flex-col px-3 py-0.5 min-w-[140px] group/item">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[9px] font-bold text-gray-500 uppercase tracking-widest group-hover/item:text-gray-400 transition-colors">{t('dashboard.autoSync')}</span>
|
||||
{/* Watch Indicator Badge */}
|
||||
<div
|
||||
className={`flex items-center gap-1 px-1 rounded-[2px] transition-colors ${scheduleInfo.autoWatch ? 'text-plex-orange bg-plex-orange/10' : 'text-gray-700 bg-gray-800'}`}
|
||||
title={scheduleInfo.autoWatch ? t('dashboard.watchModeActive') : t('dashboard.watchModeDisabled')}
|
||||
>
|
||||
{scheduleInfo.autoWatch ? <Eye size={9} /> : <EyeOff size={9} />}
|
||||
<span className="text-[8px] font-bold uppercase">{t('dashboard.watch')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={`flex items-center gap-1.5 text-xs font-medium mt-0.5 ${scheduleInfo.active ? 'text-green-400' : 'text-gray-600'}`}>
|
||||
<Clock size={12} strokeWidth={2.5} />
|
||||
<span className="truncate max-w-[120px]">{scheduleInfo.active ? scheduleInfo.value : t('common.disabled')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Language Switcher */}
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setIsLangMenuOpen(!isLangMenuOpen)}
|
||||
className="flex items-center justify-center w-9 h-9 rounded-full border border-gray-700 bg-gray-800/50 text-gray-400 hover:text-white hover:bg-gray-700 transition-all"
|
||||
title="Switch Language"
|
||||
>
|
||||
<Languages size={18} />
|
||||
</button>
|
||||
{isLangMenuOpen && (
|
||||
<>
|
||||
<div className="fixed inset-0 z-40" onClick={() => setIsLangMenuOpen(false)}></div>
|
||||
<div className="absolute right-0 top-full mt-2 w-32 bg-gray-800 border border-gray-700 rounded-lg shadow-xl z-50 overflow-hidden">
|
||||
<button
|
||||
onClick={() => { setLanguage('en'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'en' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
English
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setLanguage('es'); setIsLangMenuOpen(false); }}
|
||||
className={`w-full px-4 py-2 text-sm text-left hover:bg-gray-700 transition-colors ${language === 'es' ? 'text-plex-orange font-bold' : 'text-gray-300'}`}
|
||||
>
|
||||
Español
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Connection Status Button */}
|
||||
<button
|
||||
onClick={() => setIsConnectionModalOpen(true)}
|
||||
className={`flex items-center justify-center w-9 h-9 rounded-full border transition-all duration-300 hover:scale-105 active:scale-95 shadow-md
|
||||
${isConnected
|
||||
? "bg-green-500/10 border-green-500/50 text-green-400 hover:bg-green-500/20 hover:shadow-green-500/20"
|
||||
: "bg-red-500/10 border-red-500/50 text-red-400 hover:bg-red-500/20 hover:shadow-red-500/20"
|
||||
}`}
|
||||
title={isConnected ? t('dashboard.connected') : t('dashboard.disconnected')}
|
||||
>
|
||||
{isConnected ? <Server size={18} /> : <ServerOff size={18} />}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
/* Syncing / Success Text Banner */
|
||||
@@ -445,7 +737,7 @@ const App: React.FC = () => {
|
||||
}}
|
||||
>
|
||||
<h1 className={`text-xl md:text-2xl font-black tracking-[0.2em] uppercase whitespace-nowrap transition-colors duration-300 ${syncState === SyncState.SUCCESS ? 'text-[#22c55e]' : 'text-[#F59E0B]'}`}>
|
||||
{syncState === SyncState.SYNCING ? 'SYNCHRONIZING' : 'SYNC COMPLETE'}
|
||||
{syncState === SyncState.SYNCING ? t('dashboard.synchronizing') : t('dashboard.syncComplete')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
@@ -502,8 +794,12 @@ const App: React.FC = () => {
|
||||
<StrategySelector
|
||||
currentStrategy={currentStrategy}
|
||||
onSelect={handleStrategyChange}
|
||||
savedRegexReplacements={regexReplacements}
|
||||
onSaveRegex={handleSaveRegex}
|
||||
savedPathMapping={pathMappingConfig}
|
||||
onSavePathMapping={handleSavePathMapping}
|
||||
savedBackup={backupSettings}
|
||||
onSaveBackup={handleSaveBackupSettings}
|
||||
savedSchedule={scheduleSettings}
|
||||
onSaveSchedule={handleSaveSchedule}
|
||||
syncState={syncState}
|
||||
onSync={handleSyncTrigger}
|
||||
/>
|
||||
@@ -526,7 +822,7 @@ const App: React.FC = () => {
|
||||
|
||||
{/* Footer */}
|
||||
<footer className="flex-none py-4 text-center text-xs text-gray-600 border-t border-white/5 bg-gray-900/50 backdrop-blur">
|
||||
<p>© {new Date().getFullYear()} PlexSync Manager. Connected to Docker backend.</p>
|
||||
<p>{t('app.footer', { year: new Date().getFullYear() })}</p>
|
||||
</footer>
|
||||
|
||||
{/* Modals */}
|
||||
@@ -540,4 +836,4 @@ const App: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
export default App;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';
|
||||
import { translations, Language, TranslationStructure } from './translations';
|
||||
|
||||
interface LanguageContextProps {
|
||||
language: Language;
|
||||
setLanguage: (lang: Language) => void;
|
||||
t: (path: string, params?: Record<string, string | number>) => string;
|
||||
}
|
||||
|
||||
const LanguageContext = createContext<LanguageContextProps | undefined>(undefined);
|
||||
|
||||
export const LanguageProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const [language, setLanguageState] = useState<Language>('en');
|
||||
|
||||
useEffect(() => {
|
||||
const savedLang = localStorage.getItem('plexsync-language') as Language;
|
||||
if (savedLang && translations[savedLang]) {
|
||||
setLanguageState(savedLang);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const setLanguage = (lang: Language) => {
|
||||
setLanguageState(lang);
|
||||
localStorage.setItem('plexsync-language', lang);
|
||||
};
|
||||
|
||||
const t = (path: string, params?: Record<string, string | number>): string => {
|
||||
const keys = path.split('.');
|
||||
let current: any = translations[language];
|
||||
|
||||
for (const key of keys) {
|
||||
if (current[key] === undefined) {
|
||||
console.warn(`Missing translation for key: ${path} in language: ${language}`);
|
||||
return path;
|
||||
}
|
||||
current = current[key];
|
||||
}
|
||||
|
||||
let text = current as string;
|
||||
|
||||
if (params) {
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
text = text.replace(`{${key}}`, String(value));
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
};
|
||||
|
||||
return (
|
||||
<LanguageContext.Provider value={{ language, setLanguage, t }}>
|
||||
{children}
|
||||
</LanguageContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useLanguage = () => {
|
||||
const context = useContext(LanguageContext);
|
||||
if (!context) {
|
||||
throw new Error('useLanguage must be used within a LanguageProvider');
|
||||
}
|
||||
return context;
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||
import { PlexConnectionSettings, PlexServerConnection, PlexLibrary } from '../types';
|
||||
import { apiService } from '../services/api';
|
||||
import { X, Server, Lock, User, Key, Globe, Eye, EyeOff, CheckCircle, Library, ChevronDown, ChevronRight, Settings, Loader2 } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
|
||||
interface ConnectionModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -12,6 +13,7 @@ interface ConnectionModalProps {
|
||||
}
|
||||
|
||||
const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onConnectSuccess, onShowMessage }) => {
|
||||
const { t } = useLanguage();
|
||||
const [formData, setFormData] = useState<PlexConnectionSettings>({
|
||||
protocol: 'http',
|
||||
address: '',
|
||||
@@ -71,7 +73,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
const updatedInfo = { ...connectedServerInfo, libraryName: lib.title };
|
||||
setConnectedServerInfo(updatedInfo);
|
||||
onConnectSuccess(updatedInfo);
|
||||
onShowMessage(`Library switched to ${lib.title}`);
|
||||
onShowMessage(t('toasts.librarySwitched', { library: lib.title }));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -90,7 +92,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
abortControllerRef.current.abort();
|
||||
abortControllerRef.current = null;
|
||||
setIsConnecting(false);
|
||||
setError("Connection cancelled by user.");
|
||||
setError(t('toasts.connectionCancelled'));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -119,7 +121,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
const info = result.data.serverInfo;
|
||||
setConnectedServerInfo(info);
|
||||
onShowMessage(`Successfully connected to ${info.name || 'Plex Server'}`);
|
||||
onShowMessage(t('toasts.connectedTo', { name: info.name || 'Plex Server' }));
|
||||
|
||||
const libs = info.libraries || [];
|
||||
setLibraries(libs);
|
||||
@@ -134,21 +136,27 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
onConnectSuccess(info);
|
||||
}
|
||||
} else {
|
||||
setError(result.message || "Connection failed");
|
||||
setError(result.message || t('server.connectionFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const isConnected = !!connectedServerInfo;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
|
||||
<div className="bg-gray-900 border border-gray-700 rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200 flex flex-col max-h-[90vh]">
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="bg-gray-900 border border-gray-700 rounded-xl shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200 flex flex-col max-h-[90vh]"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
|
||||
{/* Header */}
|
||||
<div className="px-6 py-4 bg-gray-800 border-b border-gray-700 flex items-center justify-between flex-none">
|
||||
<h3 className="text-lg font-semibold text-white flex items-center gap-2">
|
||||
<Server size={18} className={isConnected ? "text-green-400" : "text-plex-orange"} />
|
||||
{isConnected ? 'Server Connected' : 'Connect Plex Server'}
|
||||
{isConnected ? t('connection.titleConnected') : t('connection.titleConnect')}
|
||||
</h3>
|
||||
<button onClick={onClose} className="text-gray-400 hover:text-white transition-colors">
|
||||
<X size={20} />
|
||||
@@ -167,7 +175,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
{/* Server Connection */}
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">Server Details</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">{t('connection.serverDetails')}</label>
|
||||
<div className="grid grid-cols-4 gap-3">
|
||||
<div className="col-span-1">
|
||||
<select
|
||||
@@ -191,7 +199,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
name="address"
|
||||
required
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="IP Address or Domain"
|
||||
placeholder={t('connection.address')}
|
||||
value={formData.address}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -205,7 +213,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="port"
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="Port (e.g. 32400)"
|
||||
placeholder={t('connection.port')}
|
||||
value={formData.port}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 px-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -217,7 +225,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
|
||||
{/* Authentication */}
|
||||
<div className="space-y-3">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">Authentication</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider">{t('connection.authentication')}</label>
|
||||
|
||||
{/* Token */}
|
||||
<div className="relative">
|
||||
@@ -228,7 +236,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="token"
|
||||
disabled={isConnected || isConnecting}
|
||||
placeholder="X-Plex-Token (Optional)"
|
||||
placeholder={t('connection.token')}
|
||||
value={formData.token}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 bg-gray-800 border border-gray-600 rounded-md text-sm text-white placeholder-gray-500 focus:border-plex-orange focus:outline-none focus:ring-1 focus:ring-plex-orange transition-all font-mono ${isConnected ? 'opacity-60 cursor-not-allowed' : ''}`}
|
||||
@@ -250,7 +258,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type="text"
|
||||
name="username"
|
||||
disabled={isTokenProvided || isConnecting}
|
||||
placeholder="Username / Email"
|
||||
placeholder={t('connection.username')}
|
||||
value={formData.username}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-3 rounded-md text-sm transition-all focus:outline-none ${disabledInputClass}`}
|
||||
@@ -266,7 +274,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
type={showPassword ? "text" : "password"}
|
||||
name="password"
|
||||
disabled={isTokenProvided || isConnecting}
|
||||
placeholder="Password"
|
||||
placeholder={t('connection.password')}
|
||||
value={formData.password}
|
||||
onChange={handleChange}
|
||||
className={`w-full h-10 pl-9 pr-10 rounded-md text-sm transition-all focus:outline-none ${disabledInputClass}`}
|
||||
@@ -294,7 +302,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<Settings size={14} />
|
||||
<span>Advanced Options</span>
|
||||
<span>{t('connection.advanced')}</span>
|
||||
</div>
|
||||
{showAdvanced ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
||||
</button>
|
||||
@@ -302,7 +310,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{showAdvanced && (
|
||||
<div className="p-3 bg-gray-900/50 space-y-3 animate-in slide-in-from-top-2">
|
||||
<div>
|
||||
<label className="text-xs text-gray-500 mb-1 block">Connection Timeout (Seconds)</label>
|
||||
<label className="text-xs text-gray-500 mb-1 block">{t('connection.timeout')}</label>
|
||||
<input
|
||||
type="number"
|
||||
min="1"
|
||||
@@ -331,15 +339,15 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{isConnecting ? (
|
||||
<>
|
||||
<Loader2 size={16} className="animate-spin" />
|
||||
<span>Connecting... <span className="opacity-75 font-normal ml-1">(Cancel)</span></span>
|
||||
<span>{t('connection.connecting')} <span className="opacity-75 font-normal ml-1">({t('common.cancel')})</span></span>
|
||||
</>
|
||||
) : 'Connect Server'}
|
||||
) : t('connection.connectBtn')}
|
||||
</button>
|
||||
) : (
|
||||
<div className="mt-2 p-2 bg-green-500/10 border border-green-500/20 rounded-lg text-center">
|
||||
<p className="text-green-400 text-sm font-semibold flex items-center justify-center gap-2">
|
||||
<CheckCircle size={16} />
|
||||
Connected Successfully
|
||||
{t('connection.connectedSuccess')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
@@ -348,7 +356,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
{/* Library Selection - Appears after connection */}
|
||||
{isConnected && libraries.length > 0 && (
|
||||
<div className="mt-6 pt-5 border-t border-gray-700 animate-in slide-in-from-top-2 fade-in">
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider block mb-2">Select Library to Sync</label>
|
||||
<label className="text-xs font-semibold text-gray-400 uppercase tracking-wider block mb-2">{t('connection.selectLibrary')}</label>
|
||||
<div className="relative">
|
||||
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||
<Library size={14} className="text-plex-orange" />
|
||||
@@ -372,7 +380,7 @@ const ConnectionModal: React.FC<ConnectionModalProps> = ({ isOpen, onClose, onCo
|
||||
onClick={onClose}
|
||||
className="px-6 py-2 bg-gray-700 hover:bg-gray-600 text-white text-sm font-medium rounded-lg transition-colors border border-gray-600 hover:border-gray-500"
|
||||
>
|
||||
Done
|
||||
{t('common.done')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
|
||||
import React from 'react';
|
||||
import { Playlist } from '../types';
|
||||
import { Disc3, Clock } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
|
||||
interface PlaylistCardProps {
|
||||
playlist: Playlist;
|
||||
}
|
||||
|
||||
const PlaylistCard: React.FC<PlaylistCardProps> = ({ playlist }) => {
|
||||
const { t } = useLanguage();
|
||||
return (
|
||||
<div className="group flex flex-col w-full p-2.5 bg-gray-800/60 rounded-md border border-gray-700/50 hover:bg-gray-700 hover:border-plex-orange/50 transition-all duration-200 cursor-pointer shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
@@ -16,11 +19,11 @@ const PlaylistCard: React.FC<PlaylistCardProps> = ({ playlist }) => {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center mt-1.5 space-x-4 text-xs text-gray-500 group-hover:text-gray-400">
|
||||
<span className="flex items-center" title="Track Count">
|
||||
<span className="flex items-center" title={t('playlist.trackCount')}>
|
||||
<Disc3 size={12} className="mr-1.5 opacity-70" />
|
||||
{playlist.trackCount}
|
||||
</span>
|
||||
<span className="flex items-center" title="Last Updated">
|
||||
<span className="flex items-center" title={t('playlist.lastUpdated')}>
|
||||
<Clock size={12} className="mr-1.5 opacity-70" />
|
||||
{new Date(playlist.lastUpdated).toLocaleDateString()}
|
||||
</span>
|
||||
@@ -29,4 +32,4 @@ const PlaylistCard: React.FC<PlaylistCardProps> = ({ playlist }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default PlaylistCard;
|
||||
export default PlaylistCard;
|
||||
|
||||
@@ -3,6 +3,7 @@ import React from 'react';
|
||||
import { Playlist, ServerType, PlexServerConnection } from '../types';
|
||||
import PlaylistCard from './PlaylistCard';
|
||||
import { RefreshCw, Server, Cloud, WifiOff, X } from 'lucide-react';
|
||||
import { useLanguage } from '../LanguageContext';
|
||||
|
||||
interface ServerPanelProps {
|
||||
type: ServerType;
|
||||
@@ -14,6 +15,7 @@ interface ServerPanelProps {
|
||||
}
|
||||
|
||||
const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, onRefresh, onCancel, serverInfo }) => {
|
||||
const { t } = useLanguage();
|
||||
const isLocal = type === ServerType.LOCAL;
|
||||
|
||||
let Icon = isLocal ? Server : Cloud;
|
||||
@@ -28,17 +30,17 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
let displaySubtitle: React.ReactNode = null;
|
||||
|
||||
if (isLocal) {
|
||||
displayTitle = 'Local Server';
|
||||
displayTitle = t('server.local');
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-400 font-medium mt-0.5 md:mt-0 md:ml-0">
|
||||
{playlists.length} Playlists
|
||||
{t('server.playlists', { count: playlists.length })}
|
||||
</p>
|
||||
);
|
||||
} else {
|
||||
// Cloud Logic
|
||||
if (serverInfo) {
|
||||
if (serverInfo.isConnected) {
|
||||
displayTitle = serverInfo.name || 'Cloud Server';
|
||||
displayTitle = serverInfo.name || t('server.cloud');
|
||||
displaySubtitle = (
|
||||
<div className="flex items-center text-xs text-gray-300 font-medium space-x-1.5 truncate mt-0.5 md:mt-0">
|
||||
<span className="text-plex-orange truncate font-semibold">{serverInfo.libraryName}</span>
|
||||
@@ -47,20 +49,20 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
displayTitle = 'Not Connected';
|
||||
displayTitle = t('server.notConnected');
|
||||
Icon = WifiOff;
|
||||
headerColor = 'text-red-400';
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-500 font-medium mt-0.5">
|
||||
Connection failed
|
||||
{t('server.connectionFailed')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
displayTitle = 'Cloud Server';
|
||||
displayTitle = t('server.cloud');
|
||||
displaySubtitle = (
|
||||
<p className="text-xs text-gray-500 font-medium mt-0.5">
|
||||
{isLoading ? 'Connecting...' : 'Waiting...'}
|
||||
{isLoading ? t('server.connecting') : t('server.waiting')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
@@ -121,7 +123,7 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
: 'text-gray-400 hover:text-white hover:bg-white/10'
|
||||
}
|
||||
`}
|
||||
title={isLoading ? "Cancel Refresh" : "Refresh Playlists"}
|
||||
title={isLoading ? t('server.cancelRefresh') : t('server.refreshPlaylists')}
|
||||
>
|
||||
{isLoading ? (
|
||||
<div className="relative flex items-center justify-center">
|
||||
@@ -141,11 +143,11 @@ const ServerPanel: React.FC<ServerPanelProps> = ({ type, playlists, isLoading, o
|
||||
{isLoading && playlists.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-full text-gray-500 space-y-3">
|
||||
<RefreshCw size={24} className="animate-spin text-plex-orange/50" />
|
||||
<p className="text-xs font-medium tracking-wide uppercase">Syncing...</p>
|
||||
<p className="text-xs font-medium tracking-wide uppercase">{t('server.syncing')}</p>
|
||||
</div>
|
||||
) : playlists.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-full text-gray-500">
|
||||
<p className="text-sm">No playlists found.</p>
|
||||
<p className="text-sm">{t('server.noPlaylists')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2.5 md:space-y-3">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,10 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>PlexSync Manager</title>
|
||||
<title>PMS Playlist Sync</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<script>
|
||||
tailwind.config = {
|
||||
@@ -41,13 +42,13 @@
|
||||
background: #6b7280;
|
||||
}
|
||||
|
||||
/* Force native date/time pickers to use dark mode scheme */
|
||||
input[type="time"] {
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/*
|
||||
Symmetrical Diagonal Scroll Animations
|
||||
Pattern width: 40px (20px color + 20px transparent).
|
||||
Diagonal length: 40 * sqrt(2) ≈ 56.57px.
|
||||
|
||||
Left Side: Anchored to Right (Center). Moves Left (increases right offset).
|
||||
Right Side: Anchored to Left (Center). Moves Right (increases left offset).
|
||||
*/
|
||||
@keyframes scroll-out-left {
|
||||
0% { background-position: right 0 top 0; }
|
||||
@@ -64,7 +65,8 @@
|
||||
"lucide-react": "https://aistudiocdn.com/lucide-react@^0.555.0",
|
||||
"react/": "https://aistudiocdn.com/react@^19.2.0/",
|
||||
"react": "https://aistudiocdn.com/react@^19.2.0",
|
||||
"react-dom/": "https://aistudiocdn.com/react-dom@^19.2.0/"
|
||||
"react-dom/": "https://aistudiocdn.com/react-dom@^19.2.0/",
|
||||
"react-dom": "https://aistudiocdn.com/react-dom@^19.2.0"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -72,4 +74,4 @@
|
||||
<body class="bg-gray-900 text-gray-100 antialiased min-h-screen">
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import App from './App';
|
||||
import { LanguageProvider } from './LanguageContext';
|
||||
|
||||
const rootElement = document.getElementById('root');
|
||||
if (!rootElement) {
|
||||
@@ -10,6 +12,8 @@ if (!rootElement) {
|
||||
const root = ReactDOM.createRoot(rootElement);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
<LanguageProvider>
|
||||
<App />
|
||||
</LanguageProvider>
|
||||
</React.StrictMode>
|
||||
);
|
||||
);
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
export const en = {
|
||||
app: {
|
||||
// title and manager are no longer used for branding
|
||||
title: 'PlexSync',
|
||||
manager: 'Manager',
|
||||
footer: '© {year} PMS Playlist Sync. Connected to Docker backend.',
|
||||
},
|
||||
common: {
|
||||
save: 'Save',
|
||||
cancel: 'Cancel',
|
||||
revert: 'Revert',
|
||||
delete: 'Delete',
|
||||
done: 'Done',
|
||||
loading: 'Loading...',
|
||||
refresh: 'Refresh',
|
||||
close: 'Close',
|
||||
none: 'None',
|
||||
disabled: 'Disabled',
|
||||
add: 'Add',
|
||||
},
|
||||
server: {
|
||||
local: 'Local Server',
|
||||
cloud: 'Cloud Server',
|
||||
playlists: '{count} Playlists',
|
||||
notConnected: 'Not Connected',
|
||||
connectionFailed: 'Connection failed',
|
||||
connecting: 'Connecting...',
|
||||
waiting: 'Waiting...',
|
||||
syncing: 'Syncing...',
|
||||
noPlaylists: 'No playlists found.',
|
||||
cancelRefresh: 'Cancel Refresh',
|
||||
refreshPlaylists: 'Refresh Playlists',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: 'Track Count',
|
||||
lastUpdated: 'Last Updated',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: 'Mapping',
|
||||
backup: 'Backup',
|
||||
autoSync: 'Auto-Sync',
|
||||
watch: 'Watch',
|
||||
watchModeActive: 'Watch Mode: Active',
|
||||
watchModeDisabled: 'Watch Mode: Disabled',
|
||||
notSet: 'Not Set',
|
||||
retain: 'Retain: {count}',
|
||||
keep: 'Keep {count}',
|
||||
connected: 'Connected to Plex',
|
||||
disconnected: 'Disconnected',
|
||||
synchronizing: 'SYNCHRONIZING',
|
||||
syncComplete: 'SYNC COMPLETE',
|
||||
},
|
||||
strategies: {
|
||||
title: 'Sync Strategy',
|
||||
localOverwrite: {
|
||||
label: 'Local Overwrite',
|
||||
desc: 'Local playlist completely overwrites Cloud. (No Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: 'Cloud Overwrite',
|
||||
desc: 'Cloud playlist completely overwrites Local. (No Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: 'Two-way Merge (Local Priority)',
|
||||
desc: 'Merge both. Conflicts resolve to Local version.',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: 'Two-way Merge (Cloud Priority)',
|
||||
desc: 'Merge both. Conflicts resolve to Cloud version.',
|
||||
},
|
||||
syncNow: 'Sync Now',
|
||||
syncing: 'Sync in Progress...',
|
||||
saveWarning: 'Please save pending changes (Backups/Path Mapping) before syncing.',
|
||||
},
|
||||
mapping: {
|
||||
title: 'Path Mapping',
|
||||
simple: 'Simple Mapping',
|
||||
regex: 'Regex Rules',
|
||||
simpleTitle: 'Path Mapping',
|
||||
simpleSubtitle: 'Map Local paths to Cloud paths using simple string matching',
|
||||
regexPre: 'Pre-Processing (Before Sync)',
|
||||
regexPost: 'Post-Processing (After Sync / Result)',
|
||||
localPath: 'Local Path',
|
||||
cloudPath: 'Cloud Path',
|
||||
pattern: 'Pattern',
|
||||
replace: 'Replace',
|
||||
saveRules: 'Save Rules',
|
||||
noRules: 'No rules defined.',
|
||||
},
|
||||
backup: {
|
||||
title: 'Backup Retention',
|
||||
enable: 'Enable Backups',
|
||||
enableDesc: 'Create a copy before changes',
|
||||
maxVersions: 'Max versions to keep:',
|
||||
autoDelete: 'Oldest deleted automatically',
|
||||
},
|
||||
schedule: {
|
||||
title: 'Scheduled Tasks',
|
||||
cron: 'Cron',
|
||||
daily: 'Daily',
|
||||
weekly: 'Weekly',
|
||||
enableCron: 'Enable Cron Schedule',
|
||||
enableDaily: 'Enable Daily Run',
|
||||
enableWeekly: 'Enable Weekly Run',
|
||||
watchLocal: 'Watch Local Changes',
|
||||
watchDesc: 'Auto-sync when local playlist updates',
|
||||
schedule: 'Schedule',
|
||||
notConfigured: 'Not configured',
|
||||
today: 'Today',
|
||||
tomorrow: 'Tomorrow',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: 'Server Connected',
|
||||
titleConnect: 'Connect Plex Server',
|
||||
serverDetails: 'Server Details',
|
||||
authentication: 'Authentication',
|
||||
protocol: 'Protocol',
|
||||
address: 'IP Address or Domain',
|
||||
port: 'Port',
|
||||
token: 'X-Plex-Token (Optional)',
|
||||
username: 'Username / Email',
|
||||
password: 'Password',
|
||||
advanced: 'Advanced Options',
|
||||
timeout: 'Connection Timeout (Seconds)',
|
||||
connectBtn: 'Connect Server',
|
||||
connecting: 'Connecting...',
|
||||
connectedSuccess: 'Connected Successfully',
|
||||
selectLibrary: 'Select Library to Sync',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: 'Local refresh cancelled.',
|
||||
cloudRefreshCancelled: 'Cloud refresh cancelled.',
|
||||
strategySaved: 'Selected strategy "{strategy}" has been saved.',
|
||||
mappingSaved: 'Path mapping rules have been saved.',
|
||||
backupSaved: 'Backup settings have been saved.',
|
||||
backupFailed: 'Failed to save backup settings.',
|
||||
scheduleDisabled: 'Scheduled tasks disabled.',
|
||||
scheduleEmpty: 'Scheduled tasks disabled (Empty Cron).',
|
||||
scheduleStarted: 'Scheduled task started successfully.',
|
||||
scheduleFailed: 'Failed to update schedule.',
|
||||
syncFailed: 'Sync failed. Please check connection.',
|
||||
librarySwitched: 'Library switched to {library}',
|
||||
connectedTo: 'Successfully connected to {name}',
|
||||
connectionCancelled: 'Connection cancelled by user.',
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
export const es = {
|
||||
app: {
|
||||
// title and manager are no longer used for branding
|
||||
title: 'PlexSync',
|
||||
manager: 'Gestor',
|
||||
footer: '© {year} PMS Playlist Sync. Conectado al backend Docker.',
|
||||
},
|
||||
common: {
|
||||
save: 'Guardar',
|
||||
cancel: 'Cancelar',
|
||||
revert: 'Revertir',
|
||||
delete: 'Eliminar',
|
||||
done: 'Hecho',
|
||||
loading: 'Cargando...',
|
||||
refresh: 'Actualizar',
|
||||
close: 'Cerrar',
|
||||
none: 'Ninguno',
|
||||
disabled: 'Deshabilitado',
|
||||
add: 'Añadir',
|
||||
},
|
||||
server: {
|
||||
local: 'Servidor Local',
|
||||
cloud: 'Servidor Nube',
|
||||
playlists: '{count} Listas',
|
||||
notConnected: 'No Conectado',
|
||||
connectionFailed: 'Conexión fallida',
|
||||
connecting: 'Conectando...',
|
||||
waiting: 'Esperando...',
|
||||
syncing: 'Sincronizando...',
|
||||
noPlaylists: 'No se encontraron listas.',
|
||||
cancelRefresh: 'Cancelar',
|
||||
refreshPlaylists: 'Actualizar Listas',
|
||||
},
|
||||
playlist: {
|
||||
trackCount: 'Pistas',
|
||||
lastUpdated: 'Actualizado',
|
||||
},
|
||||
dashboard: {
|
||||
mapping: 'Mapeo',
|
||||
backup: 'Respaldo',
|
||||
autoSync: 'Auto-Sync',
|
||||
watch: 'Vigilar',
|
||||
watchModeActive: 'Modo Vigía: Activo',
|
||||
watchModeDisabled: 'Modo Vigía: Desactivado',
|
||||
notSet: 'No Def.',
|
||||
retain: 'Retener: {count}',
|
||||
keep: 'Guardar {count}',
|
||||
connected: 'Conectado a Plex',
|
||||
disconnected: 'Desconectado',
|
||||
synchronizing: 'SINCRONIZANDO',
|
||||
syncComplete: 'SINCRONIZACIÓN COMPLETA',
|
||||
},
|
||||
strategies: {
|
||||
title: 'Estrategia de Sync',
|
||||
localOverwrite: {
|
||||
label: 'Sobreescribir Local',
|
||||
desc: 'La lista local sobreescribe la nube. (Sin Diff)',
|
||||
},
|
||||
cloudOverwrite: {
|
||||
label: 'Sobreescribir Nube',
|
||||
desc: 'La lista de la nube sobreescribe la local. (Sin Diff)',
|
||||
},
|
||||
mergeLocal: {
|
||||
label: 'Fusión (Prioridad Local)',
|
||||
desc: 'Fusionar ambas. Conflictos resueltos a versión Local.',
|
||||
},
|
||||
mergeCloud: {
|
||||
label: 'Fusión (Prioridad Nube)',
|
||||
desc: 'Fusionar ambas. Conflictos resueltos a versión Nube.',
|
||||
},
|
||||
syncNow: 'Sincronizar Ahora',
|
||||
syncing: 'Sincronizando...',
|
||||
saveWarning: 'Guarde los cambios pendientes (Respaldos/Mapeo) antes de sincronizar.',
|
||||
},
|
||||
mapping: {
|
||||
title: 'Mapeo de Rutas',
|
||||
simple: 'Mapeo Simple',
|
||||
regex: 'Reglas Regex',
|
||||
simpleTitle: 'Mapeo de Rutas',
|
||||
simpleSubtitle: 'Mapear rutas locales a la nube usando coincidencia simple',
|
||||
regexPre: 'Pre-Procesamiento (Antes de Sync)',
|
||||
regexPost: 'Post-Procesamiento (Después de Sync)',
|
||||
localPath: 'Ruta Local',
|
||||
cloudPath: 'Ruta Nube',
|
||||
pattern: 'Patrón',
|
||||
replace: 'Reemplazo',
|
||||
saveRules: 'Guardar Reglas',
|
||||
noRules: 'No hay reglas definidas.',
|
||||
},
|
||||
backup: {
|
||||
title: 'Retención de Respaldo',
|
||||
enable: 'Habilitar Respaldos',
|
||||
enableDesc: 'Crear copia antes de cambios',
|
||||
maxVersions: 'Máx versiones a guardar:',
|
||||
autoDelete: 'El más antiguo se borra automáticamente',
|
||||
},
|
||||
schedule: {
|
||||
title: 'Tareas Programadas',
|
||||
cron: 'Cron',
|
||||
daily: 'Diario',
|
||||
weekly: 'Semanal',
|
||||
enableCron: 'Habilitar Cron',
|
||||
enableDaily: 'Habilitar Ejecución Diaria',
|
||||
enableWeekly: 'Habilitar Ejecución Semanal',
|
||||
watchLocal: 'Vigilar Cambios Locales',
|
||||
watchDesc: 'Auto-sync cuando la lista local se actualiza',
|
||||
schedule: 'Horario',
|
||||
notConfigured: 'No configurado',
|
||||
today: 'Hoy',
|
||||
tomorrow: 'Mañana',
|
||||
},
|
||||
connection: {
|
||||
titleConnected: 'Servidor Conectado',
|
||||
titleConnect: 'Conectar Servidor Plex',
|
||||
serverDetails: 'Detalles del Servidor',
|
||||
authentication: 'Autenticación',
|
||||
protocol: 'Protocolo',
|
||||
address: 'Dirección IP o Dominio',
|
||||
port: 'Puerto',
|
||||
token: 'X-Plex-Token (Opcional)',
|
||||
username: 'Usuario / Email',
|
||||
password: 'Password',
|
||||
advanced: 'Opciones Avanzadas',
|
||||
timeout: 'Tiempo de espera (Segundos)',
|
||||
connectBtn: 'Conectar Servidor',
|
||||
connecting: 'Conectando...',
|
||||
connectedSuccess: 'Conectado Exitosamente',
|
||||
selectLibrary: 'Seleccionar Librería',
|
||||
},
|
||||
toasts: {
|
||||
localRefreshCancelled: 'Actualización local cancelada.',
|
||||
cloudRefreshCancelled: 'Actualización nube cancelada.',
|
||||
strategySaved: 'Estrategia seleccionada "{strategy}" guardada.',
|
||||
mappingSaved: 'Reglas de mapeo guardadas.',
|
||||
backupSaved: 'Configuración de respaldo guardada.',
|
||||
backupFailed: 'Error al guardar configuración de respaldo.',
|
||||
scheduleDisabled: 'Tareas programadas deshabilitadas.',
|
||||
scheduleEmpty: 'Tareas programadas deshabilitadas (Cron Vacío).',
|
||||
scheduleStarted: 'Tarea programada iniciada exitosamente.',
|
||||
scheduleFailed: 'Error al actualizar horario.',
|
||||
syncFailed: 'Fallo en sync. Revise conexión.',
|
||||
librarySwitched: 'Librería cambiada a {library}',
|
||||
connectedTo: 'Conectado exitosamente a {name}',
|
||||
connectionCancelled: 'Conexión cancelada por usuario.',
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "PlexSync Manager",
|
||||
"name": "PMS Playlist Sync",
|
||||
"description": "A modern dashboard to synchronize and manage playlists between Local and Cloud Plex servers.",
|
||||
"requestFramePermissions": []
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "plexsync-manager",
|
||||
"name": "pms-playlist-sync",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
|
||||
import { Playlist, ServerType, ApiResponse, PlexServerConnection, PlexConnectionSettings, PlexLibrary, SyncStrategy, RegexReplacement } from '../types';
|
||||
|
||||
|
||||
|
||||
|
||||
import { Playlist, ServerType, ApiResponse, PlexServerConnection, PlexConnectionSettings, PlexLibrary, SyncStrategy, PathMappingConfig, ScheduleSettings, ScheduleMode, BackupSettings } from '../types';
|
||||
import { MOCK_LOCAL_PLAYLISTS, MOCK_CLOUD_PLAYLISTS } from './mockData';
|
||||
|
||||
const SIMULATE_DELAY_MS = 800;
|
||||
@@ -126,15 +130,24 @@ const authenticatePlex = async (settings: PlexConnectionSettings, signal?: Abort
|
||||
});
|
||||
}
|
||||
|
||||
const triggerSync = async (strategy: SyncStrategy, regexRules: RegexReplacement[]): Promise<void> => {
|
||||
const triggerSync = async (strategy: SyncStrategy, pathMapping: PathMappingConfig): Promise<void> => {
|
||||
return new Promise((resolve) => {
|
||||
// Simulate a sync process taking 3 seconds
|
||||
// In a real app, pathMapping would be sent to backend
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 3000);
|
||||
});
|
||||
};
|
||||
|
||||
// Basic Cron validation helper
|
||||
const validateCron = (expression: string): boolean => {
|
||||
const parts = expression.trim().split(/\s+/);
|
||||
if (parts.length !== 5) return false;
|
||||
// A very naive check, real validation is more complex but this fits the mock requirement
|
||||
return true;
|
||||
};
|
||||
|
||||
export const apiService = {
|
||||
getPlaylists: async (serverType: ServerType, signal?: AbortSignal): Promise<ApiResponse<Playlist[]>> => {
|
||||
try {
|
||||
@@ -184,12 +197,37 @@ export const apiService = {
|
||||
}
|
||||
},
|
||||
|
||||
syncPlaylists: async (strategy: SyncStrategy, regexRules: RegexReplacement[]): Promise<ApiResponse<null>> => {
|
||||
syncPlaylists: async (strategy: SyncStrategy, pathMapping: PathMappingConfig): Promise<ApiResponse<null>> => {
|
||||
try {
|
||||
await triggerSync(strategy, regexRules);
|
||||
await triggerSync(strategy, pathMapping);
|
||||
return { data: null, status: 'success', message: 'Sync complete' };
|
||||
} catch (error) {
|
||||
return { data: null, status: 'error', message: 'Sync failed' };
|
||||
}
|
||||
},
|
||||
|
||||
saveScheduleSettings: async (settings: ScheduleSettings): Promise<ApiResponse<null>> => {
|
||||
// Simulate API call
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
// Validation only applies if the mode is CRON and user provided input
|
||||
if (settings.mode === ScheduleMode.CRON && settings.cronExpression.trim() !== '') {
|
||||
if (!validateCron(settings.cronExpression)) {
|
||||
resolve({ data: null, status: 'error', message: 'Invalid Cron expression format' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
resolve({ data: null, status: 'success', message: 'Schedule updated successfully' });
|
||||
}, 500);
|
||||
});
|
||||
},
|
||||
|
||||
saveBackupSettings: async (settings: BackupSettings): Promise<ApiResponse<null>> => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({ data: null, status: 'success', message: 'Backup settings saved' });
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
import { en } from './locales/en';
|
||||
import { es } from './locales/es';
|
||||
|
||||
export const translations = {
|
||||
en,
|
||||
es
|
||||
};
|
||||
|
||||
export type Language = keyof typeof translations;
|
||||
export type TranslationStructure = typeof en;
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
|
||||
export interface Track {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -34,10 +35,49 @@ export enum SyncState {
|
||||
ERROR = 'ERROR'
|
||||
}
|
||||
|
||||
export interface RegexReplacement {
|
||||
export interface ReplacementRule {
|
||||
id: string;
|
||||
pattern: string;
|
||||
replacement: string;
|
||||
search: string;
|
||||
replace: string;
|
||||
}
|
||||
|
||||
export interface PathMappingRules {
|
||||
localPre: ReplacementRule[];
|
||||
localPost: ReplacementRule[];
|
||||
remotePre: ReplacementRule[];
|
||||
remotePost: ReplacementRule[];
|
||||
}
|
||||
|
||||
export enum PathMappingMode {
|
||||
SIMPLE = 'SIMPLE',
|
||||
REGEX = 'REGEX'
|
||||
}
|
||||
|
||||
export interface PathMappingConfig {
|
||||
mode: PathMappingMode;
|
||||
simple: ReplacementRule[];
|
||||
regex: PathMappingRules;
|
||||
}
|
||||
|
||||
export interface BackupSettings {
|
||||
enabled: boolean;
|
||||
retentionCount: number;
|
||||
}
|
||||
|
||||
export enum ScheduleMode {
|
||||
DISABLED = 'DISABLED',
|
||||
CRON = 'CRON',
|
||||
DAILY = 'DAILY',
|
||||
WEEKLY = 'WEEKLY'
|
||||
}
|
||||
|
||||
export interface ScheduleSettings {
|
||||
mode: ScheduleMode;
|
||||
cronExpression: string;
|
||||
dailyTime: string;
|
||||
weeklyDays: number[]; // 0 = Sunday, 1 = Monday, etc.
|
||||
weeklyTime: string;
|
||||
autoWatch: boolean;
|
||||
}
|
||||
|
||||
export interface PlexLibrary {
|
||||
@@ -69,4 +109,4 @@ export interface ApiResponse<T> {
|
||||
data: T;
|
||||
status: 'success' | 'error';
|
||||
message?: string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user