Replacing files fine tuning
This commit is contained in:
parent
bcc6634e34
commit
503ba36a88
@ -32,6 +32,12 @@ from thefuzz import process
|
|||||||
from string import ascii_lowercase as letters
|
from string import ascii_lowercase as letters
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
# ###################### SETTINGS #########################
|
||||||
|
process_multiple_matches = True
|
||||||
|
do_processing = True
|
||||||
|
process_no_matches = True
|
||||||
|
# #########################################################
|
||||||
|
|
||||||
|
|
||||||
def insensitive_glob(pattern):
|
def insensitive_glob(pattern):
|
||||||
def either(c):
|
def either(c):
|
||||||
@ -44,10 +50,6 @@ source_dir = '/home/kae/music/Singles/tmp' # os.getcwd()
|
|||||||
parent_dir = os.path.dirname(source_dir)
|
parent_dir = os.path.dirname(source_dir)
|
||||||
assert source_dir != parent_dir
|
assert source_dir != parent_dir
|
||||||
|
|
||||||
process_multiple_matches = True
|
|
||||||
do_processing = False
|
|
||||||
process_no_matches = True
|
|
||||||
|
|
||||||
name_and_tags: List[str] = []
|
name_and_tags: List[str] = []
|
||||||
name_not_tags: List[str] = []
|
name_not_tags: List[str] = []
|
||||||
tags_not_name: List[str] = []
|
tags_not_name: List[str] = []
|
||||||
@ -89,7 +91,7 @@ def main():
|
|||||||
matches = insensitive_glob(os.path.join(parent_dir, stem) + '*')
|
matches = insensitive_glob(os.path.join(parent_dir, stem) + '*')
|
||||||
match_count = len(matches)
|
match_count = len(matches)
|
||||||
if match_count == 0:
|
if match_count == 0:
|
||||||
no_match.append(f"{fname}, {us_t=}, {us_a=}")
|
if process_no_matches:
|
||||||
print(f"\n file={fname}\n title={us_t}\n artist={us_a}\n")
|
print(f"\n file={fname}\n title={us_t}\n artist={us_a}\n")
|
||||||
# Try fuzzy search
|
# Try fuzzy search
|
||||||
d = {}
|
d = {}
|
||||||
@ -102,20 +104,34 @@ def main():
|
|||||||
print(f"{k}: {v}")
|
print(f"{k}: {v}")
|
||||||
data = input("pick one, return to quit: ")
|
data = input("pick one, return to quit: ")
|
||||||
if data == "":
|
if data == "":
|
||||||
|
no_match.append(f"{fname}, {us_t=}, {us_a=}")
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
key = int(data)
|
key = int(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
if key in d:
|
if key in d:
|
||||||
print("***KAE confirm with tags")
|
old_file = os.path.join(parent_dir, d[key])
|
||||||
dst = d[key]
|
oldtags = get_tags(old_file)
|
||||||
process_track(new_file, dst, us_t, us_a)
|
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
|
break
|
||||||
else:
|
else:
|
||||||
|
no_match.append(f"{fname}, {us_t=}, {us_a=}")
|
||||||
continue
|
continue
|
||||||
continue # from break after testing for "" in data
|
no_match.append(f"{fname}, {us_t=}, {us_a=}")
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
no_match.append(f"{fname}, {us_t=}, {us_a=}")
|
||||||
|
continue
|
||||||
|
|
||||||
if match_count > 1:
|
if match_count > 1:
|
||||||
multiple_similar.append(fname + "\n " + "\n ".join(matches))
|
multiple_similar.append(fname + "\n " + "\n ".join(matches))
|
||||||
if match_count <= 26 and process_multiple_matches:
|
if match_count <= 26 and process_multiple_matches:
|
||||||
@ -204,7 +220,10 @@ def process_track(src, dst, title, artist):
|
|||||||
|
|
||||||
os.unlink(dst)
|
os.unlink(dst)
|
||||||
shutil.move(src, new_path)
|
shutil.move(src, new_path)
|
||||||
|
try:
|
||||||
track = Tracks.get_by_path(session, new_path)
|
track = Tracks.get_by_path(session, new_path)
|
||||||
|
except:
|
||||||
|
import ipdb; ipdb.set_trace()
|
||||||
if track:
|
if track:
|
||||||
track.rescan(session)
|
track.rescan(session)
|
||||||
else:
|
else:
|
||||||
|
|||||||
20
poetry.lock
generated
20
poetry.lock
generated
@ -366,6 +366,14 @@ category = "dev"
|
|||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8,<4.0"
|
python-versions = ">=3.8,<4.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pyfzf"
|
||||||
|
version = "0.3.1"
|
||||||
|
description = "Python wrapper for junegunn's fuzzyfinder (fzf)"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pygments"
|
name = "pygments"
|
||||||
version = "2.11.2"
|
version = "2.11.2"
|
||||||
@ -481,6 +489,14 @@ pytest = ">=3.0.0"
|
|||||||
dev = ["pre-commit", "tox"]
|
dev = ["pre-commit", "tox"]
|
||||||
doc = ["sphinx", "sphinx-rtd-theme"]
|
doc = ["sphinx", "sphinx-rtd-theme"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-levenshtein"
|
||||||
|
version = "0.12.2"
|
||||||
|
description = "Python extension for computing string edit distances and similarities."
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-slugify"
|
name = "python-slugify"
|
||||||
version = "6.1.2"
|
version = "6.1.2"
|
||||||
@ -655,7 +671,7 @@ python-versions = "*"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.9"
|
python-versions = "^3.9"
|
||||||
content-hash = "f56b509dd26d76adcd2c01ee04f9e80ed736fb5189b27bcb5e005fc50ba773c9"
|
content-hash = "b181eb743e8b6c9cb7e03c4db0bcef425fe410d2ec3c4c801ce20e448a26f166"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
alembic = [
|
alembic = [
|
||||||
@ -928,6 +944,7 @@ pydub = [
|
|||||||
{file = "pydub-0.25.1.tar.gz", hash = "sha256:980a33ce9949cab2a569606b65674d748ecbca4f0796887fd6f46173a7b0d30f"},
|
{file = "pydub-0.25.1.tar.gz", hash = "sha256:980a33ce9949cab2a569606b65674d748ecbca4f0796887fd6f46173a7b0d30f"},
|
||||||
]
|
]
|
||||||
pydub-stubs = []
|
pydub-stubs = []
|
||||||
|
pyfzf = []
|
||||||
pygments = [
|
pygments = [
|
||||||
{file = "Pygments-2.11.2-py3-none-any.whl", hash = "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65"},
|
{file = "Pygments-2.11.2-py3-none-any.whl", hash = "sha256:44238f1b60a76d78fc8ca0528ee429702aae011c265fe6a8dd8b63049ae41c65"},
|
||||||
{file = "Pygments-2.11.2.tar.gz", hash = "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a"},
|
{file = "Pygments-2.11.2.tar.gz", hash = "sha256:4e426f72023d88d03b2fa258de560726ce890ff3b630f88c21cbb8b2503b8c6a"},
|
||||||
@ -997,6 +1014,7 @@ pytest-qt = [
|
|||||||
{file = "pytest-qt-4.0.2.tar.gz", hash = "sha256:dfc5240dec7eb43b76bcb5f9a87eecae6ef83592af49f3af5f1d5d093acaa93e"},
|
{file = "pytest-qt-4.0.2.tar.gz", hash = "sha256:dfc5240dec7eb43b76bcb5f9a87eecae6ef83592af49f3af5f1d5d093acaa93e"},
|
||||||
{file = "pytest_qt-4.0.2-py2.py3-none-any.whl", hash = "sha256:e03847ac02a890ccaac0fde1748855b9dce425aceba62005c6cfced6cf7d5456"},
|
{file = "pytest_qt-4.0.2-py2.py3-none-any.whl", hash = "sha256:e03847ac02a890ccaac0fde1748855b9dce425aceba62005c6cfced6cf7d5456"},
|
||||||
]
|
]
|
||||||
|
python-levenshtein = []
|
||||||
python-slugify = []
|
python-slugify = []
|
||||||
python-vlc = [
|
python-vlc = [
|
||||||
{file = "python-vlc-3.0.16120.tar.gz", hash = "sha256:92f98fee088f72bd6d063b3b3312d0bd29b37e7ad65ddeb3a7303320300c2807"},
|
{file = "python-vlc-3.0.16120.tar.gz", hash = "sha256:92f98fee088f72bd6d063b3b3312d0bd29b37e7ad65ddeb3a7303320300c2807"},
|
||||||
|
|||||||
@ -20,6 +20,8 @@ PyQt5-sip = "^12.9.1"
|
|||||||
types-psutil = "^5.8.22"
|
types-psutil = "^5.8.22"
|
||||||
python-slugify = "^6.1.2"
|
python-slugify = "^6.1.2"
|
||||||
thefuzz = "^0.19.0"
|
thefuzz = "^0.19.0"
|
||||||
|
python-Levenshtein = "^0.12.2"
|
||||||
|
pyfzf = "^0.3.1"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
ipdb = "^0.13.9"
|
ipdb = "^0.13.9"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user