mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
autobpm: add types
This commit is contained in:
parent
e3776f1910
commit
ee2f114342
1 changed files with 13 additions and 8 deletions
|
|
@ -13,17 +13,22 @@
|
|||
|
||||
"""Uses Librosa to calculate the `bpm` field."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
import librosa
|
||||
from soundfile import LibsndfileError
|
||||
|
||||
from beets import ui, util
|
||||
from beets import util
|
||||
from beets.importer import ImportTask
|
||||
from beets.library import Item, Library
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.ui import Subcommand, should_write
|
||||
|
||||
|
||||
class AutoBPMPlugin(BeetsPlugin):
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self.config.add(
|
||||
{
|
||||
|
|
@ -36,20 +41,20 @@ class AutoBPMPlugin(BeetsPlugin):
|
|||
if self.config["auto"].get(bool):
|
||||
self.import_stages = [self.imported]
|
||||
|
||||
def commands(self):
|
||||
cmd = ui.Subcommand(
|
||||
def commands(self) -> list[Subcommand]:
|
||||
cmd = Subcommand(
|
||||
"autobpm", help="detect and add bpm from audio using Librosa"
|
||||
)
|
||||
cmd.func = self.command
|
||||
return [cmd]
|
||||
|
||||
def command(self, lib, opts, args):
|
||||
self.calculate_bpm(lib.items(ui.decargs(args)), write=ui.should_write())
|
||||
def command(self, lib: Library, _, args: list[str]) -> None:
|
||||
self.calculate_bpm(list(lib.items(args)), write=should_write())
|
||||
|
||||
def imported(self, session, task):
|
||||
def imported(self, _, task: ImportTask) -> None:
|
||||
self.calculate_bpm(task.imported_items())
|
||||
|
||||
def calculate_bpm(self, items, write=False):
|
||||
def calculate_bpm(self, items: list[Item], write: bool = False) -> None:
|
||||
overwrite = self.config["overwrite"].get(bool)
|
||||
|
||||
for item in items:
|
||||
|
|
|
|||
Loading…
Reference in a new issue