diff --git a/app/replace_files.py b/app/replace_files.py index 9642917..1e52673 100755 --- a/app/replace_files.py +++ b/app/replace_files.py @@ -15,6 +15,7 @@ import glob import os +import pydymenu import shutil import sys @@ -33,9 +34,9 @@ from sqlalchemy.exc import IntegrityError from typing import List # ###################### SETTINGS ######################### -process_multiple_matches = False -do_processing = False -process_no_matches = False +process_multiple_matches = True +do_processing = True +process_no_matches = True # ######################################################### @@ -96,37 +97,28 @@ def main(): match_count = len(matches) if match_count == 0: if process_no_matches: - print(f"\n file={fname}\n title={us_t}\n artist={us_a}\n") - # Try fuzzy search - d = {} - while True: - for i, match in enumerate( - [a[0] for a in process.extract(fname, tracks, limit=5)] - ): - d[i] = match - for k, v in d.items(): - print(f"{k}: {v}") - data = input("pick one, return to quit: ") - if data == "": - no_match.append(f"{fname}, {us_t=}, {us_a=}") - break - try: - key = int(data) - except ValueError: + prompt = f"\n file={fname}\n title={us_t}\n artist={us_a}: " + # Use fzf to search + choice = pydymenu.fzf(tracks, prompt) + if choice: + old_file = os.path.join(parent_dir, choice[0]) + oldtags = get_tags(old_file) + old_title = oldtags['title'] + old_artist = oldtags['artist'] + print() + print(f" File name will change {choice[0]}") + print(f" → {fname}") + print() + print(f" Title tag will change {old_title}") + print(f" → {us_t}") + print() + print(f" Artist tag will change {old_artist}") + print(f" → {us_a}") + print() + data = input("Go ahead (y to accept)? ") + if data == "y": + process_track(new_file, old_file, us_t, us_a) continue - if key in d: - old_file = os.path.join(parent_dir, d[key]) - oldtags = get_tags(old_file) - old_title = oldtags['title'] - old_artist = oldtags['artist'] - print() - print(f" Title tag will change {old_title} → {us_t}") - print(f" Artist tag will change {old_artist} → {us_a}") - print() - data = input("Go ahead (y to accept)? ") - if data == "y": - process_track(new_file, old_file, us_t, us_a) - break else: no_match.append(f"{fname}, {us_t=}, {us_a=}") continue diff --git a/poetry.lock b/poetry.lock index a0c289a..b816256 100644 --- a/poetry.lock +++ b/poetry.lock @@ -73,6 +73,17 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +[[package]] +name = "commonmark" +version = "0.9.1" +description = "Python parser for the CommonMark Markdown spec" +category = "main" +optional = false +python-versions = "*" + +[package.extras] +test = ["hypothesis (==3.55.3)", "flake8 (==3.7.8)"] + [[package]] name = "decorator" version = "5.1.1" @@ -366,6 +377,17 @@ category = "dev" optional = false python-versions = ">=3.8,<4.0" +[[package]] +name = "pydymenu" +version = "0.5.2" +description = "A pythonic wrapper interface for fzf, dmenu, and rofi." +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +rich = "*" + [[package]] name = "pyfzf" version = "0.3.1" @@ -378,7 +400,7 @@ python-versions = "*" name = "pygments" version = "2.11.2" description = "Pygments is a syntax highlighting package written in Python." -category = "dev" +category = "main" optional = false python-versions = ">=3.5" @@ -519,6 +541,21 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "rich" +version = "12.5.1" +description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" +category = "main" +optional = false +python-versions = ">=3.6.3,<4.0.0" + +[package.dependencies] +commonmark = ">=0.9.0,<0.10.0" +pygments = ">=2.6.0,<3.0.0" + +[package.extras] +jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"] + [[package]] name = "six" version = "1.16.0" @@ -671,7 +708,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "b181eb743e8b6c9cb7e03c4db0bcef425fe410d2ec3c4c801ce20e448a26f166" +content-hash = "91e055875df86707e1ce1544b1d29126265011d750897912daa37af3fe005498" [metadata.files] alembic = [ @@ -702,6 +739,7 @@ colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] +commonmark = [] decorator = [ {file = "decorator-5.1.1-py3-none-any.whl", hash = "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186"}, {file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"}, @@ -944,6 +982,7 @@ pydub = [ {file = "pydub-0.25.1.tar.gz", hash = "sha256:980a33ce9949cab2a569606b65674d748ecbca4f0796887fd6f46173a7b0d30f"}, ] pydub-stubs = [] +pydymenu = [] pyfzf = [] pygments = [ {file = "Pygments-2.11.2-py3-none-any.whl", hash = "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65"}, @@ -1020,6 +1059,7 @@ python-vlc = [ {file = "python-vlc-3.0.16120.tar.gz", hash = "sha256:92f98fee088f72bd6d063b3b3312d0bd29b37e7ad65ddeb3a7303320300c2807"}, {file = "python_vlc-3.0.16120-py3-none-any.whl", hash = "sha256:c409afb38fe9f788a663b4302ca583f31289ef0860ab2b1668da96bbe8f14bfc"}, ] +rich = [] six = [ {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, diff --git a/pyproject.toml b/pyproject.toml index db24b5a..1b3fdd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ python-slugify = "^6.1.2" thefuzz = "^0.19.0" python-Levenshtein = "^0.12.2" pyfzf = "^0.3.1" +pydymenu = "^0.5.2" [tool.poetry.dev-dependencies] ipdb = "^0.13.9"