Compare commits
3 Commits
chatgpt-as
...
grok-assis
| Author | SHA1 | Date | |
|---|---|---|---|
|
3b1be1c4b1
|
|||
|
8f709877bc
|
|||
|
57e051b45c
|
@@ -1,11 +1,14 @@
|
||||
{
|
||||
"_output_dir": "/home/darkhelm/Projects/DarkHelm.org/plex-playlist/temp",
|
||||
"_template": "gh:cjolowicz/cookiecutter-hypermodern-python",
|
||||
"author": "Cliff Hill",
|
||||
"copyright_year": "2025",
|
||||
"development_status": "Development Status :: 2 - Pre-Alpha",
|
||||
"email": "xlorep@darkhelm.org",
|
||||
"friendly_name": "Automated Daily Playlist Generator for Plex Music",
|
||||
"friendly_name": "Plex Playlist",
|
||||
"github_user": "xlorepdarkhelm",
|
||||
"license": "MIT",
|
||||
"license": "Apache-2.0",
|
||||
"package_name": "playlist",
|
||||
"project_name": "plex-playlist",
|
||||
"version": "0.1.0"
|
||||
"version": "0.0.0"
|
||||
}
|
||||
|
||||
18
.flake8
18
.flake8
@@ -1,21 +1,9 @@
|
||||
[flake8]
|
||||
select = B,B9,C,D,DAR,E,F,N,RST,S,W
|
||||
ignore = E203,E501,RST201,RST203,RST301,W503
|
||||
max-line-length = 88
|
||||
max-line-length = 80
|
||||
max-complexity = 10
|
||||
docstring-convention = google
|
||||
per-file-ignores = tests/*:S101
|
||||
based-on-style = "pep8"
|
||||
column-limit = 88
|
||||
indent-width = 4
|
||||
spaces_before_comment = 2
|
||||
ALLOW_SPLIT_BEFORE_DICT_VALUE = false
|
||||
DEDENT_CLOSING_BRACKETS = true
|
||||
EACH_DICT_ENTRY_ON_SEPARATE_LINE = true
|
||||
COALESCE_BRACKETS = true
|
||||
USE_TABS = false
|
||||
ALLOW_MULTILINE_LAMBDAS = true
|
||||
BLANK_LINE_BEFORE_NESTED_CLASS_ON_DEF = true
|
||||
INDENT_DICTIONARY_VALUE = true
|
||||
SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN = true
|
||||
DISABLE_ENDING_COMMA_HEURISTIC = true
|
||||
rst-roles = class,const,func,meth,mod,ref
|
||||
rst-directives = deprecated
|
||||
|
||||
3
.github/dependabot.yml
vendored
3
.github/dependabot.yml
vendored
@@ -16,3 +16,6 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
versioning-strategy: lockfile-only
|
||||
allow:
|
||||
- dependency-type: "all"
|
||||
|
||||
10
.github/workflows/constraints.txt
vendored
10
.github/workflows/constraints.txt
vendored
@@ -1,5 +1,5 @@
|
||||
pip==21.0.1
|
||||
nox==2020.12.31
|
||||
nox-poetry==0.8.2
|
||||
poetry==1.1.5
|
||||
virtualenv==20.4.2
|
||||
pip==22.1.2
|
||||
nox==2022.1.7
|
||||
nox-poetry==1.0.0
|
||||
poetry==1.1.13
|
||||
virtualenv==20.14.1
|
||||
|
||||
4
.github/workflows/labeler.yml
vendored
4
.github/workflows/labeler.yml
vendored
@@ -11,9 +11,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run Labeler
|
||||
uses: crazy-max/ghaction-github-labeler@v3.1.1
|
||||
uses: crazy-max/ghaction-github-labeler@v4.0.0
|
||||
with:
|
||||
skip-delete: true
|
||||
|
||||
12
.github/workflows/release.yml
vendored
12
.github/workflows/release.yml
vendored
@@ -12,14 +12,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v2.3.4
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2.2.1
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: "3.9"
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
@@ -57,21 +57,21 @@ jobs:
|
||||
|
||||
- name: Publish package on PyPI
|
||||
if: steps.check-version.outputs.tag
|
||||
uses: pypa/gh-action-pypi-publish@v1.4.2
|
||||
uses: pypa/gh-action-pypi-publish@v1.5.0
|
||||
with:
|
||||
user: __token__
|
||||
password: ${{ secrets.PYPI_TOKEN }}
|
||||
|
||||
- name: Publish package on TestPyPI
|
||||
if: "! steps.check-version.outputs.tag"
|
||||
uses: pypa/gh-action-pypi-publish@v1.4.2
|
||||
uses: pypa/gh-action-pypi-publish@v1.5.0
|
||||
with:
|
||||
user: __token__
|
||||
password: ${{ secrets.TEST_PYPI_TOKEN }}
|
||||
repository_url: https://test.pypi.org/legacy/
|
||||
|
||||
- name: Publish the release notes
|
||||
uses: release-drafter/release-drafter@v5.14.0
|
||||
uses: release-drafter/release-drafter@v5.20.0
|
||||
with:
|
||||
publish: ${{ steps.check-version.outputs.tag != '' }}
|
||||
tag: ${{ steps.check-version.outputs.tag }}
|
||||
|
||||
85
.github/workflows/tests.yml
vendored
85
.github/workflows/tests.yml
vendored
@@ -6,53 +6,65 @@ on:
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: ${{ matrix.session }} ${{ matrix.python-version }} / ${{ matrix.os }}
|
||||
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "pre-commit" }
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "safety" }
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "mypy" }
|
||||
- { python-version: 3.8, os: ubuntu-latest, session: "mypy" }
|
||||
- { python-version: 3.7, os: ubuntu-latest, session: "mypy" }
|
||||
- { python-version: 3.6, os: ubuntu-latest, session: "mypy" }
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "tests" }
|
||||
- { python-version: 3.8, os: ubuntu-latest, session: "tests" }
|
||||
- { python-version: 3.7, os: ubuntu-latest, session: "tests" }
|
||||
- { python-version: 3.6, os: ubuntu-latest, session: "tests" }
|
||||
- { python-version: 3.9, os: windows-latest, session: "tests" }
|
||||
- { python-version: 3.9, os: macos-latest, session: "tests" }
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "typeguard" }
|
||||
- { python-version: 3.9, os: ubuntu-latest, session: "xdoctest" }
|
||||
- { python-version: 3.8, os: ubuntu-latest, session: "docs-build" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "pre-commit" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "safety" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "mypy" }
|
||||
- { python: "3.9", os: "ubuntu-latest", session: "mypy" }
|
||||
- { python: "3.8", os: "ubuntu-latest", session: "mypy" }
|
||||
- { python: "3.7", os: "ubuntu-latest", session: "mypy" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "tests" }
|
||||
- { python: "3.9", os: "ubuntu-latest", session: "tests" }
|
||||
- { python: "3.8", os: "ubuntu-latest", session: "tests" }
|
||||
- { python: "3.7", os: "ubuntu-latest", session: "tests" }
|
||||
- { python: "3.10", os: "windows-latest", session: "tests" }
|
||||
- { python: "3.10", os: "macos-latest", session: "tests" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "typeguard" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "xdoctest" }
|
||||
- { python: "3.10", os: "ubuntu-latest", session: "docs-build" }
|
||||
|
||||
env:
|
||||
NOXSESSION: ${{ matrix.session }}
|
||||
FORCE_COLOR: "1"
|
||||
PRE_COMMIT_COLOR: "always"
|
||||
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v2.3.4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2.2.1
|
||||
- name: Set up Python ${{ matrix.python }}
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
python-version: ${{ matrix.python }}
|
||||
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
pip install --constraint=.github/workflows/constraints.txt pip
|
||||
pip --version
|
||||
|
||||
- name: Upgrade pip in virtual environments
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
import pip
|
||||
|
||||
with open(os.environ["GITHUB_ENV"], mode="a") as io:
|
||||
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
|
||||
|
||||
- name: Install Poetry
|
||||
run: |
|
||||
pip install --constraint=.github/workflows/constraints.txt poetry
|
||||
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
|
||||
poetry --version
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
|
||||
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
|
||||
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
|
||||
nox --version
|
||||
|
||||
- name: Compute pre-commit cache key
|
||||
@@ -71,7 +83,7 @@ jobs:
|
||||
print("::set-output name=result::{}".format(result))
|
||||
|
||||
- name: Restore pre-commit cache
|
||||
uses: actions/cache@v2.1.4
|
||||
uses: actions/cache@v3
|
||||
if: matrix.session == 'pre-commit'
|
||||
with:
|
||||
path: ~/.cache/pre-commit
|
||||
@@ -81,18 +93,18 @@ jobs:
|
||||
|
||||
- name: Run Nox
|
||||
run: |
|
||||
nox --force-color --python=${{ matrix.python-version }}
|
||||
nox --python=${{ matrix.python }}
|
||||
|
||||
- name: Upload coverage data
|
||||
if: always() && matrix.session == 'tests'
|
||||
uses: "actions/upload-artifact@v2.2.2"
|
||||
uses: "actions/upload-artifact@v3"
|
||||
with:
|
||||
name: coverage-data
|
||||
path: ".coverage.*"
|
||||
|
||||
- name: Upload documentation
|
||||
if: matrix.session == 'docs-build'
|
||||
uses: actions/upload-artifact@v2.2.2
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: docs
|
||||
path: docs/_build
|
||||
@@ -102,12 +114,12 @@ jobs:
|
||||
needs: tests
|
||||
steps:
|
||||
- name: Check out the repository
|
||||
uses: actions/checkout@v2.3.4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Python 3.9
|
||||
uses: actions/setup-python@v2.2.1
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v3
|
||||
with:
|
||||
python-version: 3.9
|
||||
python-version: "3.10"
|
||||
|
||||
- name: Upgrade pip
|
||||
run: |
|
||||
@@ -116,26 +128,27 @@ jobs:
|
||||
|
||||
- name: Install Poetry
|
||||
run: |
|
||||
pip install --constraint=.github/workflows/constraints.txt poetry
|
||||
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
|
||||
poetry --version
|
||||
|
||||
- name: Install Nox
|
||||
run: |
|
||||
pip install --constraint=.github/workflows/constraints.txt nox nox-poetry
|
||||
pipx install --pip-args=--constraint=.github/workflows/constraints.txt nox
|
||||
pipx inject --pip-args=--constraint=.github/workflows/constraints.txt nox nox-poetry
|
||||
nox --version
|
||||
|
||||
- name: Download coverage data
|
||||
uses: actions/download-artifact@v2.0.8
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: coverage-data
|
||||
|
||||
- name: Combine coverage data and display human readable report
|
||||
run: |
|
||||
nox --force-color --session=coverage
|
||||
nox --session=coverage
|
||||
|
||||
- name: Create coverage report
|
||||
run: |
|
||||
nox --force-color --session=coverage -- xml
|
||||
nox --session=coverage -- xml
|
||||
|
||||
- name: Upload coverage report
|
||||
uses: codecov/codecov-action@v1.2.2
|
||||
uses: codecov/codecov-action@v3.1.0
|
||||
|
||||
166
.gitignore
vendored
166
.gitignore
vendored
@@ -1,158 +1,10 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
.python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
Sessionx.vim
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
/.coverage
|
||||
/.coverage.*
|
||||
/.nox/
|
||||
/.python-version
|
||||
/.pytype/
|
||||
/dist/
|
||||
/docs/_build/
|
||||
/src/*.egg-info/
|
||||
__pycache__/
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
---
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
@@ -22,6 +21,12 @@ repos:
|
||||
entry: check-yaml
|
||||
language: system
|
||||
types: [yaml]
|
||||
- id: darglint
|
||||
name: darglint
|
||||
entry: darglint
|
||||
language: system
|
||||
types: [python]
|
||||
stages: [manual]
|
||||
- id: end-of-file-fixer
|
||||
name: Fix End of Files
|
||||
entry: end-of-file-fixer
|
||||
@@ -34,24 +39,28 @@ repos:
|
||||
language: system
|
||||
types: [python]
|
||||
require_serial: true
|
||||
- id: reorder-python-imports
|
||||
name: Reorder python imports
|
||||
entry: reorder-python-imports
|
||||
args: [--darglint-ignore-regex, .*]
|
||||
- id: isort
|
||||
name: isort
|
||||
entry: isort
|
||||
require_serial: true
|
||||
language: system
|
||||
types_or: [cython, pyi, python]
|
||||
args: ["--filter-files"]
|
||||
- id: pyupgrade
|
||||
name: pyupgrade
|
||||
description: Automatically upgrade syntax for newer versions.
|
||||
entry: pyupgrade
|
||||
language: system
|
||||
types: [python]
|
||||
args:
|
||||
[
|
||||
--application-directories=src,
|
||||
--py39-plus,
|
||||
--exit-zero-even-if-changed,
|
||||
]
|
||||
args: [--py37-plus]
|
||||
- id: trailing-whitespace
|
||||
name: Trim Trailing Whitespace
|
||||
entry: trailing-whitespace-fixer
|
||||
language: system
|
||||
types: [text]
|
||||
stages: [commit, push, manual]
|
||||
- repo: https://github.com/prettier/pre-commit
|
||||
rev: v2.1.2
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v2.6.0
|
||||
hooks:
|
||||
- id: prettier
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
version: 2
|
||||
build:
|
||||
os: ubuntu-20.04
|
||||
tools:
|
||||
python: "3.10"
|
||||
sphinx:
|
||||
configuration: docs/conf.py
|
||||
formats: all
|
||||
python:
|
||||
version: 3.8
|
||||
install:
|
||||
- requirements: docs/requirements.txt
|
||||
- path: .
|
||||
|
||||
132
CODE_OF_CONDUCT.md
Normal file
132
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual
|
||||
identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the overall
|
||||
community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or advances of
|
||||
any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email address,
|
||||
without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
[xlorep@darkhelm.org](mailto:xlorep@darkhelm.org).
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of
|
||||
actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or permanent
|
||||
ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the
|
||||
community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.1, available at
|
||||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][mozilla coc].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][faq]. Translations are available at
|
||||
[https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[mozilla coc]: https://github.com/mozilla/diversity
|
||||
[faq]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
@@ -1,105 +0,0 @@
|
||||
Contributor Covenant Code of Conduct
|
||||
====================================
|
||||
|
||||
Our Pledge
|
||||
----------
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
||||
|
||||
|
||||
Our Standards
|
||||
-------------
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our community include:
|
||||
|
||||
- Demonstrating empathy and kindness toward other people
|
||||
- Being respectful of differing opinions, viewpoints, and experiences
|
||||
- Giving and gracefully accepting constructive feedback
|
||||
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
||||
- Focusing on what is best not just for us as individuals, but for the overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
- The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
- Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
- Public or private harassment
|
||||
- Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
- Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
Enforcement Responsibilities
|
||||
----------------------------
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
||||
|
||||
|
||||
Scope
|
||||
-----
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
||||
|
||||
|
||||
Enforcement
|
||||
-----------
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at xlorep@darkhelm.org. All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
||||
|
||||
|
||||
Enforcement Guidelines
|
||||
----------------------
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
|
||||
1. Correction
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
|
||||
2. Warning
|
||||
~~~~~~~~~~
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
||||
|
||||
|
||||
3. Temporary Ban
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
||||
|
||||
|
||||
4. Permanent Ban
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
||||
|
||||
|
||||
Attribution
|
||||
-----------
|
||||
|
||||
This Code of Conduct is adapted from the `Contributor Covenant <homepage_>`__, version 2.0,
|
||||
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by `Mozilla’s code of conduct enforcement ladder <https://github.com/mozilla/diversity>`__.
|
||||
|
||||
.. _homepage: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
||||
115
CONTRIBUTING.md
Normal file
115
CONTRIBUTING.md
Normal file
@@ -0,0 +1,115 @@
|
||||
# Contributor Guide
|
||||
|
||||
Thank you for your interest in improving this project.
|
||||
This project is open-source under the [Apache 2.0 license] and
|
||||
welcomes contributions in the form of bug reports, feature requests, and pull requests.
|
||||
|
||||
Here is a list of important resources for contributors:
|
||||
|
||||
- [Source Code]
|
||||
- [Documentation]
|
||||
- [Issue Tracker]
|
||||
- [Code of Conduct]
|
||||
|
||||
[apache 2.0 license]: https://opensource.org/licenses/Apache-2.0
|
||||
[source code]: https://github.com/xlorepdarkhelm/plex-playlist
|
||||
[documentation]: https://plex-playlist.readthedocs.io/
|
||||
[issue tracker]: https://github.com/xlorepdarkhelm/plex-playlist/issues
|
||||
|
||||
## How to report a bug
|
||||
|
||||
Report bugs on the [Issue Tracker].
|
||||
|
||||
When filing an issue, make sure to answer these questions:
|
||||
|
||||
- Which operating system and Python version are you using?
|
||||
- Which version of this project are you using?
|
||||
- What did you do?
|
||||
- What did you expect to see?
|
||||
- What did you see instead?
|
||||
|
||||
The best way to get your bug fixed is to provide a test case,
|
||||
and/or steps to reproduce the issue.
|
||||
|
||||
## How to request a feature
|
||||
|
||||
Request features on the [Issue Tracker].
|
||||
|
||||
## How to set up your development environment
|
||||
|
||||
You need Python 3.7+ and the following tools:
|
||||
|
||||
- [Poetry]
|
||||
- [Nox]
|
||||
- [nox-poetry]
|
||||
|
||||
Install the package with development requirements:
|
||||
|
||||
```console
|
||||
$ poetry install
|
||||
```
|
||||
|
||||
You can now run an interactive Python session,
|
||||
or the command-line interface:
|
||||
|
||||
```console
|
||||
$ poetry run python
|
||||
$ poetry run plex-playlist
|
||||
```
|
||||
|
||||
[poetry]: https://python-poetry.org/
|
||||
[nox]: https://nox.thea.codes/
|
||||
[nox-poetry]: https://nox-poetry.readthedocs.io/
|
||||
|
||||
## How to test the project
|
||||
|
||||
Run the full test suite:
|
||||
|
||||
```console
|
||||
$ nox
|
||||
```
|
||||
|
||||
List the available Nox sessions:
|
||||
|
||||
```console
|
||||
$ nox --list-sessions
|
||||
```
|
||||
|
||||
You can also run a specific Nox session.
|
||||
For example, invoke the unit test suite like this:
|
||||
|
||||
```console
|
||||
$ nox --session=tests
|
||||
```
|
||||
|
||||
Unit tests are located in the _tests_ directory,
|
||||
and are written using the [pytest] testing framework.
|
||||
|
||||
[pytest]: https://pytest.readthedocs.io/
|
||||
|
||||
## How to submit changes
|
||||
|
||||
Open a [pull request] to submit changes to this project.
|
||||
|
||||
Your pull request needs to meet the following guidelines for acceptance:
|
||||
|
||||
- The Nox test suite must pass without errors and warnings.
|
||||
- Include unit tests. This project maintains 100% code coverage.
|
||||
- If your changes add functionality, update the documentation accordingly.
|
||||
|
||||
Feel free to submit early, though—we can always iterate on this.
|
||||
|
||||
To run linting and code formatting checks before committing your change, you can install pre-commit as a Git hook by running the following command:
|
||||
|
||||
```console
|
||||
$ nox --session=pre-commit -- install
|
||||
```
|
||||
|
||||
It is recommended to open an issue before starting work on anything.
|
||||
This will allow a chance to talk it over with the owners and validate your approach.
|
||||
|
||||
[pull request]: https://github.com/xlorepdarkhelm/plex-playlist/pulls
|
||||
|
||||
<!-- github-only -->
|
||||
|
||||
[code of conduct]: CODE_OF_CONDUCT.md
|
||||
123
CONTRIBUTING.rst
123
CONTRIBUTING.rst
@@ -1,123 +0,0 @@
|
||||
Contributor Guide
|
||||
=================
|
||||
|
||||
Thank you for your interest in improving this project.
|
||||
This project is open-source under the `MIT license`_ and
|
||||
welcomes contributions in the form of bug reports, feature requests, and pull requests.
|
||||
|
||||
Here is a list of important resources for contributors:
|
||||
|
||||
- `Source Code`_
|
||||
- `Documentation`_
|
||||
- `Issue Tracker`_
|
||||
- `Code of Conduct`_
|
||||
|
||||
.. _MIT license: https://opensource.org/licenses/MIT
|
||||
.. _Source Code: https://github.com/xlorepdarkhelm/plex-playlist
|
||||
.. _Documentation: https://plex-playlist.readthedocs.io/
|
||||
.. _Issue Tracker: https://github.com/xlorepdarkhelm/plex-playlist/issues
|
||||
|
||||
How to report a bug
|
||||
-------------------
|
||||
|
||||
Report bugs on the `Issue Tracker`_.
|
||||
|
||||
When filing an issue, make sure to answer these questions:
|
||||
|
||||
- Which operating system and Python version are you using?
|
||||
- Which version of this project are you using?
|
||||
- What did you do?
|
||||
- What did you expect to see?
|
||||
- What did you see instead?
|
||||
|
||||
The best way to get your bug fixed is to provide a test case,
|
||||
and/or steps to reproduce the issue.
|
||||
|
||||
|
||||
How to request a feature
|
||||
------------------------
|
||||
|
||||
Request features on the `Issue Tracker`_.
|
||||
|
||||
|
||||
How to set up your development environment
|
||||
------------------------------------------
|
||||
|
||||
You need Python 3.6+ and the following tools:
|
||||
|
||||
- Poetry_
|
||||
- Nox_
|
||||
- nox-poetry_
|
||||
|
||||
Install the package with development requirements:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ poetry install
|
||||
|
||||
You can now run an interactive Python session,
|
||||
or the command-line interface:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ poetry run python
|
||||
$ poetry run plex-playlist
|
||||
|
||||
.. _Poetry: https://python-poetry.org/
|
||||
.. _Nox: https://nox.thea.codes/
|
||||
.. _nox-poetry: https://nox-poetry.readthedocs.io/
|
||||
|
||||
|
||||
How to test the project
|
||||
-----------------------
|
||||
|
||||
Run the full test suite:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ nox
|
||||
|
||||
List the available Nox sessions:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ nox --list-sessions
|
||||
|
||||
You can also run a specific Nox session.
|
||||
For example, invoke the unit test suite like this:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ nox --session=tests
|
||||
|
||||
Unit tests are located in the ``tests`` directory,
|
||||
and are written using the pytest_ testing framework.
|
||||
|
||||
.. _pytest: https://pytest.readthedocs.io/
|
||||
|
||||
|
||||
How to submit changes
|
||||
---------------------
|
||||
|
||||
Open a `pull request`_ to submit changes to this project.
|
||||
|
||||
Your pull request needs to meet the following guidelines for acceptance:
|
||||
|
||||
- The Nox test suite must pass without errors and warnings.
|
||||
- Include unit tests. This project maintains 100% code coverage.
|
||||
- If your changes add functionality, update the documentation accordingly.
|
||||
|
||||
Feel free to submit early, though—we can always iterate on this.
|
||||
|
||||
To run linting and code formatting checks before commiting your change, you can install pre-commit as a Git hook by running the following command:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ nox --session=pre-commit -- install
|
||||
|
||||
It is recommended to open an issue before starting work on anything.
|
||||
This will allow a chance to talk it over with the owners and validate your approach.
|
||||
|
||||
.. _pull request: https://github.com/xlorepdarkhelm/plex-playlist/pulls
|
||||
.. github-only
|
||||
.. _Code of Conduct: CODE_OF_CONDUCT.rst
|
||||
20
Jenkinsfile
vendored
20
Jenkinsfile
vendored
@@ -1,20 +0,0 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker {
|
||||
image 'python:3.10-alpine3.14'
|
||||
args '--rm --name playlist-testing'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh 'echo ${USER}'
|
||||
sh 'set'
|
||||
sh 'pip3 install -U pip'
|
||||
sh 'pip3 install wheel nox nox_poetry poetry'
|
||||
sh 'nox --version'
|
||||
sh 'poetry --version'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
217
LICENSE
Normal file
217
LICENSE
Normal file
@@ -0,0 +1,217 @@
|
||||
Copyright 2025 Cliff Hill
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
22
LICENSE.rst
22
LICENSE.rst
@@ -1,22 +0,0 @@
|
||||
MIT License
|
||||
===========
|
||||
|
||||
Copyright © 2021 Cliff Hill
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
**The software is provided "as is", without warranty of any kind, express or
|
||||
implied, including but not limited to the warranties of merchantability,
|
||||
fitness for a particular purpose and noninfringement. In no event shall the
|
||||
authors or copyright holders be liable for any claim, damages or other
|
||||
liability, whether in an action of contract, tort or otherwise, arising from,
|
||||
out of or in connection with the software or the use or other dealings in the
|
||||
software.**
|
||||
73
README.md
Normal file
73
README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# Plex Playlist
|
||||
|
||||
[][pypi_]
|
||||
[][status]
|
||||
[][python version]
|
||||
[][license]
|
||||
|
||||
[][read the docs]
|
||||
[][tests]
|
||||
[][codecov]
|
||||
|
||||
[][pre-commit]
|
||||
[][black]
|
||||
|
||||
[pypi_]: https://pypi.org/project/plex-playlist/
|
||||
[status]: https://pypi.org/project/plex-playlist/
|
||||
[python version]: https://pypi.org/project/plex-playlist
|
||||
[read the docs]: https://plex-playlist.readthedocs.io/
|
||||
[tests]: https://github.com/xlorepdarkhelm/plex-playlist/actions?workflow=Tests
|
||||
[codecov]: https://app.codecov.io/gh/xlorepdarkhelm/plex-playlist
|
||||
[pre-commit]: https://github.com/pre-commit/pre-commit
|
||||
[black]: https://github.com/psf/black
|
||||
|
||||
## Features
|
||||
|
||||
- TODO
|
||||
|
||||
## Requirements
|
||||
|
||||
- TODO
|
||||
|
||||
## Installation
|
||||
|
||||
You can install _Plex Playlist_ via [pip] from [PyPI]:
|
||||
|
||||
```console
|
||||
$ pip install plex-playlist
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Please see the [Command-line Reference] for details.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are very welcome.
|
||||
To learn more, see the [Contributor Guide].
|
||||
|
||||
## License
|
||||
|
||||
Distributed under the terms of the [Apache 2.0 license][license],
|
||||
_Plex Playlist_ is free and open source software.
|
||||
|
||||
## Issues
|
||||
|
||||
If you encounter any problems,
|
||||
please [file an issue] along with a detailed description.
|
||||
|
||||
## Credits
|
||||
|
||||
This project was generated from [@cjolowicz]'s [Hypermodern Python Cookiecutter] template.
|
||||
|
||||
[@cjolowicz]: https://github.com/cjolowicz
|
||||
[pypi]: https://pypi.org/
|
||||
[hypermodern python cookiecutter]: https://github.com/cjolowicz/cookiecutter-hypermodern-python
|
||||
[file an issue]: https://github.com/xlorepdarkhelm/plex-playlist/issues
|
||||
[pip]: https://pip.pypa.io/
|
||||
|
||||
<!-- github-only -->
|
||||
|
||||
[license]: https://github.com/xlorepdarkhelm/plex-playlist/blob/main/LICENSE
|
||||
[contributor guide]: https://github.com/xlorepdarkhelm/plex-playlist/blob/main/CONTRIBUTING.md
|
||||
[command-line reference]: https://plex-playlist.readthedocs.io/en/latest/usage.html
|
||||
99
README.rst
99
README.rst
@@ -1,99 +0,0 @@
|
||||
Automated Daily Playlist Generator for Plex Music
|
||||
=================================================
|
||||
|
||||
|PyPI| |Python Version| |License|
|
||||
|
||||
|Read the Docs| |Tests| |Codecov|
|
||||
|
||||
|pre-commit| |Black|
|
||||
|
||||
.. |PyPI| image:: https://img.shields.io/pypi/v/plex-playlist.svg
|
||||
:target: https://pypi.org/project/plex-playlist/
|
||||
:alt: PyPI
|
||||
.. |Python Version| image:: https://img.shields.io/pypi/pyversions/plex-playlist
|
||||
:target: https://pypi.org/project/plex-playlist
|
||||
:alt: Python Version
|
||||
.. |License| image:: https://img.shields.io/pypi/l/plex-playlist
|
||||
:target: https://opensource.org/licenses/MIT
|
||||
:alt: License
|
||||
.. |Read the Docs| image:: https://img.shields.io/readthedocs/plex-playlist/latest.svg?label=Read%20the%20Docs
|
||||
:target: https://plex-playlist.readthedocs.io/
|
||||
:alt: Read the documentation at https://plex-playlist.readthedocs.io/
|
||||
.. |Tests| image:: https://github.com/xlorepdarkhelm/plex-playlist/workflows/Tests/badge.svg
|
||||
:target: https://github.com/xlorepdarkhelm/plex-playlist/actions?workflow=Tests
|
||||
:alt: Tests
|
||||
.. |Codecov| image:: https://codecov.io/gh/xlorepdarkhelm/plex-playlist/branch/main/graph/badge.svg
|
||||
:target: https://codecov.io/gh/xlorepdarkhelm/plex-playlist
|
||||
:alt: Codecov
|
||||
.. |pre-commit| image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
|
||||
:target: https://github.com/pre-commit/pre-commit
|
||||
:alt: pre-commit
|
||||
.. |Black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
||||
:target: https://github.com/psf/black
|
||||
:alt: Black
|
||||
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* TODO
|
||||
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
* TODO
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
You can install *Automated Daily Playlist Generator for Plex Music* via pip_ from PyPI_:
|
||||
|
||||
.. code:: console
|
||||
|
||||
$ pip install plex-playlist
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
Please see the `Command-line Reference <Usage_>`_ for details.
|
||||
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
Contributions are very welcome.
|
||||
To learn more, see the `Contributor Guide`_.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Distributed under the terms of the `MIT license`_,
|
||||
*Automated Daily Playlist Generator for Plex Music* is free and open source software.
|
||||
|
||||
|
||||
Issues
|
||||
------
|
||||
|
||||
If you encounter any problems,
|
||||
please `file an issue`_ along with a detailed description.
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
This project was generated from `@cjolowicz`_'s `Hypermodern Python Cookiecutter`_ template.
|
||||
|
||||
.. _@cjolowicz: https://github.com/cjolowicz
|
||||
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
|
||||
.. _MIT license: https://opensource.org/licenses/MIT
|
||||
.. _PyPI: https://pypi.org/
|
||||
.. _Hypermodern Python Cookiecutter: https://github.com/cjolowicz/cookiecutter-hypermodern-python
|
||||
.. _file an issue: https://github.com/xlorepdarkhelm/plex-playlist/issues
|
||||
.. _pip: https://pip.pypa.io/
|
||||
.. github-only
|
||||
.. _Contributor Guide: CONTRIBUTING.rst
|
||||
.. _Usage: https://plex-playlist.readthedocs.io/en/latest/usage.html
|
||||
@@ -1,4 +1,3 @@
|
||||
---
|
||||
comment: false
|
||||
coverage:
|
||||
status:
|
||||
|
||||
3
docs/codeofconduct.md
Normal file
3
docs/codeofconduct.md
Normal file
@@ -0,0 +1,3 @@
|
||||
```{include} ../CODE_OF_CONDUCT.md
|
||||
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
.. include:: ../CODE_OF_CONDUCT.rst
|
||||
11
docs/conf.py
11
docs/conf.py
@@ -1,15 +1,12 @@
|
||||
"""Sphinx configuration."""
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
project = "Automated Daily Playlist Generator for Plex Music"
|
||||
project = "Plex Playlist"
|
||||
author = "Cliff Hill"
|
||||
copyright = f"{datetime.now().year}, {author}"
|
||||
copyright = "2025, Cliff Hill"
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx_click",
|
||||
"sphinx_rtd_theme",
|
||||
"myst_parser",
|
||||
]
|
||||
autodoc_typehints = "description"
|
||||
html_theme = "sphinx_rtd_theme"
|
||||
html_theme = "furo"
|
||||
|
||||
7
docs/contributing.md
Normal file
7
docs/contributing.md
Normal file
@@ -0,0 +1,7 @@
|
||||
```{include} ../CONTRIBUTING.md
|
||||
---
|
||||
end-before: <!-- github-only -->
|
||||
---
|
||||
```
|
||||
|
||||
[code of conduct]: codeofconduct
|
||||
@@ -1,4 +0,0 @@
|
||||
.. include:: ../CONTRIBUTING.rst
|
||||
:end-before: github-only
|
||||
|
||||
.. _Code of Conduct: codeofconduct.html
|
||||
23
docs/index.md
Normal file
23
docs/index.md
Normal file
@@ -0,0 +1,23 @@
|
||||
```{include} ../README.md
|
||||
---
|
||||
end-before: <!-- github-only -->
|
||||
---
|
||||
```
|
||||
|
||||
[license]: license
|
||||
[contributor guide]: contributing
|
||||
[command-line reference]: usage
|
||||
|
||||
```{toctree}
|
||||
---
|
||||
hidden:
|
||||
maxdepth: 1
|
||||
---
|
||||
|
||||
usage
|
||||
reference
|
||||
contributing
|
||||
Code of Conduct <codeofconduct>
|
||||
License <license>
|
||||
Changelog <https://github.com/xlorepdarkhelm/plex-playlist/releases>
|
||||
```
|
||||
@@ -1,16 +0,0 @@
|
||||
.. include:: ../README.rst
|
||||
:end-before: github-only
|
||||
|
||||
.. _Contributor Guide: contributing.html
|
||||
.. _Usage: usage.html
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
:maxdepth: 1
|
||||
|
||||
usage
|
||||
reference
|
||||
contributing
|
||||
Code of Conduct <codeofconduct>
|
||||
License <license>
|
||||
Changelog <https://github.com/xlorepdarkhelm/plex-playlist/releases>
|
||||
7
docs/license.md
Normal file
7
docs/license.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# License
|
||||
|
||||
```{literalinclude} ../LICENSE
|
||||
---
|
||||
language: none
|
||||
---
|
||||
```
|
||||
@@ -1 +0,0 @@
|
||||
.. include:: ../LICENSE.rst
|
||||
8
docs/reference.md
Normal file
8
docs/reference.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Reference
|
||||
|
||||
## playlist
|
||||
|
||||
```{eval-rst}
|
||||
.. automodule:: playlist
|
||||
:members:
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
Reference
|
||||
=========
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
:backlinks: none
|
||||
|
||||
|
||||
playlist.__main__
|
||||
-----------------
|
||||
|
||||
.. automodule:: playlist.__main__
|
||||
:members:
|
||||
@@ -1,3 +1,4 @@
|
||||
sphinx==3.5.2
|
||||
sphinx-click==2.6.0
|
||||
sphinx-rtd-theme==0.5.1
|
||||
furo==2022.4.7
|
||||
sphinx==4.5.0
|
||||
sphinx-click==4.1.0
|
||||
myst_parser==0.17.2
|
||||
|
||||
7
docs/usage.md
Normal file
7
docs/usage.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Usage
|
||||
|
||||
```{eval-rst}
|
||||
.. click:: playlist.__main__:main
|
||||
:prog: plex-playlist
|
||||
:nested: full
|
||||
```
|
||||
@@ -1,6 +0,0 @@
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. click:: playlist.__main__:main
|
||||
:prog: plex-playlist
|
||||
:nested: full
|
||||
@@ -1,6 +0,0 @@
|
||||
[settings]
|
||||
line-length = 88
|
||||
multi_line_output = 5
|
||||
include_trailing_comma = true
|
||||
known_future_library = "future"
|
||||
indent = ' ' '
|
||||
20
mypy.ini
20
mypy.ini
@@ -1,20 +0,0 @@
|
||||
[mypy]
|
||||
check_untyped_defs = True
|
||||
disallow_any_generics = True
|
||||
disallow_incomplete_defs = True
|
||||
disallow_subclassing_any = True
|
||||
disallow_untyped_calls = True
|
||||
disallow_untyped_decorators = True
|
||||
disallow_untyped_defs = True
|
||||
no_implicit_optional = True
|
||||
no_implicit_reexport = True
|
||||
pretty = True
|
||||
show_column_numbers = True
|
||||
show_error_codes = True
|
||||
show_error_context = True
|
||||
strict_equality = True
|
||||
warn_redundant_casts = True
|
||||
warn_return_any = True
|
||||
warn_unreachable = True
|
||||
warn_unused_configs = True
|
||||
warn_unused_ignores = True
|
||||
145
noxfile.py
145
noxfile.py
@@ -1,16 +1,30 @@
|
||||
"""Nox sessions."""
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from textwrap import dedent
|
||||
|
||||
import nox
|
||||
from nox_poetry import Session
|
||||
from nox_poetry import session
|
||||
|
||||
|
||||
try:
|
||||
from nox_poetry import Session
|
||||
from nox_poetry import session
|
||||
except ImportError:
|
||||
message = f"""\
|
||||
Nox failed to import the 'nox-poetry' package.
|
||||
|
||||
Please install it using the following command:
|
||||
|
||||
{sys.executable} -m pip install nox-poetry"""
|
||||
raise SystemExit(dedent(message)) from None
|
||||
|
||||
|
||||
package = "playlist"
|
||||
python_versions = ["3.9"]
|
||||
python_versions = ["3.10", "3.9", "3.8", "3.7"]
|
||||
nox.needs_version = ">= 2021.6.6"
|
||||
nox.options.sessions = (
|
||||
"pre-commit",
|
||||
"safety",
|
||||
@@ -22,7 +36,7 @@ nox.options.sessions = (
|
||||
)
|
||||
|
||||
|
||||
def activate_virtualenv_in_precommit_hooks(session: Session) -> None: # noqa: CCR001
|
||||
def activate_virtualenv_in_precommit_hooks(session: Session) -> None:
|
||||
"""Activate virtualenv in hooks installed by pre-commit.
|
||||
|
||||
This function patches git hooks installed by pre-commit to activate the
|
||||
@@ -32,13 +46,42 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None: # noqa: C
|
||||
Args:
|
||||
session: The Session object.
|
||||
"""
|
||||
if session.bin is None:
|
||||
return # type: ignore [unreachable]
|
||||
assert session.bin is not None # noqa: S101
|
||||
|
||||
# Only patch hooks containing a reference to this session's bindir. Support
|
||||
# quoting rules for Python and bash, but strip the outermost quotes so we
|
||||
# can detect paths within the bindir, like <bindir>/python.
|
||||
bindirs = [
|
||||
bindir[1:-1] if bindir[0] in "'\"" else bindir
|
||||
for bindir in (repr(session.bin), shlex.quote(session.bin))
|
||||
]
|
||||
|
||||
virtualenv = session.env.get("VIRTUAL_ENV")
|
||||
if virtualenv is None:
|
||||
return
|
||||
|
||||
headers = {
|
||||
# pre-commit < 2.16.0
|
||||
"python": f"""\
|
||||
import os
|
||||
os.environ["VIRTUAL_ENV"] = {virtualenv!r}
|
||||
os.environ["PATH"] = os.pathsep.join((
|
||||
{session.bin!r},
|
||||
os.environ.get("PATH", ""),
|
||||
))
|
||||
""",
|
||||
# pre-commit >= 2.16.0
|
||||
"bash": f"""\
|
||||
VIRTUAL_ENV={shlex.quote(virtualenv)}
|
||||
PATH={shlex.quote(session.bin)}"{os.pathsep}$PATH"
|
||||
""",
|
||||
# pre-commit >= 2.17.0 on Windows forces sh shebang
|
||||
"/bin/sh": f"""\
|
||||
VIRTUAL_ENV={shlex.quote(virtualenv)}
|
||||
PATH={shlex.quote(session.bin)}"{os.pathsep}$PATH"
|
||||
""",
|
||||
}
|
||||
|
||||
hookdir = Path(".git") / "hooks"
|
||||
if not hookdir.is_dir():
|
||||
return
|
||||
@@ -47,36 +90,35 @@ def activate_virtualenv_in_precommit_hooks(session: Session) -> None: # noqa: C
|
||||
if hook.name.endswith(".sample") or not hook.is_file():
|
||||
continue
|
||||
|
||||
if not hook.read_bytes().startswith(b"#!"):
|
||||
continue
|
||||
|
||||
text = hook.read_text()
|
||||
bindir = repr(session.bin)[1:-1] # strip quotes
|
||||
if not (
|
||||
|
||||
if not any(
|
||||
Path("A") == Path("a") and bindir.lower() in text.lower() or bindir in text
|
||||
for bindir in bindirs
|
||||
):
|
||||
continue
|
||||
|
||||
lines = text.splitlines()
|
||||
if not (lines[0].startswith("#!") and "python" in lines[0].lower()):
|
||||
continue
|
||||
|
||||
header = dedent(
|
||||
f"""\
|
||||
import os
|
||||
os.environ["VIRTUAL_ENV"] = {virtualenv!r}
|
||||
os.environ["PATH"] = os.pathsep.join((
|
||||
{session.bin!r},
|
||||
os.environ.get("PATH", ""),
|
||||
))
|
||||
""",
|
||||
)
|
||||
|
||||
lines.insert(1, header)
|
||||
hook.write_text("\n".join(lines))
|
||||
for executable, header in headers.items():
|
||||
if executable in lines[0].lower():
|
||||
lines.insert(1, dedent(header))
|
||||
hook.write_text("\n".join(lines))
|
||||
break
|
||||
|
||||
|
||||
@session(name="pre-commit", python="3.9")
|
||||
@session(name="pre-commit", python=python_versions[0])
|
||||
def precommit(session: Session) -> None:
|
||||
"""Lint using pre-commit."""
|
||||
args = session.posargs or ["run", "--all-files", "--show-diff-on-failure"]
|
||||
args = session.posargs or [
|
||||
"run",
|
||||
"--all-files",
|
||||
"--hook-stage=manual",
|
||||
"--show-diff-on-failure",
|
||||
]
|
||||
session.install(
|
||||
"black",
|
||||
"darglint",
|
||||
@@ -85,22 +127,23 @@ def precommit(session: Session) -> None:
|
||||
"flake8-bugbear",
|
||||
"flake8-docstrings",
|
||||
"flake8-rst-docstrings",
|
||||
"isort",
|
||||
"pep8-naming",
|
||||
"pre-commit",
|
||||
"pre-commit-hooks",
|
||||
"reorder-python-imports",
|
||||
"pyupgrade",
|
||||
)
|
||||
session.run("pre-commit", *args)
|
||||
if args and args[0] == "install":
|
||||
activate_virtualenv_in_precommit_hooks(session)
|
||||
|
||||
|
||||
@session(python="3.9")
|
||||
@session(python=python_versions[0])
|
||||
def safety(session: Session) -> None:
|
||||
"""Scan dependencies for insecure packages."""
|
||||
requirements = session.poetry.export_requirements()
|
||||
session.install("safety")
|
||||
session.run("safety", "check", f"--file={requirements}", "--bare")
|
||||
session.run("safety", "check", "--full-report", f"--file={requirements}")
|
||||
|
||||
|
||||
@session(python=python_versions)
|
||||
@@ -108,7 +151,7 @@ def mypy(session: Session) -> None:
|
||||
"""Type-check using mypy."""
|
||||
args = session.posargs or ["src", "tests", "docs/conf.py"]
|
||||
session.install(".")
|
||||
session.install("mypy", "pytest", "pytest-asyncio", "pytest-mock", "types-all")
|
||||
session.install("mypy", "pytest")
|
||||
session.run("mypy", *args)
|
||||
if not session.posargs:
|
||||
session.run("mypy", f"--python-executable={sys.executable}", "noxfile.py")
|
||||
@@ -118,59 +161,59 @@ def mypy(session: Session) -> None:
|
||||
def tests(session: Session) -> None:
|
||||
"""Run the test suite."""
|
||||
session.install(".")
|
||||
session.install(
|
||||
"coverage[toml]",
|
||||
"pytest",
|
||||
"pytest-asyncio",
|
||||
"pytest-mock",
|
||||
"pygments",
|
||||
)
|
||||
session.install("coverage[toml]", "pytest", "pygments")
|
||||
try:
|
||||
session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs)
|
||||
finally:
|
||||
if session.interactive:
|
||||
session.notify("coverage")
|
||||
session.notify("coverage", posargs=[])
|
||||
|
||||
|
||||
@session
|
||||
@session(python=python_versions[0])
|
||||
def coverage(session: Session) -> None:
|
||||
"""Produce the coverage report."""
|
||||
# Do not use session.posargs unless this is the only session.
|
||||
nsessions = len(session._runner.manifest)
|
||||
has_args = session.posargs and nsessions == 1
|
||||
args = session.posargs if has_args else ["report"]
|
||||
args = session.posargs or ["report"]
|
||||
|
||||
session.install("coverage[toml]")
|
||||
|
||||
if not has_args and any(Path().glob(".coverage.*")):
|
||||
if not session.posargs and any(Path().glob(".coverage.*")):
|
||||
session.run("coverage", "combine")
|
||||
|
||||
session.run("coverage", *args)
|
||||
|
||||
|
||||
@session(python=python_versions)
|
||||
@session(python=python_versions[0])
|
||||
def typeguard(session: Session) -> None:
|
||||
"""Runtime type checking using Typeguard."""
|
||||
session.install(".")
|
||||
session.install("pytest", "pytest-asyncio", "pytest-mock", "typeguard", "pygments")
|
||||
session.install("pytest", "typeguard", "pygments")
|
||||
session.run("pytest", f"--typeguard-packages={package}", *session.posargs)
|
||||
|
||||
|
||||
@session(python=python_versions)
|
||||
def xdoctest(session: Session) -> None:
|
||||
"""Run examples with xdoctest."""
|
||||
args = session.posargs or ["all"]
|
||||
if session.posargs:
|
||||
args = [package, *session.posargs]
|
||||
else:
|
||||
args = [f"--modname={package}", "--command=all"]
|
||||
if "FORCE_COLOR" in os.environ:
|
||||
args.append("--colored=1")
|
||||
|
||||
session.install(".")
|
||||
session.install("xdoctest[colors]")
|
||||
session.run("python", "-m", "xdoctest", package, *args)
|
||||
session.run("python", "-m", "xdoctest", *args)
|
||||
|
||||
|
||||
@session(name="docs-build", python="3.9")
|
||||
@session(name="docs-build", python=python_versions[0])
|
||||
def docs_build(session: Session) -> None:
|
||||
"""Build the documentation."""
|
||||
args = session.posargs or ["docs", "docs/_build"]
|
||||
if not session.posargs and "FORCE_COLOR" in os.environ:
|
||||
args.insert(0, "--color")
|
||||
|
||||
session.install(".")
|
||||
session.install("sphinx", "sphinx-click", "sphinx-rtd-theme")
|
||||
session.install("sphinx", "sphinx-click", "furo", "myst-parser")
|
||||
|
||||
build_dir = Path("docs", "_build")
|
||||
if build_dir.exists():
|
||||
@@ -179,12 +222,12 @@ def docs_build(session: Session) -> None:
|
||||
session.run("sphinx-build", *args)
|
||||
|
||||
|
||||
@session(python="3.9")
|
||||
@session(python=python_versions[0])
|
||||
def docs(session: Session) -> None:
|
||||
"""Build and serve the documentation with live reloading on file changes."""
|
||||
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
|
||||
session.install(".")
|
||||
session.install("sphinx", "sphinx-autobuild", "sphinx-click", "sphinx-rtd-theme")
|
||||
session.install("sphinx", "sphinx-autobuild", "sphinx-click", "furo", "myst-parser")
|
||||
|
||||
build_dir = Path("docs", "_build")
|
||||
if build_dir.exists():
|
||||
|
||||
3675
poetry.lock
generated
3675
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,68 +1,81 @@
|
||||
[tool.poetry]
|
||||
name = "plex-playlist"
|
||||
version = "0.1.0"
|
||||
description = "Automated Daily Playlist Generator for Plex Music"
|
||||
version = "0.0.0"
|
||||
description = "Plex Playlist"
|
||||
authors = ["Cliff Hill <xlorep@darkhelm.org>"]
|
||||
license = "MIT"
|
||||
readme = "README.rst"
|
||||
homepage = "https://gitlab.com/xlorepdarkhelm/plex-playlist"
|
||||
repository = "https://gitlab.com/xlorepdarkhelm/plex-playlist"
|
||||
license = "Apache-2.0"
|
||||
readme = "README.md"
|
||||
homepage = "https://github.com/xlorepdarkhelm/plex-playlist"
|
||||
repository = "https://github.com/xlorepdarkhelm/plex-playlist"
|
||||
documentation = "https://plex-playlist.readthedocs.io"
|
||||
packages = [
|
||||
{ include = "playlist", from = "src" },
|
||||
]
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Development Status :: 2 - Pre-Alpha",
|
||||
]
|
||||
|
||||
[tool.poetry.urls]
|
||||
Changelog = "https://gitlab.com/xlorepdarkhelm/plex-playlist/releases"
|
||||
Changelog = "https://github.com/xlorepdarkhelm/plex-playlist/releases"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.10,<3.11"
|
||||
click = "^8.0.3"
|
||||
PlexAPI = "^4.5.2"
|
||||
appdirs = "^1.4.4"
|
||||
asyncpg = "^0.23.0"
|
||||
uvloop = "^0.15.2"
|
||||
desert = "^2020.11.18"
|
||||
numpy = "^1.21.2"
|
||||
typeguard = "^2.12.1"
|
||||
gino = "^1.0.1"
|
||||
quart = "^0.16.3"
|
||||
marshmallow-sqlalchemy = "^0.27.0"
|
||||
strictyaml = "^1.6.1"
|
||||
python = "^3.7"
|
||||
click = ">=8.0.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
typeguard = "^2.12.0"
|
||||
jupyter = "^1.0.0"
|
||||
pre-commit = "^2.13.0"
|
||||
pre-commit-hooks = "^4.0.1"
|
||||
pytest = "^6.2.5"
|
||||
pytest-asyncio = "^0.15.1"
|
||||
pytest-mock = "^3.6.1"
|
||||
black = "^22.1.0"
|
||||
types-all = "^1.0.0"
|
||||
|
||||
Pygments = ">=2.10.0"
|
||||
black = ">=21.10b0"
|
||||
coverage = {extras = ["toml"], version = ">=6.2"}
|
||||
darglint = ">=1.8.1"
|
||||
flake8 = ">=4.0.1"
|
||||
flake8-bandit = ">=2.1.2"
|
||||
flake8-bugbear = ">=21.9.2"
|
||||
flake8-docstrings = ">=1.6.0"
|
||||
flake8-rst-docstrings = ">=0.2.5"
|
||||
furo = ">=2021.11.12"
|
||||
isort = ">=5.10.1"
|
||||
mypy = ">=0.930"
|
||||
pep8-naming = ">=0.12.1"
|
||||
pre-commit = ">=2.16.0"
|
||||
pre-commit-hooks = ">=4.1.0"
|
||||
pytest = ">=6.2.5"
|
||||
pyupgrade = ">=2.29.1"
|
||||
safety = ">=1.10.3"
|
||||
sphinx = ">=4.3.2"
|
||||
sphinx-autobuild = ">=2021.3.14"
|
||||
sphinx-click = ">=3.0.2"
|
||||
typeguard = ">=2.13.3"
|
||||
xdoctest = {extras = ["colors"], version = ">=0.15.10"}
|
||||
myst-parser = {version = ">=0.16.1"}
|
||||
|
||||
[tool.poetry.scripts]
|
||||
plex-playlist = "playlist.__main__:main"
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ["py310"]
|
||||
|
||||
[tool.coverage.paths]
|
||||
source = ["src", "*/site-packages"]
|
||||
tests = ["tests", "*/tests"]
|
||||
|
||||
[tool.coverage.run]
|
||||
branch = true
|
||||
source = ["playlist"]
|
||||
source = ["playlist", "tests"]
|
||||
|
||||
[tool.coverage.report]
|
||||
show_missing = true
|
||||
fail_under = 100
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
force_single_line = true
|
||||
lines_after_imports = 2
|
||||
|
||||
[tool.mypy]
|
||||
strict = true
|
||||
warn_unreachable = true
|
||||
pretty = true
|
||||
show_column_numbers = true
|
||||
show_error_codes = true
|
||||
show_error_context = true
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
@@ -1 +1 @@
|
||||
"""Automated Daily Playlist Generator for Plex Music."""
|
||||
"""Plex Playlist."""
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
"""Command-line interface."""
|
||||
import click
|
||||
|
||||
from playlist.plex import server
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.version_option() # type: ignore
|
||||
@click.version_option()
|
||||
def main() -> None:
|
||||
"""Automated Daily Playlist Generator for Plex Music."""
|
||||
print(server)
|
||||
"""Plex Playlist."""
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
"""Package containing all data classes used for the application."""
|
||||
@@ -1,35 +0,0 @@
|
||||
"""Utility functions & classes used in the application."""
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
import typing
|
||||
|
||||
import desert
|
||||
import marshmallow
|
||||
|
||||
|
||||
DataSub = typing.TypeVar("DataSub", bound="BaseData")
|
||||
|
||||
|
||||
class BaseData:
|
||||
"""Base class for data classes in the application."""
|
||||
|
||||
@classmethod # type: ignore [misc]
|
||||
@property
|
||||
@functools.cache
|
||||
def Schema(cls: type[BaseData]) -> marshmallow.Schema: # noqa: N802
|
||||
"""The marshmallow Schema object for this data class."""
|
||||
return desert.schema(cls)
|
||||
|
||||
@classmethod
|
||||
def load(cls: type[BaseData], data: dict[str, object]) -> DataSub:
|
||||
"""Load the given data dictionary into a class instance."""
|
||||
return typing.cast(DataSub, cls.Schema.load(data)) # type: ignore [attr-defined]
|
||||
|
||||
def dump(self: BaseData) -> dict[str, object]:
|
||||
"""Dump the class instance into a data dictionary."""
|
||||
cls = type(self)
|
||||
return typing.cast(
|
||||
dict[str, object],
|
||||
cls.Schema.dump(self), # type: ignore [attr-defined]
|
||||
)
|
||||
@@ -1,53 +0,0 @@
|
||||
"""Application-level constants."""
|
||||
import concurrent.futures
|
||||
import dataclasses
|
||||
import datetime
|
||||
import pathlib
|
||||
|
||||
import appdirs # type: ignore
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _Defaults:
|
||||
BATCH_SIZE: int
|
||||
PROCESS_DELAY: int
|
||||
DURATION: int
|
||||
PLAYTIME: datetime.timedelta
|
||||
MAX_TRACKS: int
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class _Paths:
|
||||
CONFIG: pathlib.Path
|
||||
DATA: pathlib.Path
|
||||
CACHE: pathlib.Path
|
||||
LOG: pathlib.Path
|
||||
|
||||
|
||||
APPNAME = "plex-playlist"
|
||||
APPAUTHOR = "Cliff Hill"
|
||||
|
||||
|
||||
_dirs = appdirs.AppDirs(APPNAME, APPAUTHOR)
|
||||
|
||||
|
||||
DEFAULTS = _Defaults(
|
||||
BATCH_SIZE=1000,
|
||||
PROCESS_DELAY=0,
|
||||
DURATION=0,
|
||||
PLAYTIME=datetime.timedelta(days=1),
|
||||
MAX_TRACKS=0,
|
||||
)
|
||||
|
||||
|
||||
PROCESS_POOL = concurrent.futures.ProcessPoolExecutor()
|
||||
MAX_PROCESSES = PROCESS_POOL._max_workers # type: ignore [attr-defined]
|
||||
SETTINGS_FILENAME = "settings.yaml"
|
||||
|
||||
|
||||
PATHS = _Paths(
|
||||
CONFIG=pathlib.Path(_dirs.user_config_dir),
|
||||
DATA=pathlib.Path(_dirs.user_data_dir),
|
||||
CACHE=pathlib.Path(_dirs.user_cache_dir),
|
||||
LOG=pathlib.Path(_dirs.user_log_dir),
|
||||
)
|
||||
@@ -1,41 +0,0 @@
|
||||
"""Contains the data models used throughout the application."""
|
||||
import dataclasses
|
||||
import datetime
|
||||
|
||||
import desert
|
||||
import marshmallow
|
||||
|
||||
from playlist.data import base
|
||||
from playlist.data.sql import db
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Track(db.Model, base.BaseData): # type: ignore [misc]
|
||||
"""Model defining a Track object."""
|
||||
|
||||
___tablename__ = "tracks"
|
||||
|
||||
id: int = dataclasses.field(
|
||||
init=False,
|
||||
repr=False,
|
||||
default=db.Column(db.Integer(), primary_key=True),
|
||||
)
|
||||
plex_id: int = db.Column(db.Integer)
|
||||
track_num: int = db.Column(db.Integer)
|
||||
title: str = db.Column(db.String)
|
||||
artist: str = db.Column(db.String)
|
||||
album_num: int = db.Column(db.Integer)
|
||||
album: str = db.Column(db.String)
|
||||
album_artist: str = db.Column(db.String)
|
||||
duration: int = db.Column(db.Integer)
|
||||
comments: str = db.Column(db.String)
|
||||
added: datetime.datetime = db.Column(db.DateTime)
|
||||
play_count: int = db.Column(db.Integer)
|
||||
rating: int | None = dataclasses.field(
|
||||
default=db.Column(db.Integer(), nullable=True, default=None),
|
||||
metadata=desert.metadata(marshmallow.fields.Int(allow_none=True)),
|
||||
)
|
||||
played: datetime.datetime | None = dataclasses.field(
|
||||
default=db.Column(db.Integer, nullable=True, default=None),
|
||||
metadata=desert.metadata(marshmallow.fields.DateTime(allow_none=True)),
|
||||
)
|
||||
@@ -1,187 +0,0 @@
|
||||
"""Define and control the Settings object for the playlist app."""
|
||||
from __future__ import annotations
|
||||
|
||||
import collections.abc
|
||||
import contextlib
|
||||
import dataclasses
|
||||
import datetime
|
||||
import functools
|
||||
import getpass
|
||||
import json
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
import plexapi.myplex
|
||||
import strictyaml
|
||||
from playlist.data import base
|
||||
from playlist.data import const
|
||||
|
||||
|
||||
__all__ = ["get", "modify"]
|
||||
|
||||
|
||||
class YamlData(base.BaseData):
|
||||
"""Base class for strictyaml classes."""
|
||||
|
||||
@classmethod # type: ignore [misc]
|
||||
@property
|
||||
@functools.cache
|
||||
def strictyaml_schema(cls: type[YamlData]) -> strictyaml.Map:
|
||||
"""Get the strictyaml schema for this class."""
|
||||
field_map = {}
|
||||
for field in dataclasses.fields(cls):
|
||||
try:
|
||||
field_map[field.name] = globals()[field.type].strictyaml_schema
|
||||
except (KeyError, AttributeError):
|
||||
match field.type:
|
||||
case "int":
|
||||
field_type = strictyaml.Int
|
||||
case "str":
|
||||
field_type = strictyaml.Str
|
||||
case "float":
|
||||
field_type = strictyaml.Float
|
||||
case "datetime.timedelta":
|
||||
field_type = strictyaml.Int
|
||||
case "datetime.datetime":
|
||||
field_type = strictyaml.Datetime
|
||||
case _:
|
||||
raise TypeError
|
||||
field_map[field.name] = field_type()
|
||||
return strictyaml.Map(field_map)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class CredentialSettings(YamlData):
|
||||
"""Credentials component for Settings object."""
|
||||
|
||||
baseurl: str
|
||||
token: str
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[CredentialSettings]) -> CredentialSettings: # pragma: no cover
|
||||
"""Get the credentials to store in the Settings instance.
|
||||
|
||||
Returns:
|
||||
CredentialSettings: The dictionary containing the baseurl and token string
|
||||
to connect with.
|
||||
"""
|
||||
username = input("Plex Username: ")
|
||||
password = getpass.getpass("Plex Password: ")
|
||||
server = input("Plex Server: ")
|
||||
|
||||
account = plexapi.myplex.MyPlexAccount(username, password)
|
||||
plex = account.resource(server).connect()
|
||||
return CredentialSettings(baseurl=plex._baseurl, token=plex._token)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class DownloadSettings(YamlData):
|
||||
"""DownloadSettingser options for Settings object."""
|
||||
|
||||
batch_size: int
|
||||
process_delay: float
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[DownloadSettings]) -> DownloadSettings:
|
||||
return cls(
|
||||
batch_size=const.DEFAULTS.BATCH_SIZE,
|
||||
process_delay=const.DEFAULTS.PROCESS_DELAY,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class TrackSettings(YamlData):
|
||||
"""Track options for Settings object."""
|
||||
|
||||
duration: float
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[TrackSettings]) -> TrackSettings:
|
||||
return cls(duration=const.DEFAULTS.DURATION)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class PlaylistSettings(YamlData):
|
||||
"""Playlist options for Settings object."""
|
||||
|
||||
playtime: datetime.timedelta
|
||||
max_tracks: int
|
||||
|
||||
@classmethod
|
||||
def create(cls: type[PlaylistSettings]) -> PlaylistSettings:
|
||||
return cls(
|
||||
playtime=const.DEFAULTS.PLAYTIME,
|
||||
max_tracks=const.DEFAULTS.MAX_TRACKS,
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Settings(YamlData):
|
||||
"""Settings object, loaded from settings.yaml file."""
|
||||
|
||||
creds: CredentialSettings = dataclasses.field(
|
||||
default_factory=CredentialSettings.create,
|
||||
)
|
||||
download: DownloadSettings = dataclasses.field(
|
||||
default_factory=DownloadSettings.create,
|
||||
)
|
||||
track: TrackSettings = dataclasses.field(default_factory=TrackSettings.create)
|
||||
playlist: PlaylistSettings = dataclasses.field(
|
||||
default_factory=PlaylistSettings.create,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def yaml_read(
|
||||
cls: type[Settings],
|
||||
filepath: pathlib.Path,
|
||||
) -> Settings:
|
||||
"""Read the given YAML file and convert it into an object."""
|
||||
try:
|
||||
with filepath.open() as fp:
|
||||
yaml_data = strictyaml.load(fp.read(), cls.strictyaml_schema)
|
||||
return typing.cast(Settings, cls.load(yaml_data.data))
|
||||
except strictyaml.YAMLValidationError:
|
||||
return cls.yaml_create(filepath)
|
||||
|
||||
def yaml_write(self: Settings, filepath: pathlib.Path) -> None:
|
||||
"""Write this object as the given YAML file."""
|
||||
data: type(self).Dict = self.dump() # type: ignore [valid-type]
|
||||
|
||||
with filepath.open(mode="w") as fp:
|
||||
yaml_data = strictyaml.as_document(data)
|
||||
fp.write(yaml_data.as_yaml())
|
||||
|
||||
@classmethod
|
||||
def yaml_create(
|
||||
cls: type[Settings],
|
||||
filepath: pathlib.Path,
|
||||
) -> Settings: # pragma: no cover
|
||||
"""Create the YAML file with this object."""
|
||||
data = cls()
|
||||
data.yaml_write(filepath)
|
||||
return data
|
||||
|
||||
|
||||
@functools.cache
|
||||
def get() -> Settings: # pragma: no cover
|
||||
"""Get the Settings object instance."""
|
||||
filepath = const.PATHS.CONFIG / const.SETTINGS_FILENAME
|
||||
instance: Settings
|
||||
try:
|
||||
instance = Settings.yaml_read(filepath)
|
||||
except FileNotFoundError:
|
||||
const.PATHS.CONFIG.mkdir(parents=True, exist_ok=True)
|
||||
instance = Settings.yaml_create(filepath)
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def modify() -> collections.abc.Generator[Settings, None, None]: # pragma: no cover
|
||||
"""Provide the Settings object to make a modification and automatically save it."""
|
||||
s = get()
|
||||
try:
|
||||
yield s
|
||||
finally:
|
||||
filepath = const.PATHS.CONFIG / const.SETTINGS_FILENAME
|
||||
s.yaml_write(filepath)
|
||||
@@ -1,4 +0,0 @@
|
||||
"""Contains the gino DB connection for the application."""
|
||||
import gino
|
||||
|
||||
db = gino.Gino()
|
||||
284
src/playlist/loader.py
Normal file
284
src/playlist/loader.py
Normal file
@@ -0,0 +1,284 @@
|
||||
from plexapi.server import PlexServer
|
||||
import sys
|
||||
import os
|
||||
import toml
|
||||
import argparse
|
||||
from config_path import ConfigPath
|
||||
import asyncio
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import aiofiles
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Configuration file setup using config-path
|
||||
CONFIG_DIR: ConfigPath = ConfigPath("PlexPlaylist", "Plex", ".config")
|
||||
CONFIG_FILE: str = CONFIG_DIR.path("plex_config.toml")
|
||||
|
||||
# Executor for blocking operations
|
||||
executor: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=4)
|
||||
|
||||
@dataclass
|
||||
class Track:
|
||||
"""Dataclass representing a music track from Plex.
|
||||
|
||||
Attributes:
|
||||
track_number: The track number or "N/A" if not available.
|
||||
disc_number: The disc number or "N/A" if not applicable.
|
||||
title: The title of the track.
|
||||
track_artist: The artist of the track.
|
||||
album_title: The title of the album.
|
||||
album_artist: The artist of the album.
|
||||
year: The release year of the album or "N/A".
|
||||
genres: List of genres associated with the track.
|
||||
date_added: Date the track was added to the library (YYYY-MM-DD).
|
||||
last_played: Date the track was last played (YYYY-MM-DD) or "Never".
|
||||
play_count: Number of times the track has been played.
|
||||
rating: User rating of the track or "Not Rated".
|
||||
"""
|
||||
track_number: str
|
||||
disc_number: str
|
||||
title: str
|
||||
track_artist: str
|
||||
album_title: str
|
||||
album_artist: str
|
||||
year: str
|
||||
genres: list[str]
|
||||
date_added: str
|
||||
last_played: str
|
||||
play_count: int
|
||||
rating: str
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""String representation of the track for printing.
|
||||
|
||||
Returns:
|
||||
Formatted string with all track details.
|
||||
"""
|
||||
output: list[str] = [f"Track #{self.track_number}"]
|
||||
if self.disc_number != "N/A":
|
||||
output.append(f"Disc #{self.disc_number}")
|
||||
output.extend([
|
||||
f"Title: {self.title}",
|
||||
f"Track Artist: {self.track_artist}",
|
||||
f"Album: {self.album_title}",
|
||||
f"Album Artist: {self.album_artist}",
|
||||
f"Year: {self.year}",
|
||||
f"Genre: {', '.join(self.genres) if self.genres else 'N/A'}",
|
||||
f"Date Added: {self.date_added}",
|
||||
f"Last Played: {self.last_played}",
|
||||
f"Play Count: {self.play_count}",
|
||||
f"Rating: {self.rating}",
|
||||
"-" * 30
|
||||
])
|
||||
return "\n".join(output)
|
||||
|
||||
async def save_config(baseurl: str, token: str) -> None:
|
||||
"""Save Plex configuration to a local TOML file asynchronously.
|
||||
|
||||
Args:
|
||||
baseurl: The URL of the Plex server (e.g., http://192.168.1.100:32400).
|
||||
token: The authentication token for the Plex server.
|
||||
|
||||
Raises:
|
||||
Exception: If there's an error writing to the config file.
|
||||
"""
|
||||
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
|
||||
await loop.run_in_executor(executor, os.makedirs, os.path.dirname(CONFIG_FILE), {"exist_ok": True})
|
||||
|
||||
config: dict[str, dict[str, str]] = {
|
||||
"plex": {
|
||||
"baseurl": baseurl,
|
||||
"token": token
|
||||
}
|
||||
}
|
||||
async with aiofiles.open(CONFIG_FILE, 'w') as f:
|
||||
await f.write(toml.dumps(config))
|
||||
print("Configuration saved successfully")
|
||||
|
||||
async def load_config() -> tuple[str | None, str | None]:
|
||||
"""Load Plex configuration from local TOML file asynchronously.
|
||||
|
||||
Returns:
|
||||
A tuple of (baseurl, token) if found, else (None, None).
|
||||
"""
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
async with aiofiles.open(CONFIG_FILE, 'r') as f:
|
||||
content: str = await f.read()
|
||||
config: dict[str, dict[str, str]] = toml.loads(content)
|
||||
return config.get("plex", {}).get("baseurl"), config.get("plex", {}).get("token")
|
||||
return None, None
|
||||
|
||||
async def connect_to_plex(baseurl: str, token: str) -> PlexServer | None:
|
||||
"""Connect to Plex server with given credentials asynchronously.
|
||||
|
||||
Args:
|
||||
baseurl: The URL of the Plex server.
|
||||
token: The authentication token for the Plex server.
|
||||
|
||||
Returns:
|
||||
PlexServer instance if successful, None if connection fails.
|
||||
"""
|
||||
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
|
||||
try:
|
||||
plex: PlexServer = await loop.run_in_executor(executor, PlexServer, baseurl, token)
|
||||
return plex
|
||||
except Exception as e:
|
||||
print(f"Error connecting to Plex server: {e}")
|
||||
return None
|
||||
|
||||
async def process_track_batch(tracks: list, batch_start: int, batch_end: int, total_tracks: int) -> list[Track]:
|
||||
"""Process a batch of tracks asynchronously and return a list of Track objects.
|
||||
|
||||
Args:
|
||||
tracks: List of raw Plex track objects.
|
||||
batch_start: Starting index of the batch.
|
||||
batch_end: Ending index of the batch.
|
||||
total_tracks: Total number of tracks for progress reporting.
|
||||
|
||||
Returns:
|
||||
List of processed Track objects for this batch.
|
||||
"""
|
||||
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
|
||||
print(f"\nProcessing tracks {batch_start + 1}-{batch_end} of {total_tracks}")
|
||||
|
||||
batch_tracks: list[Track] = []
|
||||
for track in tracks[batch_start:batch_end]:
|
||||
track_number: str = track.index or "N/A"
|
||||
disc_number: str = track.parentIndex if hasattr(track, 'parentIndex') else "N/A"
|
||||
track_title: str = track.title or "Unknown Title"
|
||||
|
||||
# Wrap potentially blocking calls
|
||||
track_artist: str = track.originalTitle or (
|
||||
await loop.run_in_executor(executor, lambda t=track: t.artist().title if t.artist() else "Unknown Artist")
|
||||
)
|
||||
album_title: str = await loop.run_in_executor(executor, lambda t=track: t.album().title if t.album() else "Unknown Album")
|
||||
album_artist: str = await loop.run_in_executor(executor, lambda t=track:
|
||||
t.album().artist().title if t.album() and t.album().artist() else "Unknown Artist")
|
||||
year: str = await loop.run_in_executor(executor, lambda t=track: t.album().year if t.album() else "N/A")
|
||||
|
||||
genres: list = track.genres if hasattr(track, 'genres') and track.genres else []
|
||||
genre_list: list[str] = [genre.tag for genre in genres] if genres else []
|
||||
date_added: str = track.addedAt.strftime('%Y-%m-%d') if track.addedAt else "N/A"
|
||||
last_played: str = track.lastViewedAt.strftime('%Y-%m-%d') if track.lastViewedAt else "Never"
|
||||
play_count: int = track.viewCount if track.viewCount is not None else 0
|
||||
rating: str = track.userRating if track.userRating is not None else "Not Rated"
|
||||
|
||||
# Create Track instance and append to batch list
|
||||
track_data: Track = Track(
|
||||
track_number=track_number,
|
||||
disc_number=disc_number,
|
||||
title=track_title,
|
||||
track_artist=track_artist,
|
||||
album_title=album_title,
|
||||
album_artist=album_artist,
|
||||
year=year,
|
||||
genres=genre_list,
|
||||
date_added=date_added,
|
||||
last_played=last_played,
|
||||
play_count=play_count,
|
||||
rating=rating
|
||||
)
|
||||
batch_tracks.append(track_data)
|
||||
|
||||
return batch_tracks
|
||||
|
||||
async def get_music_tracks(plex: PlexServer, batch_size: int = 1000) -> list[Track]:
|
||||
"""Retrieve all music tracks from Plex server in batches and return combined list.
|
||||
|
||||
Args:
|
||||
plex: Connected PlexServer instance.
|
||||
batch_size: Number of tracks to process per batch. Defaults to 1000.
|
||||
|
||||
Returns:
|
||||
Combined list of all processed Track objects.
|
||||
|
||||
Raises:
|
||||
Exception: If there's an error retrieving tracks from the Plex server.
|
||||
"""
|
||||
try:
|
||||
# Get all music libraries
|
||||
loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
|
||||
sections: list = await loop.run_in_executor(executor, lambda: [s for s in plex.library.sections() if s.type == 'artist'])
|
||||
|
||||
if not sections:
|
||||
print("No music libraries found!")
|
||||
return []
|
||||
|
||||
# Collect all tracks from all music sections
|
||||
all_tracks: list = []
|
||||
for section in sections:
|
||||
print(f"\nCollecting tracks from library: {section.title}")
|
||||
tracks: list = await loop.run_in_executor(executor, section.search, {'libtype': 'track'})
|
||||
all_tracks.extend(tracks)
|
||||
|
||||
total_tracks: int = len(all_tracks)
|
||||
print(f"\nFound {total_tracks} tracks across all libraries")
|
||||
print("-" * 50)
|
||||
|
||||
if total_tracks == 0:
|
||||
print("No tracks found!")
|
||||
return []
|
||||
|
||||
# Create tasks for each batch
|
||||
tasks: list[asyncio.Task] = []
|
||||
for batch_start in range(0, total_tracks, batch_size):
|
||||
batch_end: int = min(batch_start + batch_size, total_tracks)
|
||||
tasks.append(process_track_batch(all_tracks, batch_start, batch_end, total_tracks))
|
||||
|
||||
# Run all batch tasks concurrently and gather results
|
||||
batch_results: list[list[Track]] = await asyncio.gather(*tasks)
|
||||
|
||||
# Efficiently combine all tracks from batches
|
||||
combined_tracks: list[Track] = []
|
||||
for batch in batch_results:
|
||||
combined_tracks.extend(batch)
|
||||
|
||||
# Print all tracks
|
||||
for track in combined_tracks:
|
||||
print(track)
|
||||
|
||||
return combined_tracks
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error retrieving music tracks: {e}")
|
||||
return []
|
||||
|
||||
async def main() -> None:
|
||||
"""Main entry point for the Plex Playlist Track Lister.
|
||||
|
||||
Parses command-line arguments, manages configuration, and retrieves tracks.
|
||||
"""
|
||||
parser: argparse.ArgumentParser = argparse.ArgumentParser(description="Plex Playlist Track Lister")
|
||||
parser.add_argument('--login', action='store_true', help="Force login and update credentials")
|
||||
parser.add_argument('--batch-size', type=int, default=1000,
|
||||
help="Number of tracks to process per batch (default: 1000)")
|
||||
args: argparse.Namespace = parser.parse_args()
|
||||
|
||||
# Try to load existing configuration
|
||||
baseurl: str | None
|
||||
token: str | None
|
||||
baseurl, token = await load_config()
|
||||
|
||||
# If no config exists or login is forced
|
||||
if args.login or not (baseurl and token):
|
||||
baseurl = input("Enter Plex server URL (e.g., http://192.168.1.100:32400): ").strip()
|
||||
token = input("Enter Plex token: ").strip()
|
||||
|
||||
# Test the connection
|
||||
plex: PlexServer | None = await connect_to_plex(baseurl, token)
|
||||
if plex:
|
||||
await save_config(baseurl, token)
|
||||
else:
|
||||
print("Failed to connect with provided credentials. Exiting.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
plex = await connect_to_plex(baseurl, token)
|
||||
if not plex:
|
||||
print("Stored credentials failed. Please use --login to update them.")
|
||||
sys.exit(1)
|
||||
|
||||
# Get and display music tracks with specified batch size
|
||||
tracks: list[Track] = await get_music_tracks(plex, batch_size=args.batch_size)
|
||||
print(f"\nTotal tracks retrieved: {len(tracks)}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1 +0,0 @@
|
||||
"""Package containing the full plexapi wrapper/implementation."""
|
||||
@@ -1,207 +0,0 @@
|
||||
"""Contains the code to communicate to the Plex server."""
|
||||
import asyncio
|
||||
import collections.abc
|
||||
import statistics
|
||||
import time
|
||||
import typing
|
||||
|
||||
import plexapi.audio # type: ignore [import]
|
||||
import plexapi.myplex # type: ignore [import]
|
||||
import plexapi.server # type: ignore [import]
|
||||
|
||||
from playlist import utils
|
||||
from playlist.data import const
|
||||
from playlist.data import models
|
||||
from playlist.data import settings
|
||||
|
||||
__all__ = ["gen_tracks", "total_track_count"]
|
||||
|
||||
throttle = asyncio.BoundedSemaphore(const.MAX_PROCESSES)
|
||||
|
||||
|
||||
def calc_delay(times: list[float], weights: list[float]) -> None:
|
||||
"""Calculate the process delay.
|
||||
|
||||
This is based on a weighted harmonic mean of the times the processes took in
|
||||
the last run.
|
||||
|
||||
Args:
|
||||
times: The list of times (as seconds) to use for the calculation.
|
||||
weights: The list of weights from 0 to < 1.0 for the calculation.
|
||||
"""
|
||||
with settings.modify() as s:
|
||||
avg_time_per_batch = utils.harmonic_mean(times, weights=weights)
|
||||
delay = avg_time_per_batch / const.MAX_PROCESSES
|
||||
s.download.process_delay = round(delay, ndigits=3)
|
||||
|
||||
|
||||
def calc_duration(durations: list[int]) -> None:
|
||||
"""Calculate the average duration and max tracks to play each day.
|
||||
|
||||
This is based on the geometric mean of the durations of every track loaded from
|
||||
Plex. The maximum tracks to load for a day is based on the average duration calculated
|
||||
and the amount of time that the system was played the previous day.
|
||||
|
||||
Args:
|
||||
durations: The list of durations (in seconds) for the calculation.
|
||||
"""
|
||||
with settings.modify() as s:
|
||||
avg_track_duration = statistics.geometric_mean(durations)
|
||||
s.track.duration = round(avg_track_duration / 1000, ndigits=3)
|
||||
playtime_seconds = s.playlist.playtime.total_seconds()
|
||||
s.playlist.max_tracks = int(playtime_seconds / avg_track_duration)
|
||||
|
||||
|
||||
async def gen_tracks(
|
||||
*,
|
||||
batch_size: int = settings.get().download.batch_size,
|
||||
) -> collections.abc.AsyncGenerator[models.Track, None]:
|
||||
"""Generate all Tracks from the Server, asynchronously.
|
||||
|
||||
Args:
|
||||
batch_size: determines how many Tracks are pulled from the Server at a time.
|
||||
|
||||
Yields:
|
||||
models.Track: The Track that was pulled from Plex.
|
||||
"""
|
||||
loop = asyncio.get_running_loop()
|
||||
times = []
|
||||
weights = []
|
||||
durations = []
|
||||
batches = [
|
||||
asyncio.create_task(_downloader(ndx, size, loop))
|
||||
async for ndx, size in _gen_batch_params(batch_size)
|
||||
]
|
||||
for batch_task in asyncio.as_completed(batches):
|
||||
process_time, batch = await batch_task
|
||||
weight = len(batch) / batch_size
|
||||
times.append(process_time * weight)
|
||||
weights.append(weight)
|
||||
for track in batch:
|
||||
durations.append(track.duration)
|
||||
yield track
|
||||
|
||||
calc_delay(times, weights)
|
||||
calc_duration(durations)
|
||||
|
||||
|
||||
async def total_track_count() -> int:
|
||||
"""Get the total number of tracks in the server.
|
||||
|
||||
Returns:
|
||||
int: The total number of tracks in plex.
|
||||
"""
|
||||
server = plexapi.server.PlexServer(**settings.get().creds.dump())
|
||||
loop = asyncio.get_running_loop()
|
||||
num_tracks: int = await loop.run_in_executor(
|
||||
None,
|
||||
(
|
||||
lambda: typing.cast(
|
||||
int,
|
||||
server.library.section("Music").totalViewSize("track"),
|
||||
)
|
||||
),
|
||||
)
|
||||
return num_tracks
|
||||
|
||||
|
||||
async def _downloader(
|
||||
pos: int,
|
||||
size: int,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
) -> tuple[float, list[models.Track]]:
|
||||
"""Download a batch of tracks from Plex, by running it inside a Process Pool.
|
||||
|
||||
Args:
|
||||
pos: The index number of the batch to retrieve.
|
||||
size: The size of the batch to retrieve.
|
||||
loop: The asyncio event loop to use.
|
||||
|
||||
Returns:
|
||||
tuple[float, list[models.Track]: The time (in seconds) to process, and
|
||||
the batch of Tracks that were retrieved, in dictionary form.
|
||||
"""
|
||||
async with throttle:
|
||||
start = time.time()
|
||||
batch = await loop.run_in_executor(
|
||||
const.PROCESS_POOL,
|
||||
_get_track_batch,
|
||||
size,
|
||||
pos,
|
||||
)
|
||||
end = time.time()
|
||||
process_time = end - start
|
||||
return process_time, batch
|
||||
|
||||
|
||||
def _get_track_batch(
|
||||
size: int,
|
||||
pos: int,
|
||||
) -> list[models.Track]:
|
||||
"""Get a batch of Tracks from the Plex Server.
|
||||
|
||||
Args:
|
||||
size: The size of the batch to retrieve.
|
||||
pos: The index number of the batch to retrieve.
|
||||
|
||||
Returns:
|
||||
list[models.Track]: The process time and list of Tracks retrieved,
|
||||
in dictionary form.
|
||||
"""
|
||||
server = plexapi.server.PlexServer(**settings.get().creds.dump())
|
||||
batch = server.library.section("Music").searchTracks(
|
||||
maxresults=size,
|
||||
container_start=pos,
|
||||
container_size=size,
|
||||
)
|
||||
return [_track_dump(track) for track in batch]
|
||||
|
||||
|
||||
def _track_dump(track: plexapi.audio.Track) -> models.Track:
|
||||
"""Convert a PlexAPI Audio Track object into a Track in dictionary form.
|
||||
|
||||
Args:
|
||||
track: The PlexAPI Audio Track to convert from.
|
||||
|
||||
Returns:
|
||||
models.Track: The dictionary form for the Track object converted to.
|
||||
"""
|
||||
return models.Track(
|
||||
plex_id=track.ratingKey,
|
||||
track_num=track.index,
|
||||
title=track.title,
|
||||
artist=track.artist().title,
|
||||
album_num=track.parentIndex,
|
||||
album=track.parentTitle,
|
||||
album_artist=track.grandparentTitle,
|
||||
duration=track.duration,
|
||||
rating=track.userRating,
|
||||
comments=track.summary,
|
||||
added=track.addedAt,
|
||||
play_count=track.viewCount,
|
||||
played=track.lastViewedAt,
|
||||
)
|
||||
|
||||
|
||||
async def _gen_batch_params(
|
||||
batch_size: int,
|
||||
) -> collections.abc.AsyncGenerator[tuple[int, int], None]:
|
||||
"""Generate parameters for batches to be processed with.
|
||||
|
||||
This slows down processing of the first few batches to allow for different process
|
||||
pool workers to be staggered, and make the processing more smooth.
|
||||
|
||||
Args:
|
||||
batch_size: determines how many Tracks are pulled from the Plex Server at a time.
|
||||
|
||||
Yields:
|
||||
tuple[int, int]: The batch index and batch size to process.
|
||||
"""
|
||||
quotient, remainder = divmod(await total_track_count(), batch_size)
|
||||
for ndx in range(quotient):
|
||||
if ndx and ndx < const.MAX_PROCESSES:
|
||||
await asyncio.sleep(settings.get().download.process_delay)
|
||||
yield ndx, batch_size
|
||||
if quotient and quotient < const.MAX_PROCESSES: # pragma: no cover
|
||||
await asyncio.sleep(settings.get().download.process_delay)
|
||||
yield quotient, remainder
|
||||
@@ -1,40 +0,0 @@
|
||||
"""Utility functions & classes used in the application."""
|
||||
from __future__ import annotations
|
||||
|
||||
import collections.abc
|
||||
import contextlib
|
||||
import datetime
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def time_this() -> collections.abc.Generator[None, None, None]: # pragma: no cover
|
||||
"""Context manager to time the execution of a block of code."""
|
||||
start = datetime.datetime.now()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
end = datetime.datetime.now()
|
||||
print(f"Elapsed time: {end - start}")
|
||||
|
||||
|
||||
def harmonic_mean(
|
||||
data: collections.abc.Sequence[float],
|
||||
*,
|
||||
weights: collections.abc.Sequence[float] | None = None,
|
||||
) -> float:
|
||||
"""Calculate the [weighted] harmonic mean of the given data.
|
||||
|
||||
Args:
|
||||
data: The sequence of values to calculate.
|
||||
weights: The sequence of weights to apply to the calculation. If not
|
||||
given it assumes all weights are 1.
|
||||
|
||||
Returns:
|
||||
float: The [weighted] harmonic mean of the data.
|
||||
"""
|
||||
if weights is None: # pragma: no cover
|
||||
weights = [1] * len(data)
|
||||
|
||||
numerator = sum(weights)
|
||||
denominator = sum(weight / value for weight, value in zip(weights, data))
|
||||
return numerator / denominator
|
||||
@@ -1 +0,0 @@
|
||||
"""Tests for the playlist.data package."""
|
||||
@@ -1,55 +0,0 @@
|
||||
"""Tests for the playlist.data.base module."""
|
||||
import dataclasses
|
||||
import datetime
|
||||
import typing
|
||||
|
||||
import pytest
|
||||
|
||||
from playlist.data import base
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Dummy(base.BaseData):
|
||||
"""Dummy class for tests."""
|
||||
|
||||
name: str
|
||||
some_id: int
|
||||
calc: float
|
||||
flag: bool
|
||||
modified: datetime.datetime
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummyobj() -> Dummy:
|
||||
"""Make a dummy object for testing."""
|
||||
return Dummy(
|
||||
name="Something",
|
||||
some_id=1,
|
||||
calc=0.1,
|
||||
flag=True,
|
||||
modified=datetime.datetime.now(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummydict(dummyobj: Dummy) -> dict[str, object]:
|
||||
"""Make a dummy dictionary for testing."""
|
||||
return {
|
||||
"name": dummyobj.name,
|
||||
"some_id": dummyobj.some_id,
|
||||
"calc": dummyobj.calc,
|
||||
"flag": dummyobj.flag,
|
||||
"modified": "T".join(str(dummyobj.modified).split(" ")),
|
||||
}
|
||||
|
||||
|
||||
def test_load(dummydict: dict[str, object], dummyobj: Dummy) -> None:
|
||||
"""Validate that <data class>.load() works."""
|
||||
result: Dummy = Dummy.load(dummydict)
|
||||
assert result == dummyobj
|
||||
|
||||
|
||||
def test_dump(dummydict: dict[str, typing.Any], dummyobj: Dummy) -> None:
|
||||
"""Validate that <data class instance>.dump() works."""
|
||||
result = dummyobj.dump()
|
||||
assert result == dummydict
|
||||
@@ -1,35 +0,0 @@
|
||||
"""Tests for validating the Settings object."""
|
||||
import base64
|
||||
import os
|
||||
import pathlib
|
||||
|
||||
import pytest
|
||||
|
||||
from playlist.data import settings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def example_settings() -> settings.Settings:
|
||||
"""Make testable Settings object."""
|
||||
return settings.Settings(
|
||||
creds=settings.CredentialSettings(
|
||||
baseurl="http://nowhere.huh",
|
||||
token=base64.b64encode(os.urandom(8)).decode("utf-8"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def settings_filepath(tmp_path: pathlib.Path) -> pathlib.Path:
|
||||
"""Get the path to use for the settings file."""
|
||||
return tmp_path / "fake_settings.yaml"
|
||||
|
||||
|
||||
def test_yaml(
|
||||
example_settings: settings.Settings,
|
||||
settings_filepath: pathlib.Path,
|
||||
) -> None:
|
||||
"""Test the YAML read/write operations."""
|
||||
example_settings.yaml_write(settings_filepath)
|
||||
result = example_settings.yaml_read(settings_filepath)
|
||||
assert result == example_settings
|
||||
@@ -1 +0,0 @@
|
||||
"""Tests for the playlist.plex package."""
|
||||
@@ -1,204 +0,0 @@
|
||||
"""Tests for the playlist.plex.server module."""
|
||||
import asyncio
|
||||
import datetime
|
||||
import unittest.mock
|
||||
|
||||
import pytest
|
||||
|
||||
from playlist.data import models
|
||||
from playlist.data import settings
|
||||
from playlist.plex import server
|
||||
|
||||
|
||||
def test_calc_delay(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the calc_delay function."""
|
||||
mock_settings = mocker.patch("playlist.plex.server.settings")
|
||||
mock_const = mocker.patch("playlist.plex.server.const")
|
||||
mock_s = mock_settings.modify.return_value.__enter__.return_value
|
||||
mock_const.MAX_PROCESSES = 1
|
||||
|
||||
times: list[float] = [100, 100, 100]
|
||||
weights: list[float] = [1, 1, 1]
|
||||
|
||||
server.calc_delay(times, weights)
|
||||
|
||||
result = mock_s.download.process_delay
|
||||
|
||||
assert result == 100
|
||||
|
||||
|
||||
def test_calc_duration(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the calc_duration function."""
|
||||
mock_settings = mocker.patch("playlist.plex.server.settings")
|
||||
durations = [100, 100, 100]
|
||||
mock_s = mock_settings.modify.return_value.__enter__.return_value
|
||||
mock_s.playlist.playtime.total_seconds.return_value = 300
|
||||
server.calc_duration(durations)
|
||||
result = mock_s.playlist.max_tracks
|
||||
assert result == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gen_tracks(mocker, fake_track): # type: ignore [no-untyped-def]
|
||||
"""Test the gen_tracks asynchronous generator."""
|
||||
mock_downloader = mocker.patch(
|
||||
"playlist.plex.server._downloader",
|
||||
new_callable=unittest.mock.AsyncMock,
|
||||
)
|
||||
mock_gen_batch_params = mocker.patch("playlist.plex.server._gen_batch_params")
|
||||
mock_models = mocker.patch("playlist.plex.server.models")
|
||||
mock_calc_delay = mocker.patch("playlist.plex.server.calc_delay")
|
||||
mock_calc_duration = mocker.patch("playlist.plex.server.calc_duration")
|
||||
mock_downloader.return_value = (1, [fake_track])
|
||||
|
||||
async def fake_gen_batch_params(*args): # type: ignore
|
||||
for item in [(0, 1), (1, 1)]:
|
||||
yield item
|
||||
|
||||
mock_gen_batch_params.side_effect = fake_gen_batch_params
|
||||
mock_models.Track.load.return_value.duration = 1
|
||||
|
||||
results = [item async for item in server.gen_tracks(batch_size=1)]
|
||||
|
||||
assert len(results) == 2
|
||||
assert mock_calc_delay.called
|
||||
assert mock_calc_duration.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_total_track_count(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the total_track_count coroutine."""
|
||||
mock_plexapi_server = mocker.patch("playlist.plex.server.plexapi.server")
|
||||
mock_server = mock_plexapi_server.PlexServer.return_value
|
||||
mock_total_view_size = mock_server.library.section.return_value.totalViewSize
|
||||
mock_total_view_size.return_value = 1
|
||||
|
||||
result = await server.total_track_count()
|
||||
|
||||
assert result == 1
|
||||
|
||||
|
||||
def test_get_creds(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the get_creds function."""
|
||||
mock_plexapi_myplex = mocker.patch("playlist.plex.server.plexapi.myplex")
|
||||
mock_input = mocker.patch("builtins.input")
|
||||
mock_getpass = mocker.patch("playlist.plex.server.getpass")
|
||||
mock_account = mock_plexapi_myplex.MyPlexAccount.return_value
|
||||
mock_plex = mock_account.resource.return_value.connect.return_value
|
||||
mock_plex._baseurl = "Not a valid URL"
|
||||
mock_plex._token = "Fake token"
|
||||
|
||||
expected = settings.CredentialSettings(
|
||||
baseurl=mock_plex._baseurl,
|
||||
token=mock_plex._token,
|
||||
)
|
||||
|
||||
result = server.get_creds()
|
||||
|
||||
assert result == expected
|
||||
assert mock_input.called
|
||||
assert mock_getpass.getpass.called
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_downloader(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the _downloader coroutine."""
|
||||
|
||||
async def fake_run_in_executor(*args): # type: ignore
|
||||
await asyncio.sleep(0.1)
|
||||
return "Fake batch"
|
||||
|
||||
mock_loop = unittest.mock.MagicMock()
|
||||
mock_loop.run_in_executor.side_effect = fake_run_in_executor
|
||||
|
||||
result = await server._downloader(1, 1, mock_loop)
|
||||
|
||||
process_time, batch = result
|
||||
|
||||
assert batch
|
||||
assert process_time >= 0.1
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_track(fake_plextrack): # type: ignore [no-untyped-def]
|
||||
"""Make a fake track dict object."""
|
||||
return models.Track(
|
||||
plex_id=fake_plextrack.ratingKey,
|
||||
track_num=fake_plextrack.index,
|
||||
title=fake_plextrack.title,
|
||||
artist=fake_plextrack.artist().title,
|
||||
album_num=fake_plextrack.parentIndex,
|
||||
album=fake_plextrack.parentTitle,
|
||||
album_artist=fake_plextrack.grandparentTitle,
|
||||
duration=fake_plextrack.duration,
|
||||
rating=fake_plextrack.userRating,
|
||||
comments=fake_plextrack.summary,
|
||||
added=fake_plextrack.addedAt,
|
||||
play_count=fake_plextrack.viewCount,
|
||||
played=fake_plextrack.lastViewedAt,
|
||||
)
|
||||
|
||||
|
||||
def test_get_track_batch(mocker, fake_track): # type: ignore [no-untyped-def]
|
||||
"""Test _get_track_batch function."""
|
||||
mock_plexapi_server = mocker.patch("playlist.plex.server.plexapi.server")
|
||||
mock_server = mock_plexapi_server.PlexServer.return_value
|
||||
mock_search_tracks = mock_server.library.section.return_value.searchTracks
|
||||
mock_search_tracks.return_value = ["Not a track."]
|
||||
mock_track_dump = mocker.patch("playlist.plex.server._track_dump")
|
||||
mock_track_dump.return_value = fake_track
|
||||
|
||||
result = server._get_track_batch(1, 1)
|
||||
|
||||
assert len(result)
|
||||
assert mock_track_dump.called
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_plextrack(): # type: ignore [no-untyped-def]
|
||||
"""Mock up a fake Plex track for testing."""
|
||||
mock_track = unittest.mock.MagicMock()
|
||||
mock_track.configure_mock(
|
||||
ratingKey=1,
|
||||
index=1,
|
||||
title="Nothing",
|
||||
parentIndex=1,
|
||||
parentTile="Nothing",
|
||||
grandparentTitle="Nothing",
|
||||
duration=1000,
|
||||
userRating=1,
|
||||
summary="Whatever",
|
||||
addedAt=datetime.datetime.now(),
|
||||
viewCount=1,
|
||||
lastViewedAt=None,
|
||||
)
|
||||
mock_track.artist.return_value.title = "Nothing"
|
||||
return mock_track
|
||||
|
||||
|
||||
def test_track_dump(fake_plextrack, fake_track): # type: ignore [no-untyped-def]
|
||||
"""Test the _track_dump function."""
|
||||
result = server._track_dump(fake_plextrack)
|
||||
|
||||
assert result == fake_track
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gen_batch_params(mocker): # type: ignore [no-untyped-def]
|
||||
"""Test the _gen_batch_params asynchronous generator."""
|
||||
mock_total_track_count = mocker.patch(
|
||||
"playlist.plex.server.total_track_count",
|
||||
new_callable=unittest.mock.AsyncMock,
|
||||
)
|
||||
mock_total_track_count.return_value = 12
|
||||
mock_const = mocker.patch("playlist.plex.server.const")
|
||||
mock_const.MAX_PROCESSES = 10
|
||||
mocker.patch("playlist.plex.server.settings")
|
||||
mocker.patch(
|
||||
"playlist.plex.server.asyncio",
|
||||
new_callable=unittest.mock.AsyncMock,
|
||||
)
|
||||
|
||||
result = [item async for item in server._gen_batch_params(5)]
|
||||
|
||||
assert len(result) == 3
|
||||
Reference in New Issue
Block a user