Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions docs/details/advanced/logging.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Logging

`plistsync` provides a {py:func}`plistsync.logger.init_logging` function that configures logging for the plistsync logger based on a {py:class}`plistsync.config.LoggingConfig`. The CLI calls this function automatically; for scripts and library usage you should call it yourself.
`plistsync` provides a {py:func}`plistsync.logger.init_logging` function that configures logging for the plistsync logger based on a {py:class}`plistsync.logger.LoggingConfig`. The CLI calls this function automatically; for scripts and library usage you should call it yourself.

You can retrieve the logger as usual:

Expand All @@ -24,11 +24,10 @@ logging:

## Configuring logging from a script

Call {py:func}`plistsync.logger.init_logging` with a {py:class}`~plistsync.config.LoggingConfig` to set up the plistsync logger:
Call {py:func}`plistsync.logger.init_logging` with a {py:class}`~plistsync.logger.LoggingConfig` to set up the plistsync logger:

```python
from plistsync.config import LoggingConfig
from plistsync.logger import init_logging
from plistsync.logger import init_logging, LoggingConfig

# Use defaults (level="INFO", handler="rich")
init_logging()
Expand Down
2 changes: 2 additions & 0 deletions docs/services/plex/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ services:
# via plex.tv. In this case, we try local routes first.
# E.g. 'my_plex_server'
server_name: null
# The name or ID of the Plex library section to use by default.
section_name_or_id: Music
```

## Authentication
Expand Down
21 changes: 13 additions & 8 deletions examples/community/plex_to_m3u.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Export a single Plex playlist to M3U format, with optional path rewriting."""

from pathlib import Path
from typing import Annotated
from __future__ import annotations

from typing import TYPE_CHECKING, Annotated

import typer

from plistsync.cli.config import Config
from plistsync.core.rewrite import PathRewrite
from plistsync.logger import log
from plistsync.services.plex import PlexLibrary
from plistsync.services.plex import PlexConfig, PlexLibrary

if TYPE_CHECKING:
from pathlib import Path


def main(
Expand Down Expand Up @@ -53,7 +58,9 @@ def main(
path_rewrite = PathRewrite.from_str(plex_path_base, m3u_path_base)

# Load Plex library and playlist
plex_library = PlexLibrary(plex_section_name)
plex_config = Config().get_config_for(PlexConfig)
plex_config.section_name_or_id = plex_section_name
plex_library = PlexLibrary.from_config(plex_config)
playlist = plex_library.get_playlist(name=playlist_name)

if playlist is None:
Expand All @@ -70,16 +77,14 @@ def main(
if not track.path:
log.warning(f"Track '{track.title}' has no file path — skipping.")
continue
m3u += str(path_rewrite.apply(track.path)) + '\n'
m3u += str(path_rewrite.apply(track.path)) + "\n"
num_m3u_tracks += 1

# Write M3U file
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(m3u, encoding="utf-8")

log.info(
f"Exported '{playlist.name}' → {output_path} with {num_m3u_tracks} tracks"
)
log.info(f"Exported '{playlist.name}' → {output_path} with {num_m3u_tracks} tracks")


main.__doc__ = __doc__ # set help text from module docstring
Expand Down
18 changes: 13 additions & 5 deletions examples/community/plex_traktor_bidirectional.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
The Path rewrite assumes your plex is remote and traktor is local.
"""

from pathlib import Path
from typing import Annotated
from __future__ import annotations

from typing import TYPE_CHECKING, Annotated

import typer

from plistsync.cli.config import Config
from plistsync.core.ids import FilePath
from plistsync.core.rewrite import PathRewrite
from plistsync.logger import log
from plistsync.services.plex.config import PlexConfig
from plistsync.services.plex.library import PlexLibrary
from plistsync.services.traktor import NMLLibrary, NMLPlaylistTrack

if TYPE_CHECKING:
from pathlib import Path


def main(
traktor_nml_path: Annotated[
Expand Down Expand Up @@ -59,8 +65,10 @@ def main(
path_rewrite = PathRewrite.from_str(plex_path_base, traktor_path_base)

# Get libraries
plex_library = PlexLibrary(plex_section_name)
traktor_library = NMLLibrary(traktor_nml_path)
plex_config = Config().get_config_for(PlexConfig)
plex_config.section_name_or_id = plex_section_name
plex_library = PlexLibrary.from_config(plex_config)
traktor_library = NMLLibrary(traktor_nml_path, backup_before_write=True)

# Get playlists
plex_playlist = plex_library.get_playlist(name=playlist_name)
Expand Down Expand Up @@ -120,7 +128,7 @@ def main(
p_for_plex = path_rewrite.invert.apply(p)
plex_track = plex_library.find_by_ids([FilePath(p_for_plex)])
if plex_track is None:
log.warning(f"Could not find track in plex: {str(p_for_plex)}")
log.warning(f"Could not find track in plex: {p_for_plex!s}")
else:
plex_playlist.tracks.append(plex_track)

Expand Down
3 changes: 1 addition & 2 deletions plistsync/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Toolbox for transferring, converting and matching music collections."""

from . import config, core, logger, services
from . import core, logger, services

__all__ = [
"config",
"core",
"logger",
"services",
Expand Down
4 changes: 2 additions & 2 deletions plistsync/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from typer.core import TyperGroup
from typer.main import get_group

from plistsync.config import Config
from plistsync.logger import basic_logging_handler, init_logging, log
from plistsync.services import ServiceLoader

from .commands.config import config_app
from .commands.sync import sync_app
from .config import Config
from .context import ServiceContext
from .service_commands import cli_service_factory

Expand All @@ -26,7 +26,7 @@
# signatures must use those types rather than the standalone click package.
from typer._click import Command, Context

from plistsync.config import LoggingConfig
from plistsync.logger import LoggingConfig
from plistsync.services import Service


Expand Down
2 changes: 1 addition & 1 deletion plistsync/cli/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from eyconf.cli import create_config_cli

from plistsync.config import Config
from plistsync.cli.config import Config

config_app = create_config_cli(Config)
Loading
Loading