mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-21 05:18:08 +09:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e84fec706 | ||
|
|
12bea3e0e8 | ||
|
|
c61029a9f3 | ||
|
|
c1aee2a680 | ||
|
|
9fa527aa59 | ||
|
|
e641b8e639 | ||
|
|
abaa9b5351 |
No files matched your search
@@ -1,28 +0,0 @@
|
||||
2384d2383
|
||||
< triton = ">=2.0.0,<3"
|
||||
4185d4183
|
||||
< triton = {version = "2.3.1", markers = "platform_system == \"Linux\" and platform_machine == \"x86_64\" and python_version < \"3.12\""}
|
||||
4318,4340d4315
|
||||
< name = "triton"
|
||||
< version = "2.3.1"
|
||||
< description = "A language and compiler for custom Deep Learning operations"
|
||||
< optional = false
|
||||
< python-versions = "*"
|
||||
< files = [
|
||||
< {file = "triton-2.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3c84595cbe5e546b1b290d2a58b1494df5a2ef066dd890655e5b8a8a92205c33"},
|
||||
< {file = "triton-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c9d64ae33bcb3a7a18081e3a746e8cf87ca8623ca13d2c362413ce7a486f893e"},
|
||||
< {file = "triton-2.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:eaf80e8761a9e3498aa92e7bf83a085b31959c61f5e8ac14eedd018df6fccd10"},
|
||||
< {file = "triton-2.3.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b13bf35a2b659af7159bf78e92798dc62d877aa991de723937329e2d382f1991"},
|
||||
< {file = "triton-2.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:63381e35ded3304704ea867ffde3b7cfc42c16a55b3062d41e017ef510433d66"},
|
||||
< {file = "triton-2.3.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1d968264523c7a07911c8fb51b4e0d1b920204dae71491b1fe7b01b62a31e124"},
|
||||
< ]
|
||||
<
|
||||
< [package.dependencies]
|
||||
< filelock = "*"
|
||||
<
|
||||
< [package.extras]
|
||||
< build = ["cmake (>=3.20)", "lit"]
|
||||
< tests = ["autopep8", "flake8", "isort", "numpy", "pytest", "scipy (>=1.7.1)", "torch"]
|
||||
< tutorials = ["matplotlib", "pandas", "tabulate", "torch"]
|
||||
<
|
||||
< [[package]]
|
||||
@@ -17,35 +17,3 @@ jobs:
|
||||
pypi-token: ${{ secrets.PYPI_API_TOKEN }}
|
||||
gh-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
parse-changelog: false
|
||||
|
||||
# build-windows:
|
||||
# runs-on: windows-latest
|
||||
|
||||
# steps:
|
||||
# - uses: actions/checkout@v2
|
||||
|
||||
# - name: Set up Python
|
||||
# uses: actions/setup-python@v2
|
||||
# with:
|
||||
# python-version: '3.9'
|
||||
|
||||
# - name: Install dependencies with Poetry
|
||||
# run: |
|
||||
# pip install poetry
|
||||
# poetry install
|
||||
|
||||
# - name: Download ffmpeg binary
|
||||
# run: python platform/download_ffmpeg.py
|
||||
|
||||
# - name: Build EXE with PyInstaller
|
||||
# run: poetry run pyinstaller karaoke-gen.spec
|
||||
|
||||
# - name: Upload EXE as Artifact
|
||||
# uses: actions/upload-artifact@v2
|
||||
# with:
|
||||
# name: karaoke-gen-windows
|
||||
# path: |
|
||||
# build/
|
||||
# *.exe
|
||||
# */*.exe
|
||||
|
||||
+4
-4
@@ -5,10 +5,10 @@
|
||||
*.mp3
|
||||
|
||||
# Andrew functional adds
|
||||
audio/
|
||||
lyrics/
|
||||
karaoke/
|
||||
tests/outputs
|
||||
/audio/
|
||||
/lyrics/
|
||||
/karaoke/
|
||||
/tests/outputs
|
||||
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 karaokenerds
|
||||
Copyright (c) 2025 Nomad Karaoke LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -27,6 +27,9 @@ karaoke-gen "https://www.youtube.com/watch?v=dQw4w9WgXcQ" "Rick Astley" "Never G
|
||||
|
||||
# Or let it search YouTube for you
|
||||
karaoke-gen "Rick Astley" "Never Gonna Give You Up"
|
||||
|
||||
# Process multiple tracks in bulk from a CSV file
|
||||
karaoke-bulk input.csv --style_params_json=style.json
|
||||
```
|
||||
|
||||
## Workflow Options
|
||||
@@ -82,12 +85,58 @@ karaoke-gen --youtube_client_secrets_file="path/to/client_secret.json" --youtube
|
||||
karaoke-gen --brand_prefix="BRAND" --organised_dir="path/to/Tracks-Organized" "Rick Astley" "Never Gonna Give You Up"
|
||||
```
|
||||
|
||||
## Python API
|
||||
|
||||
Karaoke Gen can also be used as a Python library:
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
from karaoke_gen import KaraokeController, ProjectConfig
|
||||
|
||||
async def generate_karaoke():
|
||||
# Create a configuration
|
||||
config = ProjectConfig(
|
||||
artist="Rick Astley",
|
||||
title="Never Gonna Give You Up",
|
||||
input_media="https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
output_dir="output",
|
||||
create_track_subfolders=True,
|
||||
)
|
||||
|
||||
# Create a controller
|
||||
controller = KaraokeController(config)
|
||||
|
||||
# Process the track
|
||||
tracks = await controller.process()
|
||||
|
||||
# Print the output files
|
||||
for track in tracks:
|
||||
print(f"Final video: {track.final_video}")
|
||||
|
||||
# Run the async function
|
||||
asyncio.run(generate_karaoke())
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
Karaoke Gen has a modular architecture with the following components:
|
||||
|
||||
- **Controller**: Orchestrates the entire process
|
||||
- **Services**: Handle specific aspects of the process
|
||||
- **Media Service**: Downloads and extracts media
|
||||
- **Audio Service**: Separates and processes audio
|
||||
- **Lyrics Service**: Fetches and synchronizes lyrics
|
||||
- **Video Service**: Renders video with synchronized lyrics
|
||||
- **Distribution Service**: Organizes and shares the output files
|
||||
- **Utilities**: Common utility functions for file handling, logging, etc.
|
||||
|
||||
## Full Command Reference
|
||||
|
||||
For a complete list of options:
|
||||
|
||||
```bash
|
||||
karaoke-gen --help
|
||||
karaoke-bulk --help
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
# Generated by conda-lock.
|
||||
# platform: linux-64
|
||||
# input_hash: f64a1c4f40227315aea520256e9eb1b2ede7cf46e8f7ba4636b8299642464004
|
||||
@EXPLICIT
|
||||
https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2#d7c89558ba9fa0495403155b64376d81
|
||||
https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2023.11.17-hbcca054_0.conda#01ffc8d36f9eba0ce0b3c1955fa780ee
|
||||
https://conda.anaconda.org/conda-forge/linux-64/ld_impl_linux-64-2.40-h41732ed_0.conda#7aca3059a1729aa76c597603f10b0dd3
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-13.2.0-h7e041cc_3.conda#937eaed008f6bf2191c5fe76f87755e9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-4-hd8ed1ab_3.tar.bz2#878f923dd6acc8aeb47a75da6c4098be
|
||||
https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.12-4_cp312.conda#dccc2d142812964fcc6abdc97b672dff
|
||||
https://conda.anaconda.org/conda-forge/noarch/tzdata-2023d-h0c530f3_0.conda#8dee24b8be2d9ff81e7bd4d7d97ff1b0
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libgomp-13.2.0-h807b86a_3.conda#7124cbb46b13d395bdde68f2d215c989
|
||||
https://conda.anaconda.org/conda-forge/linux-64/_openmp_mutex-4.5-2_gnu.tar.bz2#73aaf86a425cc6e73fcf236a5a46396d
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-13.2.0-h807b86a_3.conda#23fdf1fef05baeb7eadc2aed5fb0011f
|
||||
https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hd590300_5.conda#69b8b6202a07720f448be700e300ccf4
|
||||
https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.25.0-hd590300_0.conda#89e40af02dd3a0846c0c1131c5126706
|
||||
https://conda.anaconda.org/conda-forge/linux-64/fmt-10.1.1-h00ab1b0_1.conda#50a08d74ca45785f3334b175da23fd82
|
||||
https://conda.anaconda.org/conda-forge/linux-64/gettext-0.21.1-h27087fc_0.tar.bz2#14947d8770185e5153fdd04d4673ed37
|
||||
https://conda.anaconda.org/conda-forge/linux-64/icu-73.2-h59595ed_0.conda#cc47e1facc155f91abd89b11e48e72ff
|
||||
https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.1-h166bdaf_0.tar.bz2#30186d27e2c9fa62b45fb1476b7200e3
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-hd590300_2.conda#172bf1cd1ff8629f2b1179945ed45055
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.5.0-hcb278e6_1.conda#6305a3dd2752c76335295da4e581f2fd
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libffi-3.4.2-h7f98852_5.tar.bz2#d645c6d2ac96843a2bfaccd2d62b3ac3
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libgfortran5-13.2.0-ha4646dd_3.conda#c714d905cdfa0e70200f68b80cc04764
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libiconv-1.17-hd590300_2.conda#d66573916ffcf376178462f1b61c941e
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libnsl-2.0.1-hd590300_0.conda#30fd6e37fe21f86f4bd26d6ee73eeec7
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libuuid-2.38.1-h0b41bf4_0.conda#40b61aab5c7ba9ff276c41cfffe6b80b
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda#5aa797f8787fe7a17d1b0821485b5adc
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.2.13-hd590300_5.conda#f36c115f1ee199da648e0597ec2047ad
|
||||
https://conda.anaconda.org/conda-forge/linux-64/lz4-c-1.9.4-hcb278e6_0.conda#318b08df404f9c9be5712aaa5a6f0bb0
|
||||
https://conda.anaconda.org/conda-forge/linux-64/lzo-2.10-h516909a_1000.tar.bz2#bb14fcb13341b81d5eb386423b9d2bac
|
||||
https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.4-h59595ed_2.conda#7dbaa197d7ba6032caf7ae7f32c1efa0
|
||||
https://conda.anaconda.org/conda-forge/linux-64/openssl-3.2.0-hd590300_1.conda#603827b39ea2b835268adb8c821b8570
|
||||
https://conda.anaconda.org/conda-forge/linux-64/reproc-14.2.4.post0-hd590300_1.conda#82ca53502dfd5a64a80dee76dae14685
|
||||
https://conda.anaconda.org/conda-forge/linux-64/xz-5.2.6-h166bdaf_0.tar.bz2#2161070d867d1b1204ea749c8eec4ef0
|
||||
https://conda.anaconda.org/conda-forge/linux-64/yaml-cpp-0.8.0-h59595ed_0.conda#965eaacd7c18eb8361fd12bb9e7a57d7
|
||||
https://conda.anaconda.org/conda-forge/linux-64/expat-2.5.0-hcb278e6_1.conda#8b9b5aca60558d02ddaa09d599e55920
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20191231-he28a2e2_2.tar.bz2#4d331e44109e3f0e19b4cb8f9b82f3e1
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libgfortran-ng-13.2.0-h69a702a_3.conda#73031c79546ad06f1fe62e57fdd021bc
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libnghttp2-1.58.0-h47da74e_1.conda#700ac6ea6d53d5510591c4344d5c989a
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libsolv-0.7.27-hfc55251_0.conda#7dc82edcd617c399ca7fdb51d993a0c2
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.44.2-h2797004_0.conda#3b6a9f225c3dbe0d24f4fedd4625c5bf
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.0-h0841786_0.conda#1f5a58e686b13bcfde88b93f547d23fe
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.12.3-h232c23b_0.conda#bc6ac4c0cea148d924f621985bc3892b
|
||||
https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.42-hcad00b1_0.conda#679c8961826aa4b50653bce17ee52abe
|
||||
https://conda.anaconda.org/conda-forge/linux-64/readline-8.2-h8228510_1.conda#47d31b792659ce70f470b5c82fdfb7a4
|
||||
https://conda.anaconda.org/conda-forge/linux-64/reproc-cpp-14.2.4.post0-h59595ed_1.conda#715e1d720ec1a03715bebd237972fca5
|
||||
https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda#d453b98d9c83e71da0741bb0ff4d76bc
|
||||
https://conda.anaconda.org/conda-forge/linux-64/zstd-1.5.5-hfc55251_0.conda#04b88013080254850d6c01ed54810589
|
||||
https://conda.anaconda.org/conda-forge/linux-64/krb5-1.21.2-h659d440_0.conda#cd95826dbd331ed1be26bdf401432844
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libarchive-3.7.2-h2aa1ff5_1.conda#3bf887827d1968275978361a6e405e4f
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libglib-2.78.3-h783c2da_0.conda#9bd06b12bbfa6fd1740fd23af4b0f0c7
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.25-pthreads_h413a1c8_0.conda#d172b34a443b95f86089e8229ddc9a17
|
||||
https://conda.anaconda.org/conda-forge/linux-64/python-3.12.1-hab00c5b_1_cpython.conda#0bab699354cbd66959550eb9b9866620
|
||||
https://conda.anaconda.org/conda-forge/noarch/archspec-0.2.2-pyhd8ed1ab_0.conda#0dc2fce00a160271714647c019e3a8a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/boltons-23.1.1-pyhd8ed1ab_0.conda#56febe65315cc388a5d20adf2b39a74d
|
||||
https://conda.anaconda.org/conda-forge/linux-64/brotli-python-1.1.0-py312h30efb56_1.conda#45801a89533d3336a365284d93298e36
|
||||
https://conda.anaconda.org/conda-forge/noarch/certifi-2023.11.17-pyhd8ed1ab_0.conda#2011bcf45376341dd1d690263fdbc789
|
||||
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.3.2-pyhd8ed1ab_0.conda#7f4a9e3fcff3f6356ae99244a014da6a
|
||||
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2#3faab06a954c2a04039983f2c4a50d99
|
||||
https://conda.anaconda.org/conda-forge/noarch/crashtest-0.4.1-pyhd8ed1ab_0.tar.bz2#709a2295dd907bb34afb57d54320642f
|
||||
https://conda.anaconda.org/conda-forge/linux-64/dbus-1.13.6-h5008d03_3.tar.bz2#ecfff944ba3960ecb334b9a2663d708d
|
||||
https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda#db16c66b759a64dc5183d69cc3745a52
|
||||
https://conda.anaconda.org/conda-forge/noarch/distro-1.9.0-pyhd8ed1ab_0.conda#bbdb409974cd6cb30071b1d978302726
|
||||
https://conda.anaconda.org/conda-forge/noarch/filelock-3.13.1-pyhd8ed1ab_0.conda#0c1729b74a8152fde6a38ba0a2ab9f45
|
||||
https://conda.anaconda.org/conda-forge/noarch/idna-3.6-pyhd8ed1ab_0.conda#1a76f09108576397c41c0b0c5bd84134
|
||||
https://conda.anaconda.org/conda-forge/noarch/jeepney-0.8.0-pyhd8ed1ab_0.tar.bz2#9800ad1699b42612478755a2d26c722d
|
||||
https://conda.anaconda.org/conda-forge/linux-64/jsonpointer-2.4-py312h7900ff3_3.conda#50f62bdb9b60b13c2f6ae69957342e4d
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libblas-3.9.0-20_linux64_openblas.conda#2b7bb4f7562c8cf334fc2e20c2d28abc
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.5.0-hca28451_0.conda#7144d5a828e2cae218e0e3c98d8a0aeb
|
||||
https://conda.anaconda.org/conda-forge/linux-64/menuinst-2.0.2-py312h7900ff3_0.conda#acb03947d606ff797a036d31723490fc
|
||||
https://conda.anaconda.org/conda-forge/noarch/more-itertools-10.2.0-pyhd8ed1ab_0.conda#d5c98e9706fdc5328d49a9bf2ce5fb42
|
||||
https://conda.anaconda.org/conda-forge/linux-64/msgpack-python-1.0.7-py312h8572e83_0.conda#1ae83e30fae86320e888cb4b1f2d3b47
|
||||
https://conda.anaconda.org/conda-forge/noarch/packaging-23.2-pyhd8ed1ab_0.conda#79002079284aa895f883c6b7f3f88fd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/pkginfo-1.9.6-pyhd8ed1ab_0.conda#be1e9f1c65a1ed0f2ae9352fec99db64
|
||||
https://conda.anaconda.org/conda-forge/noarch/pluggy-1.3.0-pyhd8ed1ab_0.conda#2390bd10bed1f3fdc7a537fb5a447d8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-core-1.8.1-pyhd8ed1ab_0.conda#a013d99ae50670b823c511f7274d2d2a
|
||||
https://conda.anaconda.org/conda-forge/noarch/ptyprocess-0.7.0-pyhd3deb0d_0.tar.bz2#359eeb6536da0e687af562ed265ec263
|
||||
https://conda.anaconda.org/conda-forge/linux-64/pycosat-0.6.6-py312h98912ed_0.conda#8f1c372e7b843167be885dc8229931c1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2#076becd9e05608f8dc72757d5f3a91ff
|
||||
https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2#2a7de29fb590ca14b5243c4c812c8025
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-fastjsonschema-2.19.1-pyhd8ed1ab_0.conda#4d3ceee3af4b0f9a1f48f57176bf8625
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-installer-0.7.0-pyhd8ed1ab_0.conda#65dea78f903d686c8b0c2feaf0e15e1f
|
||||
https://conda.anaconda.org/conda-forge/linux-64/ruamel.yaml.clib-0.2.7-py312h98912ed_2.conda#17591efb6a03e1dea6567cb15c619d1c
|
||||
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
|
||||
https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda#d08db09a552699ee9e7eec56b4eb3899
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2#5844808ffab9ebdb694585b50ba02a96
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomlkit-0.12.3-pyha770c72_0.conda#074d0ce7a6261ab8b497c3518796ef3e
|
||||
https://conda.anaconda.org/conda-forge/noarch/trove-classifiers-2024.1.8-pyhd8ed1ab_0.conda#b120d43603f9b021d252fb7754b35557
|
||||
https://conda.anaconda.org/conda-forge/noarch/truststore-0.8.0-pyhd8ed1ab_0.conda#08316d001eca8854392cf2837828ea11
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
|
||||
https://conda.anaconda.org/conda-forge/noarch/zipp-3.17.0-pyhd8ed1ab_0.conda#2e4d6bc0b14e10f895fc6791a7d9b26a
|
||||
https://conda.anaconda.org/conda-forge/linux-64/cffi-1.16.0-py312hf06ca03_0.conda#56b0ca764ce23cc54f3f7e2a7b970f6d
|
||||
https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.1-pyha770c72_0.conda#746623a787e06191d80a2133e5daff17
|
||||
https://conda.anaconda.org/conda-forge/noarch/jaraco.classes-3.3.0-pyhd8ed1ab_0.conda#e9f79248d30e942f7c358ff21a1790f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/jsonpatch-1.33-pyhd8ed1ab_0.conda#bfdb7c5c6ad1077c82a69a8642c87aff
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libcblas-3.9.0-20_linux64_openblas.conda#36d486d72ab64ffea932329a1d3729a3
|
||||
https://conda.anaconda.org/conda-forge/linux-64/liblapack-3.9.0-20_linux64_openblas.conda#6fabc51f5e647d09cc010c40061557e0
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libmamba-1.5.6-had39da4_0.conda#d6213d8b3abe12c556f007894752ef41
|
||||
https://conda.anaconda.org/conda-forge/noarch/pexpect-4.8.0-pyh1a96a4e_2.tar.bz2#330448ce4403cc74990ac07c555942a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pip-23.3.2-pyhd8ed1ab_0.conda#8591c748f98dcc02253003533bc2e4b1
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-plugin-export-1.6.0-pyhd8ed1ab_0.conda#1f2184db9f337d1074b1d5769165cac9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.0.0-pyhd8ed1ab_0.conda#21de50391d584eb7f4441b9de1ad773f
|
||||
https://conda.anaconda.org/conda-forge/linux-64/ruamel.yaml-0.18.5-py312h98912ed_0.conda#631213fb6dee32d9004779c5b6de3c49
|
||||
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.66.1-pyhd8ed1ab_0.conda#03c97908b976498dcae97eb4e4f3149c
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.9.0-hd8ed1ab_0.conda#c16524c1b7227dc80b36b4fa6f77cc86
|
||||
https://conda.anaconda.org/conda-forge/noarch/urllib3-2.1.0-pyhd8ed1ab_0.conda#f8ced8ee63830dec7ecc1be048d1470a
|
||||
https://conda.anaconda.org/conda-forge/linux-64/cryptography-41.0.7-py312h4742d6a_1.conda#82b6c3083757a04e8a2a4759a33df382
|
||||
https://conda.anaconda.org/conda-forge/linux-64/dulwich-0.21.7-py312h98912ed_0.conda#d9768d62ebbeb330f1b67d8ab4832ff7
|
||||
https://conda.anaconda.org/conda-forge/linux-64/libmambapy-1.5.6-py312hd9e9ff6_0.conda#ff2a396085f25808b6c2a6dea06546fe
|
||||
https://conda.anaconda.org/conda-forge/linux-64/numpy-1.26.3-py312heda63a1_0.conda#8b63634568b70ed9110f4d03dca20988
|
||||
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.11.0-pyhd8ed1ab_0.conda#8f567c0a74aa44cf732f15773b4083b0
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-build-1.0.3-pyhd8ed1ab_0.conda#d9ccabf228cb98419ca3d5694b25e1a2
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-2.31.0-pyhd8ed1ab_0.conda#a30144e4156cdbb236f99ebb49828f8b
|
||||
https://conda.anaconda.org/conda-forge/linux-64/zstandard-0.22.0-py312hd58854c_0.conda#6532ce0d6b7b6c77081ba102d3540a81
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-0.13.1-pyhd8ed1ab_0.conda#174bd699bb5aa9e2622eb4b288276ff8
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-streaming-0.9.0-pyhd8ed1ab_0.conda#38253361efb303deead3eab39ae9269b
|
||||
https://conda.anaconda.org/conda-forge/linux-64/rapidfuzz-3.6.1-py312h30efb56_0.conda#b04ed89dc0b4f4581f003c3b3b5e85d6
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_0.conda#99c98318c8646b08cc764f90ce98906e
|
||||
https://conda.anaconda.org/conda-forge/linux-64/secretstorage-3.3.3-py312h7900ff3_2.conda#39067833cbb620066d492f8bd6f11dbf
|
||||
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.25.0-pyhd8ed1ab_0.conda#c119653cba436d8183c27bf6d190e587
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-with-filecache-0.13.1-pyhd8ed1ab_0.conda#8c4781ca0893cff3a64423954ce234a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/cleo-2.1.0-pyhd8ed1ab_0.conda#69569ea8a6d1465193345a40421d138b
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-handling-2.2.0-pyh38be061_0.conda#8a3ae7f6318376aa08ea753367bb7dd6
|
||||
https://conda.anaconda.org/conda-forge/linux-64/keyring-24.3.0-py312h7900ff3_0.conda#c303e2ddfc697a70a137940f8a6b2e1d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-1.7.1-linux_pyha804496_0.conda#f4ead25aee9d567898e970a107bcac7e
|
||||
https://conda.anaconda.org/conda-forge/linux-64/conda-23.11.0-py312h7900ff3_1.conda#8dd6aeb5ba421f80d5b47ee253584f20
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-libmamba-solver-23.12.0-pyhd8ed1ab_0.conda#e877d5150e73a0844ea2939be110c3b1
|
||||
https://conda.anaconda.org/conda-forge/linux-64/mamba-1.5.6-py312h9460a1c_0.conda#055217b5da9f10750a046e9ea10a1756
|
||||
@@ -1,129 +0,0 @@
|
||||
# Generated by conda-lock.
|
||||
# platform: linux-aarch64
|
||||
# input_hash: bc3de0fcb97d5683373c177f2880616dffbe0acedde12d411f84c6ff91b56e83
|
||||
@EXPLICIT
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/ca-certificates-2023.11.17-hcefe29a_0.conda#695a28440b58e3ba920bcac4ac7c73c6
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/ld_impl_linux-aarch64-2.40-h2d8c526_0.conda#16246d69e945d0b1969a6099e7c5d457
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libgomp-13.2.0-hf8544c7_3.conda#191eb9058c6e97ca5fea3552e348a237
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libstdcxx-ng-13.2.0-h9a76618_3.conda#7ad2164936c4975d94ca883d34809c0f
|
||||
https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-4-hd8ed1ab_3.tar.bz2#878f923dd6acc8aeb47a75da6c4098be
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/python_abi-3.12-4_cp312.conda#6c09f8e580146d88f649780cebed01de
|
||||
https://conda.anaconda.org/conda-forge/noarch/tzdata-2023d-h0c530f3_0.conda#8dee24b8be2d9ff81e7bd4d7d97ff1b0
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/_openmp_mutex-4.5-2_gnu.tar.bz2#6168d71addc746e8f2b8d57dfd2edcea
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libgcc-ng-13.2.0-hf8544c7_3.conda#00f021ee1a24c798ae53c87ee79597f1
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/bzip2-1.0.8-h31becfc_5.conda#a64e35f01e0b7a2a152eca87d33b9c87
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/c-ares-1.25.0-h31becfc_0.conda#0892c14dc88498d4cb727098141d365c
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/fmt-10.1.1-h2a328a1_1.conda#49695e320c2a672846a90ca623dce1da
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/gettext-0.21.1-ha18d298_0.tar.bz2#b109f1a4d22966793d61fd7f75b744c3
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/icu-73.2-h787c7f5_0.conda#9d3c29d71f28452a2e843aff8cbe09d2
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/keyutils-1.6.1-h4e544f5_0.tar.bz2#1f24853e59c68892452ef94ddd8afd4b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libev-4.33-h31becfc_2.conda#a9a13cb143bbaa477b1ebaefbe47a302
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libexpat-2.5.0-hd600fc2_1.conda#6cd3d0a28437b3845c260f9d71d434d7
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libffi-3.4.2-h3557bc0_5.tar.bz2#dddd85f4d52121fab0a8b099c5e06501
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libgfortran5-13.2.0-h582850c_3.conda#d81dcb787465447542ad9c4cf0bab65e
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libiconv-1.17-h31becfc_2.conda#9a8eb13f14de7d761555a98712e6df65
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libnsl-2.0.1-h31becfc_0.conda#c14f32510f694e3185704d89967ec422
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libuuid-2.38.1-hb4cce97_0.conda#000e30b09db0b7c775b21695dff30969
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libxcrypt-4.4.36-h31becfc_1.conda#b4df5d7d4b63579d081fd3a4cf99740e
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libzlib-1.2.13-h31becfc_5.conda#b213aa87eea9491ef7b129179322e955
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/lz4-c-1.9.4-hd600fc2_0.conda#500145a83ed07ce79c8cef24252f366b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/lzo-2.10-h516909a_1000.tar.bz2#ef5661339990c399c68c71cfb341e6d7
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/ncurses-6.4-h0425590_2.conda#4ff0a396150dedad4269e16e5810f769
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/openssl-3.2.0-h31becfc_1.conda#b24247441ed7ce138382de2ec51200e4
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/reproc-14.2.4.post0-h31becfc_1.conda#c148bb4ba029a018527d3e4d5c7b63fa
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/xz-5.2.6-h9cdd2b7_0.tar.bz2#83baad393a31d59c20b63ba4da6592df
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/yaml-cpp-0.8.0-h2f0025b_0.conda#b5da38ee183c1e50e3e7ffb171a2eca5
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/expat-2.5.0-hd600fc2_1.conda#6dfca4be3e0080934b1105d009747e98
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libedit-3.1.20191231-he28a2e2_2.tar.bz2#29371161d77933a54fccf1bb66b96529
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libgfortran-ng-13.2.0-he9431aa_3.conda#6c292066bb9876d7ba35c590868baaeb
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libnghttp2-1.58.0-hb0e430d_1.conda#8f724cdddffa79152de61f5564a3526b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libsolv-0.7.27-hd84c7bf_0.conda#7e092bca53956dd2fddb1eed62c22c29
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libsqlite-3.44.2-h194ca79_0.conda#464a0dedd1131669324946ee1c13c1a5
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libssh2-1.11.0-h492db2e_0.conda#45532845e121677ad328c9af9953f161
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libxml2-2.12.3-h3091e33_0.conda#f7582eb42bcaa458503819687da6a143
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/pcre2-10.42-hd0f9c67_0.conda#683162253dd3b6c4d21bf037e59455f4
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/readline-8.2-h8fc344f_1.conda#105eb1e16bf83bfb2eb380a48032b655
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/reproc-cpp-14.2.4.post0-h2f0025b_1.conda#35148ef0f190022ca52cf6edd6bdc814
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/tk-8.6.13-h194ca79_0.conda#f75105e0585851f818e0009dd1dde4dc
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/zstd-1.5.5-h4c53e97_0.conda#b74eb9dbb5c3c15cb3cee7cbdf198c75
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/krb5-1.21.2-hc419048_0.conda#55b51af37bf6fdcfe06f140e62e8c8db
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libarchive-3.7.2-hd2f85e0_1.conda#a0f2e7adbcdf4041d6ee273d07ca171e
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libglib-2.78.3-h311d5f7_0.conda#09e44253dee99895f02cfad44dd8fea4
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libopenblas-0.3.25-pthreads_h5a5ec62_0.conda#60e86bc93e3f213278dc5081115fb63b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/python-3.12.1-h43d1f9e_1_cpython.conda#886aaa760e922b4f7e2522e2e0abd778
|
||||
https://conda.anaconda.org/conda-forge/noarch/archspec-0.2.2-pyhd8ed1ab_0.conda#0dc2fce00a160271714647c019e3a8a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/boltons-23.1.1-pyhd8ed1ab_0.conda#56febe65315cc388a5d20adf2b39a74d
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/brotli-python-1.1.0-py312h2aa54b4_1.conda#7253fd6feb797007a3d290bbcfd23a84
|
||||
https://conda.anaconda.org/conda-forge/noarch/certifi-2023.11.17-pyhd8ed1ab_0.conda#2011bcf45376341dd1d690263fdbc789
|
||||
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.3.2-pyhd8ed1ab_0.conda#7f4a9e3fcff3f6356ae99244a014da6a
|
||||
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2#3faab06a954c2a04039983f2c4a50d99
|
||||
https://conda.anaconda.org/conda-forge/noarch/crashtest-0.4.1-pyhd8ed1ab_0.tar.bz2#709a2295dd907bb34afb57d54320642f
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/dbus-1.13.6-h12b9eeb_3.tar.bz2#f3d63805602166bac09386741e00935e
|
||||
https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda#db16c66b759a64dc5183d69cc3745a52
|
||||
https://conda.anaconda.org/conda-forge/noarch/distro-1.9.0-pyhd8ed1ab_0.conda#bbdb409974cd6cb30071b1d978302726
|
||||
https://conda.anaconda.org/conda-forge/noarch/filelock-3.13.1-pyhd8ed1ab_0.conda#0c1729b74a8152fde6a38ba0a2ab9f45
|
||||
https://conda.anaconda.org/conda-forge/noarch/idna-3.6-pyhd8ed1ab_0.conda#1a76f09108576397c41c0b0c5bd84134
|
||||
https://conda.anaconda.org/conda-forge/noarch/jeepney-0.8.0-pyhd8ed1ab_0.tar.bz2#9800ad1699b42612478755a2d26c722d
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/jsonpointer-2.4-py312h996f985_3.conda#9899db49e70426c9d32b027777088fb8
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libblas-3.9.0-20_linuxaarch64_openblas.conda#11590ed0fb5cebe7bbfa4bab8d8b07f8
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libcurl-8.5.0-h4e8248e_0.conda#fa0f5edc06ffc25a01eed005c6dc3d8c
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/menuinst-2.0.2-py312h996f985_0.conda#1a67b77c7711209b7bbed395f1a7f57e
|
||||
https://conda.anaconda.org/conda-forge/noarch/more-itertools-10.2.0-pyhd8ed1ab_0.conda#d5c98e9706fdc5328d49a9bf2ce5fb42
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/msgpack-python-1.0.7-py312h721a97f_0.conda#23f5237a0807b8dc739bdb5853d2945c
|
||||
https://conda.anaconda.org/conda-forge/noarch/packaging-23.2-pyhd8ed1ab_0.conda#79002079284aa895f883c6b7f3f88fd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/pkginfo-1.9.6-pyhd8ed1ab_0.conda#be1e9f1c65a1ed0f2ae9352fec99db64
|
||||
https://conda.anaconda.org/conda-forge/noarch/pluggy-1.3.0-pyhd8ed1ab_0.conda#2390bd10bed1f3fdc7a537fb5a447d8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-core-1.8.1-pyhd8ed1ab_0.conda#a013d99ae50670b823c511f7274d2d2a
|
||||
https://conda.anaconda.org/conda-forge/noarch/ptyprocess-0.7.0-pyhd3deb0d_0.tar.bz2#359eeb6536da0e687af562ed265ec263
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/pycosat-0.6.6-py312hdd3e373_0.conda#368a87e79b0c4bb0f97b103bbd4b5c75
|
||||
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2#076becd9e05608f8dc72757d5f3a91ff
|
||||
https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2#2a7de29fb590ca14b5243c4c812c8025
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-fastjsonschema-2.19.1-pyhd8ed1ab_0.conda#4d3ceee3af4b0f9a1f48f57176bf8625
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-installer-0.7.0-pyhd8ed1ab_0.conda#65dea78f903d686c8b0c2feaf0e15e1f
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/ruamel.yaml.clib-0.2.7-py312hdd3e373_2.conda#ea944a8a9fce4de9a84143e3f7128134
|
||||
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
|
||||
https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda#d08db09a552699ee9e7eec56b4eb3899
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2#5844808ffab9ebdb694585b50ba02a96
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomlkit-0.12.3-pyha770c72_0.conda#074d0ce7a6261ab8b497c3518796ef3e
|
||||
https://conda.anaconda.org/conda-forge/noarch/trove-classifiers-2024.1.8-pyhd8ed1ab_0.conda#b120d43603f9b021d252fb7754b35557
|
||||
https://conda.anaconda.org/conda-forge/noarch/truststore-0.8.0-pyhd8ed1ab_0.conda#08316d001eca8854392cf2837828ea11
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
|
||||
https://conda.anaconda.org/conda-forge/noarch/zipp-3.17.0-pyhd8ed1ab_0.conda#2e4d6bc0b14e10f895fc6791a7d9b26a
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/cffi-1.16.0-py312hf3c74c0_0.conda#2b087fcfbe35a1bb081e1723b8c6362a
|
||||
https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.1-pyha770c72_0.conda#746623a787e06191d80a2133e5daff17
|
||||
https://conda.anaconda.org/conda-forge/noarch/jaraco.classes-3.3.0-pyhd8ed1ab_0.conda#e9f79248d30e942f7c358ff21a1790f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/jsonpatch-1.33-pyhd8ed1ab_0.conda#bfdb7c5c6ad1077c82a69a8642c87aff
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libcblas-3.9.0-20_linuxaarch64_openblas.conda#b41e55ae2cb9d3518da2cbe3677b3b3b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/liblapack-3.9.0-20_linuxaarch64_openblas.conda#e7412a592d9ee7c92026eb1189687271
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libmamba-1.5.6-hea3be6c_0.conda#feb0be90db1e014dde541cafa78efc15
|
||||
https://conda.anaconda.org/conda-forge/noarch/pexpect-4.8.0-pyh1a96a4e_2.tar.bz2#330448ce4403cc74990ac07c555942a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pip-23.3.2-pyhd8ed1ab_0.conda#8591c748f98dcc02253003533bc2e4b1
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-plugin-export-1.6.0-pyhd8ed1ab_0.conda#1f2184db9f337d1074b1d5769165cac9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.0.0-pyhd8ed1ab_0.conda#21de50391d584eb7f4441b9de1ad773f
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/ruamel.yaml-0.18.5-py312hdd3e373_0.conda#0e375e2cba5a2501ad822d9deedf9aaf
|
||||
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.66.1-pyhd8ed1ab_0.conda#03c97908b976498dcae97eb4e4f3149c
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.9.0-hd8ed1ab_0.conda#c16524c1b7227dc80b36b4fa6f77cc86
|
||||
https://conda.anaconda.org/conda-forge/noarch/urllib3-2.1.0-pyhd8ed1ab_0.conda#f8ced8ee63830dec7ecc1be048d1470a
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/cryptography-41.0.7-py312hc709039_1.conda#bd8d4ac4437b00b2f0d00d0e2303f8fd
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/dulwich-0.21.7-py312hdd3e373_0.conda#397a67598654b34b83057ff1a9cfff33
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/libmambapy-1.5.6-py312h1e39527_0.conda#037ef6053fa678b9e7ec1fccc83471e0
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/numpy-1.26.3-py312h470d778_0.conda#df857a4163668a976e4d91c7181514c0
|
||||
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.11.0-pyhd8ed1ab_0.conda#8f567c0a74aa44cf732f15773b4083b0
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-build-1.0.3-pyhd8ed1ab_0.conda#d9ccabf228cb98419ca3d5694b25e1a2
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-2.31.0-pyhd8ed1ab_0.conda#a30144e4156cdbb236f99ebb49828f8b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/zstandard-0.22.0-py312hb120188_0.conda#8d83dc36d9d38c83c3d30dcb0e6c9f2c
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-0.13.1-pyhd8ed1ab_0.conda#174bd699bb5aa9e2622eb4b288276ff8
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-streaming-0.9.0-pyhd8ed1ab_0.conda#38253361efb303deead3eab39ae9269b
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/rapidfuzz-3.6.1-py312h2aa54b4_0.conda#f3a808a9b78a2924b7774a8cd3c942bf
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_0.conda#99c98318c8646b08cc764f90ce98906e
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/secretstorage-3.3.3-py312h8025657_2.conda#908598f88d4288b9cabc46ded32c5ee2
|
||||
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.25.0-pyhd8ed1ab_0.conda#c119653cba436d8183c27bf6d190e587
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-with-filecache-0.13.1-pyhd8ed1ab_0.conda#8c4781ca0893cff3a64423954ce234a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/cleo-2.1.0-pyhd8ed1ab_0.conda#69569ea8a6d1465193345a40421d138b
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-handling-2.2.0-pyh38be061_0.conda#8a3ae7f6318376aa08ea753367bb7dd6
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/keyring-24.3.0-py312h996f985_0.conda#a08242a7a02d64380b5cf6a843f4356a
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-1.7.1-linux_pyha804496_0.conda#f4ead25aee9d567898e970a107bcac7e
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/conda-23.11.0-py312h996f985_1.conda#6137c0415bccff2c993b1fb7911f846d
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-libmamba-solver-23.12.0-pyhd8ed1ab_0.conda#e877d5150e73a0844ea2939be110c3b1
|
||||
https://conda.anaconda.org/conda-forge/linux-aarch64/mamba-1.5.6-py312hd80a4d2_0.conda#0b5841ba8450cf2d1f4b8e479ba16bc5
|
||||
@@ -1,115 +0,0 @@
|
||||
# Generated by conda-lock.
|
||||
# platform: osx-64
|
||||
# input_hash: 84c30aa7789ba5570aedb1d84bd49b174515e108c41a4ffa273ec1d9fca574ee
|
||||
@EXPLICIT
|
||||
https://conda.anaconda.org/conda-forge/osx-64/bzip2-1.0.8-h10d778d_5.conda#6097a6ca9ada32699b5fc4312dd6ef18
|
||||
https://conda.anaconda.org/conda-forge/osx-64/c-ares-1.25.0-h10d778d_0.conda#80e97c8f21c33a3b9256504858cf49b6
|
||||
https://conda.anaconda.org/conda-forge/osx-64/ca-certificates-2023.11.17-h8857fd0_0.conda#c687e9d14c49e3d3946d50a413cdbf16
|
||||
https://conda.anaconda.org/conda-forge/osx-64/icu-73.2-hf5e326d_0.conda#5cc301d759ec03f28328428e28f65591
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libcxx-16.0.6-hd57cbcb_0.conda#7d6972792161077908b62971802f289a
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libev-4.33-h10d778d_2.conda#899db79329439820b7e8f8de41bca902
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libexpat-2.5.0-hf0c8a7f_1.conda#6c81cb022780ee33435cca0127dd43c9
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libffi-3.4.2-h0d85af4_5.tar.bz2#ccb34fb14960ad8b125962d3d79b31a9
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libiconv-1.17-hd75f5a5_2.conda#6c3628d047e151efba7cf08c5e54d1ca
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libzlib-1.2.13-h8a1eda9_5.conda#4a3ad23f6e16f99c04e166767193d700
|
||||
https://conda.anaconda.org/conda-forge/osx-64/llvm-openmp-17.0.6-hb6ac08f_0.conda#f260ab897df05f729fc3e65dbb0850ef
|
||||
https://conda.anaconda.org/conda-forge/osx-64/lzo-2.10-haf1e3a3_1000.tar.bz2#0b6bca372a95d6c602c7a922e928ce79
|
||||
https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-4-hd8ed1ab_3.tar.bz2#878f923dd6acc8aeb47a75da6c4098be
|
||||
https://conda.anaconda.org/conda-forge/osx-64/python_abi-3.12-4_cp312.conda#87201ac4314b911b74197e588cca3639
|
||||
https://conda.anaconda.org/conda-forge/osx-64/reproc-14.2.4.post0-h10d778d_1.conda#d7c3258e871481be5bbaf28b4729e29f
|
||||
https://conda.anaconda.org/conda-forge/noarch/tzdata-2023d-h0c530f3_0.conda#8dee24b8be2d9ff81e7bd4d7d97ff1b0
|
||||
https://conda.anaconda.org/conda-forge/osx-64/xz-5.2.6-h775f41a_0.tar.bz2#a72f9d4ea13d55d745ff1ed594747f10
|
||||
https://conda.anaconda.org/conda-forge/osx-64/fmt-10.1.1-h7728843_1.conda#de48ed5d4de16ac68e8d1bd07f02e781
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libgfortran5-13.2.0-h2873a65_1.conda#3af564516b5163cd8cc08820413854bc
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libsolv-0.7.27-hf4d7fad_0.conda#dda8df0e28d488cc20dec52903dddcad
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libsqlite-3.44.2-h92b6c6a_0.conda#d4419f90019e6a2b152cd4d32f73a82f
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libxml2-2.12.3-hc0ae0f7_0.conda#959e8dad65f624a362546d96005e47f6
|
||||
https://conda.anaconda.org/conda-forge/osx-64/lz4-c-1.9.4-hf0c8a7f_0.conda#aa04f7143228308662696ac24023f991
|
||||
https://conda.anaconda.org/conda-forge/osx-64/ncurses-6.4-h93d8f39_2.conda#e58f366bd4d767e9ab97ab8b272e7670
|
||||
https://conda.anaconda.org/conda-forge/osx-64/openssl-3.2.0-hd75f5a5_1.conda#06cb561619487c88891839b9beb5244c
|
||||
https://conda.anaconda.org/conda-forge/osx-64/reproc-cpp-14.2.4.post0-h93d8f39_1.conda#a32e95ada0ee860c91e87266700970c3
|
||||
https://conda.anaconda.org/conda-forge/osx-64/tk-8.6.13-h1abcd95_1.conda#bf830ba5afc507c6232d4ef0fb1a882d
|
||||
https://conda.anaconda.org/conda-forge/osx-64/yaml-cpp-0.8.0-he965462_0.conda#1bb3addc859ed1338370da6e2996ef47
|
||||
https://conda.anaconda.org/conda-forge/osx-64/zstd-1.5.5-h829000d_0.conda#80abc41d0c48b82fe0f04e7f42f5cb7e
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libarchive-3.7.2-hd35d340_1.conda#8c7b79b20a67287a87b39df8a8c8dcc4
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libedit-3.1.20191231-h0678c8f_2.tar.bz2#6016a8a1d0e63cac3de2c352cd40208b
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libgfortran-5.0.0-13_2_0_h97931a8_1.conda#b55fd11ab6318a6e67ac191309701d5a
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libnghttp2-1.58.0-h64cf6d3_1.conda#faecc55c2a8155d9ff1c0ff9a0fef64f
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libssh2-1.11.0-hd019ec5_0.conda#ca3a72efba692c59a90d4b9fc0dfe774
|
||||
https://conda.anaconda.org/conda-forge/osx-64/readline-8.2-h9e318b2_1.conda#f17f77f2acf4d344734bda76829ce14e
|
||||
https://conda.anaconda.org/conda-forge/osx-64/krb5-1.21.2-hb884880_0.conda#80505a68783f01dc8d7308c075261b2f
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libopenblas-0.3.25-openmp_hfef2a42_0.conda#a01b96f00c3155c830d98a518c7dcbfb
|
||||
https://conda.anaconda.org/conda-forge/osx-64/python-3.12.1-h9f0c242_1_cpython.conda#41d5549764b9f37199e6255e5e9daee6
|
||||
https://conda.anaconda.org/conda-forge/noarch/archspec-0.2.2-pyhd8ed1ab_0.conda#0dc2fce00a160271714647c019e3a8a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/boltons-23.1.1-pyhd8ed1ab_0.conda#56febe65315cc388a5d20adf2b39a74d
|
||||
https://conda.anaconda.org/conda-forge/osx-64/brotli-python-1.1.0-py312heafc425_1.conda#a288b88f06b8bfe0dedaf5c4b6ac6b7a
|
||||
https://conda.anaconda.org/conda-forge/noarch/certifi-2023.11.17-pyhd8ed1ab_0.conda#2011bcf45376341dd1d690263fdbc789
|
||||
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.3.2-pyhd8ed1ab_0.conda#7f4a9e3fcff3f6356ae99244a014da6a
|
||||
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2#3faab06a954c2a04039983f2c4a50d99
|
||||
https://conda.anaconda.org/conda-forge/noarch/crashtest-0.4.1-pyhd8ed1ab_0.tar.bz2#709a2295dd907bb34afb57d54320642f
|
||||
https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda#db16c66b759a64dc5183d69cc3745a52
|
||||
https://conda.anaconda.org/conda-forge/noarch/distro-1.9.0-pyhd8ed1ab_0.conda#bbdb409974cd6cb30071b1d978302726
|
||||
https://conda.anaconda.org/conda-forge/noarch/filelock-3.13.1-pyhd8ed1ab_0.conda#0c1729b74a8152fde6a38ba0a2ab9f45
|
||||
https://conda.anaconda.org/conda-forge/noarch/idna-3.6-pyhd8ed1ab_0.conda#1a76f09108576397c41c0b0c5bd84134
|
||||
https://conda.anaconda.org/conda-forge/osx-64/jsonpointer-2.4-py312hb401068_3.conda#637aa8f6c1c61f659f1496e9b2dc7552
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libblas-3.9.0-20_osx64_openblas.conda#1673476d205d14a9042172be795f63cb
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libcurl-8.5.0-h726d00d_0.conda#86d749e27fe00fa6b7d790a6feaa22a2
|
||||
https://conda.anaconda.org/conda-forge/osx-64/menuinst-2.0.2-py312hb401068_0.conda#40fcba89895965e39ea94e53d5588b8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/more-itertools-10.2.0-pyhd8ed1ab_0.conda#d5c98e9706fdc5328d49a9bf2ce5fb42
|
||||
https://conda.anaconda.org/conda-forge/osx-64/msgpack-python-1.0.7-py312hbf0bb39_0.conda#2aa4afb76d89d1241e67385b17f6f6ba
|
||||
https://conda.anaconda.org/conda-forge/noarch/packaging-23.2-pyhd8ed1ab_0.conda#79002079284aa895f883c6b7f3f88fd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/pkginfo-1.9.6-pyhd8ed1ab_0.conda#be1e9f1c65a1ed0f2ae9352fec99db64
|
||||
https://conda.anaconda.org/conda-forge/noarch/pluggy-1.3.0-pyhd8ed1ab_0.conda#2390bd10bed1f3fdc7a537fb5a447d8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-core-1.8.1-pyhd8ed1ab_0.conda#a013d99ae50670b823c511f7274d2d2a
|
||||
https://conda.anaconda.org/conda-forge/noarch/ptyprocess-0.7.0-pyhd3deb0d_0.tar.bz2#359eeb6536da0e687af562ed265ec263
|
||||
https://conda.anaconda.org/conda-forge/osx-64/pycosat-0.6.6-py312h104f124_0.conda#106c2d37708757f4c23ff1f487bf5a3f
|
||||
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2#076becd9e05608f8dc72757d5f3a91ff
|
||||
https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2#2a7de29fb590ca14b5243c4c812c8025
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-fastjsonschema-2.19.1-pyhd8ed1ab_0.conda#4d3ceee3af4b0f9a1f48f57176bf8625
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-installer-0.7.0-pyhd8ed1ab_0.conda#65dea78f903d686c8b0c2feaf0e15e1f
|
||||
https://conda.anaconda.org/conda-forge/osx-64/ruamel.yaml.clib-0.2.7-py312h104f124_2.conda#07c5b620686d2fa9629374e8b4cf29ec
|
||||
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
|
||||
https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda#d08db09a552699ee9e7eec56b4eb3899
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2#5844808ffab9ebdb694585b50ba02a96
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomlkit-0.12.3-pyha770c72_0.conda#074d0ce7a6261ab8b497c3518796ef3e
|
||||
https://conda.anaconda.org/conda-forge/noarch/trove-classifiers-2024.1.8-pyhd8ed1ab_0.conda#b120d43603f9b021d252fb7754b35557
|
||||
https://conda.anaconda.org/conda-forge/noarch/truststore-0.8.0-pyhd8ed1ab_0.conda#08316d001eca8854392cf2837828ea11
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
|
||||
https://conda.anaconda.org/conda-forge/noarch/zipp-3.17.0-pyhd8ed1ab_0.conda#2e4d6bc0b14e10f895fc6791a7d9b26a
|
||||
https://conda.anaconda.org/conda-forge/osx-64/cffi-1.16.0-py312h38bf5a0_0.conda#a45759c013ab20b9017ef9539d234dd7
|
||||
https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.1-pyha770c72_0.conda#746623a787e06191d80a2133e5daff17
|
||||
https://conda.anaconda.org/conda-forge/noarch/jaraco.classes-3.3.0-pyhd8ed1ab_0.conda#e9f79248d30e942f7c358ff21a1790f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/jsonpatch-1.33-pyhd8ed1ab_0.conda#bfdb7c5c6ad1077c82a69a8642c87aff
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libcblas-3.9.0-20_osx64_openblas.conda#b324ad206d39ce529fb9073f9d062062
|
||||
https://conda.anaconda.org/conda-forge/osx-64/liblapack-3.9.0-20_osx64_openblas.conda#704bfc2af1288ea973b6755281e6ad32
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libmamba-1.5.6-ha449628_0.conda#549575d7237a1aba16119969b4a6b8a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/pexpect-4.8.0-pyh1a96a4e_2.tar.bz2#330448ce4403cc74990ac07c555942a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pip-23.3.2-pyhd8ed1ab_0.conda#8591c748f98dcc02253003533bc2e4b1
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-plugin-export-1.6.0-pyhd8ed1ab_0.conda#1f2184db9f337d1074b1d5769165cac9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.0.0-pyhd8ed1ab_0.conda#21de50391d584eb7f4441b9de1ad773f
|
||||
https://conda.anaconda.org/conda-forge/osx-64/ruamel.yaml-0.18.5-py312h41838bb_0.conda#0dcf9f224125a95634f9f29dca9fd7a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.66.1-pyhd8ed1ab_0.conda#03c97908b976498dcae97eb4e4f3149c
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.9.0-hd8ed1ab_0.conda#c16524c1b7227dc80b36b4fa6f77cc86
|
||||
https://conda.anaconda.org/conda-forge/noarch/urllib3-2.1.0-pyhd8ed1ab_0.conda#f8ced8ee63830dec7ecc1be048d1470a
|
||||
https://conda.anaconda.org/conda-forge/osx-64/dulwich-0.21.7-py312h41838bb_0.conda#4937c7a86084772c09af1f536a4c5a54
|
||||
https://conda.anaconda.org/conda-forge/osx-64/keyring-24.3.0-py312hb401068_0.conda#5b28534ef3af5f98470c318f29cdc375
|
||||
https://conda.anaconda.org/conda-forge/osx-64/libmambapy-1.5.6-py312h67f5953_0.conda#b173c0334cd59de8a7dda66aa5eddfee
|
||||
https://conda.anaconda.org/conda-forge/osx-64/numpy-1.26.3-py312he3a82b2_0.conda#cc7cfa90fc5c70a62b788daa71b782ef
|
||||
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.11.0-pyhd8ed1ab_0.conda#8f567c0a74aa44cf732f15773b4083b0
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-build-1.0.3-pyhd8ed1ab_0.conda#d9ccabf228cb98419ca3d5694b25e1a2
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-2.31.0-pyhd8ed1ab_0.conda#a30144e4156cdbb236f99ebb49828f8b
|
||||
https://conda.anaconda.org/conda-forge/osx-64/xattr-0.10.1-py312h104f124_1.conda#ca6c9e113d77c63aadb75d1ac46fe672
|
||||
https://conda.anaconda.org/conda-forge/osx-64/zstandard-0.22.0-py312h7a629f7_0.conda#04fa0acf5a74339f9228cdfffa78df64
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-0.13.1-pyhd8ed1ab_0.conda#174bd699bb5aa9e2622eb4b288276ff8
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-streaming-0.9.0-pyhd8ed1ab_0.conda#38253361efb303deead3eab39ae9269b
|
||||
https://conda.anaconda.org/conda-forge/osx-64/rapidfuzz-3.6.1-py312hede676d_0.conda#c83b7cf56e835950dd5934c2cdea000a
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_0.conda#99c98318c8646b08cc764f90ce98906e
|
||||
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.25.0-pyhd8ed1ab_0.conda#c119653cba436d8183c27bf6d190e587
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-with-filecache-0.13.1-pyhd8ed1ab_0.conda#8c4781ca0893cff3a64423954ce234a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/cleo-2.1.0-pyhd8ed1ab_0.conda#69569ea8a6d1465193345a40421d138b
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-handling-2.2.0-pyh38be061_0.conda#8a3ae7f6318376aa08ea753367bb7dd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-1.7.1-osx_pyh534df25_0.conda#4ebf180279e2c0274249cafdd29720cf
|
||||
https://conda.anaconda.org/conda-forge/osx-64/conda-23.11.0-py312hb401068_1.conda#2132d58fcb1dfe7f695a7f7e3edd50b9
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-libmamba-solver-23.12.0-pyhd8ed1ab_0.conda#e877d5150e73a0844ea2939be110c3b1
|
||||
https://conda.anaconda.org/conda-forge/osx-64/mamba-1.5.6-py312ha12221d_0.conda#7d86cab3301c9c3ee0c758c18c46cda9
|
||||
@@ -1,115 +0,0 @@
|
||||
# Generated by conda-lock.
|
||||
# platform: osx-arm64
|
||||
# input_hash: 766e6b133db15eac3b1f267721f23412a76a79b65727237ec5b51312bee1ece3
|
||||
@EXPLICIT
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h93a5062_5.conda#1bbc659ca658bfd49a481b5ef7a0f40f
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/c-ares-1.25.0-h93a5062_0.conda#0a40466cb14b485738f1910340775f71
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2023.11.17-hf0a4a13_0.conda#c01da7c77cfcba2107174e25c1d47384
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/icu-73.2-hc8870d7_0.conda#8521bd47c0e11c5902535bb1a17c565f
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-16.0.6-h4653b0c_0.conda#9d7d724faf0413bf1dbc5a85935700c8
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libev-4.33-h93a5062_2.conda#36d33e440c31857372a72137f78bacf5
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.5.0-hb7217d7_1.conda#5a097ad3d17e42c148c9566280481317
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.4.2-h3422bc3_5.tar.bz2#086914b672be056eb70fd4285b6783b6
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libiconv-1.17-h0d3ecfb_2.conda#69bda57310071cf6d2b86caf11573d2d
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.2.13-h53f4e23_5.conda#1a47f5236db2e06a320ffa0392f81bd8
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/llvm-openmp-17.0.6-hcd81f8e_0.conda#52019d2fa0eddbbc4e6dcd30fae0c0a4
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/lzo-2.10-h642e427_1000.tar.bz2#ddab5f96f5573a9bd5e24f9994fd6ec9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-4-hd8ed1ab_3.tar.bz2#878f923dd6acc8aeb47a75da6c4098be
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.12-4_cp312.conda#bbb3a02c78b2d8219d7213f76d644a2a
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/reproc-14.2.4.post0-h93a5062_1.conda#ef7ae6d7bb50c8c735551d825e1ea287
|
||||
https://conda.anaconda.org/conda-forge/noarch/tzdata-2023d-h0c530f3_0.conda#8dee24b8be2d9ff81e7bd4d7d97ff1b0
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/xz-5.2.6-h57fd34a_0.tar.bz2#39c6b54e94014701dd157f4f576ed211
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/fmt-10.1.1-h2ffa867_1.conda#16b8a2b5043378a2ee0182833622298b
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran5-13.2.0-hf226fd6_1.conda#4480d71b98c87faafab132d33e23135e
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libsolv-0.7.27-h9e231a4_0.conda#f5568a2094eed1fc5742dc6d4b91e222
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.44.2-h091b4b1_0.conda#d7e1af696cfadec251a0abdd7b79ed77
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libxml2-2.12.3-h0d0cfa8_0.conda#84e330ed40b5bf8e95a65529ccb94a14
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/lz4-c-1.9.4-hb7217d7_0.conda#45505bec548634f7d05e02fb25262cb9
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.4-h463b476_2.conda#52b6f254a7b9663e854f44b6570ed982
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.2.0-h0d3ecfb_1.conda#47d16d26100f19ca495882882b7bc93b
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/reproc-cpp-14.2.4.post0-h965bd2d_1.conda#f81d00496e13ee828f84b3ef17e41346
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda#b50a57ba89c32b62428b71a875291c9b
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/yaml-cpp-0.8.0-h13dd4ca_0.conda#e783a232972a5c7dca549111e63a78b2
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/zstd-1.5.5-h4f39d0f_0.conda#5b212cfb7f9d71d603ad891879dc7933
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libarchive-3.7.2-hcacb583_1.conda#1c8c447ce71bf5f769674b621142a73a
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libedit-3.1.20191231-hc8eb9b7_2.tar.bz2#30e4362988a2623e9eb34337b83e01f9
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libgfortran-5.0.0-13_2_0_hd922786_1.conda#1ad37a5c60c250bb2b4a9f75563e181c
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libnghttp2-1.58.0-ha4dd798_1.conda#1813e066bfcef82de579a0be8a766df4
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libssh2-1.11.0-h7a5bd25_0.conda#029f7dc931a3b626b94823bc77830b01
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/readline-8.2-h92ec313_1.conda#8cbb776a2f641b943d413b3e19df71f4
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/krb5-1.21.2-h92f50d5_0.conda#92f1cff174a538e0722bf2efb16fc0b2
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libopenblas-0.3.25-openmp_h6c19121_0.conda#a1843550403212b9dedeeb31466ade03
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/python-3.12.1-hdf0ec26_1_cpython.conda#7b5d48e25f131864762bfef1914d2014
|
||||
https://conda.anaconda.org/conda-forge/noarch/archspec-0.2.2-pyhd8ed1ab_0.conda#0dc2fce00a160271714647c019e3a8a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/boltons-23.1.1-pyhd8ed1ab_0.conda#56febe65315cc388a5d20adf2b39a74d
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/brotli-python-1.1.0-py312h9f69965_1.conda#1bc01b9ffdf42beb1a9fe4e9222e0567
|
||||
https://conda.anaconda.org/conda-forge/noarch/certifi-2023.11.17-pyhd8ed1ab_0.conda#2011bcf45376341dd1d690263fdbc789
|
||||
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.3.2-pyhd8ed1ab_0.conda#7f4a9e3fcff3f6356ae99244a014da6a
|
||||
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2#3faab06a954c2a04039983f2c4a50d99
|
||||
https://conda.anaconda.org/conda-forge/noarch/crashtest-0.4.1-pyhd8ed1ab_0.tar.bz2#709a2295dd907bb34afb57d54320642f
|
||||
https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda#db16c66b759a64dc5183d69cc3745a52
|
||||
https://conda.anaconda.org/conda-forge/noarch/distro-1.9.0-pyhd8ed1ab_0.conda#bbdb409974cd6cb30071b1d978302726
|
||||
https://conda.anaconda.org/conda-forge/noarch/filelock-3.13.1-pyhd8ed1ab_0.conda#0c1729b74a8152fde6a38ba0a2ab9f45
|
||||
https://conda.anaconda.org/conda-forge/noarch/idna-3.6-pyhd8ed1ab_0.conda#1a76f09108576397c41c0b0c5bd84134
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/jsonpointer-2.4-py312h81bd7bf_3.conda#327361b24f5348cab04ad9b1f74e831d
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libblas-3.9.0-20_osxarm64_openblas.conda#49bc8dec26663241ee064b2d7116ec2d
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libcurl-8.5.0-h2d989ff_0.conda#f1211ed00947a84e15a964a8f459f620
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/menuinst-2.0.2-py312h81bd7bf_0.conda#802a33b3ca10e299f2fc9d6783140cc7
|
||||
https://conda.anaconda.org/conda-forge/noarch/more-itertools-10.2.0-pyhd8ed1ab_0.conda#d5c98e9706fdc5328d49a9bf2ce5fb42
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/msgpack-python-1.0.7-py312h76e736e_0.conda#da9f2349c5090c2b26cfac93f50666ab
|
||||
https://conda.anaconda.org/conda-forge/noarch/packaging-23.2-pyhd8ed1ab_0.conda#79002079284aa895f883c6b7f3f88fd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/pkginfo-1.9.6-pyhd8ed1ab_0.conda#be1e9f1c65a1ed0f2ae9352fec99db64
|
||||
https://conda.anaconda.org/conda-forge/noarch/pluggy-1.3.0-pyhd8ed1ab_0.conda#2390bd10bed1f3fdc7a537fb5a447d8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-core-1.8.1-pyhd8ed1ab_0.conda#a013d99ae50670b823c511f7274d2d2a
|
||||
https://conda.anaconda.org/conda-forge/noarch/ptyprocess-0.7.0-pyhd3deb0d_0.tar.bz2#359eeb6536da0e687af562ed265ec263
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/pycosat-0.6.6-py312h02f2b3b_0.conda#4d07092345b6e66e580ce3cd9141c6da
|
||||
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2#076becd9e05608f8dc72757d5f3a91ff
|
||||
https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2#2a7de29fb590ca14b5243c4c812c8025
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-fastjsonschema-2.19.1-pyhd8ed1ab_0.conda#4d3ceee3af4b0f9a1f48f57176bf8625
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-installer-0.7.0-pyhd8ed1ab_0.conda#65dea78f903d686c8b0c2feaf0e15e1f
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/ruamel.yaml.clib-0.2.7-py312h02f2b3b_2.conda#39478f82c46bd2fa4e974ef11cf2c0ae
|
||||
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
|
||||
https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda#d08db09a552699ee9e7eec56b4eb3899
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2#5844808ffab9ebdb694585b50ba02a96
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomlkit-0.12.3-pyha770c72_0.conda#074d0ce7a6261ab8b497c3518796ef3e
|
||||
https://conda.anaconda.org/conda-forge/noarch/trove-classifiers-2024.1.8-pyhd8ed1ab_0.conda#b120d43603f9b021d252fb7754b35557
|
||||
https://conda.anaconda.org/conda-forge/noarch/truststore-0.8.0-pyhd8ed1ab_0.conda#08316d001eca8854392cf2837828ea11
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
|
||||
https://conda.anaconda.org/conda-forge/noarch/zipp-3.17.0-pyhd8ed1ab_0.conda#2e4d6bc0b14e10f895fc6791a7d9b26a
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/cffi-1.16.0-py312h8e38eb3_0.conda#960ecbd65860d3b1de5e30373e1bffb1
|
||||
https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.1-pyha770c72_0.conda#746623a787e06191d80a2133e5daff17
|
||||
https://conda.anaconda.org/conda-forge/noarch/jaraco.classes-3.3.0-pyhd8ed1ab_0.conda#e9f79248d30e942f7c358ff21a1790f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/jsonpatch-1.33-pyhd8ed1ab_0.conda#bfdb7c5c6ad1077c82a69a8642c87aff
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libcblas-3.9.0-20_osxarm64_openblas.conda#89f4718753c08afe8cda4dd5791ba94c
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/liblapack-3.9.0-20_osxarm64_openblas.conda#1fefac78f2315455ce2d7f34782eac0a
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libmamba-1.5.6-h90c426b_0.conda#d17c7a5761e8983d97ccd650f5e6baaa
|
||||
https://conda.anaconda.org/conda-forge/noarch/pexpect-4.8.0-pyh1a96a4e_2.tar.bz2#330448ce4403cc74990ac07c555942a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pip-23.3.2-pyhd8ed1ab_0.conda#8591c748f98dcc02253003533bc2e4b1
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-plugin-export-1.6.0-pyhd8ed1ab_0.conda#1f2184db9f337d1074b1d5769165cac9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.0.0-pyhd8ed1ab_0.conda#21de50391d584eb7f4441b9de1ad773f
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/ruamel.yaml-0.18.5-py312he37b823_0.conda#bbda05ac095a271419f91ef133eddac3
|
||||
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.66.1-pyhd8ed1ab_0.conda#03c97908b976498dcae97eb4e4f3149c
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.9.0-hd8ed1ab_0.conda#c16524c1b7227dc80b36b4fa6f77cc86
|
||||
https://conda.anaconda.org/conda-forge/noarch/urllib3-2.1.0-pyhd8ed1ab_0.conda#f8ced8ee63830dec7ecc1be048d1470a
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/dulwich-0.21.7-py312he37b823_0.conda#4f12a0d01fb466149fe0cd8875c28a59
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/keyring-24.3.0-py312h81bd7bf_0.conda#3a6735f11d9604cbafd0ab1c3e9ac77e
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/libmambapy-1.5.6-py312h344e357_0.conda#1677e62b8f4e1779ee83ce3e2911b73e
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/numpy-1.26.3-py312h8442bc7_0.conda#bb3fc436e78e8bc43af8c672079749ea
|
||||
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.11.0-pyhd8ed1ab_0.conda#8f567c0a74aa44cf732f15773b4083b0
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-build-1.0.3-pyhd8ed1ab_0.conda#d9ccabf228cb98419ca3d5694b25e1a2
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-2.31.0-pyhd8ed1ab_0.conda#a30144e4156cdbb236f99ebb49828f8b
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/xattr-0.10.1-py312h02f2b3b_1.conda#9fdf7c6f41ccca372d72951a6f120c7c
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/zstandard-0.22.0-py312h7975427_0.conda#10c282af2c570a5a52173fd571693ec6
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-0.13.1-pyhd8ed1ab_0.conda#174bd699bb5aa9e2622eb4b288276ff8
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-streaming-0.9.0-pyhd8ed1ab_0.conda#38253361efb303deead3eab39ae9269b
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/rapidfuzz-3.6.1-py312h20a0b95_0.conda#a359029e6d2b3518c23574def88518d7
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_0.conda#99c98318c8646b08cc764f90ce98906e
|
||||
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.25.0-pyhd8ed1ab_0.conda#c119653cba436d8183c27bf6d190e587
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-with-filecache-0.13.1-pyhd8ed1ab_0.conda#8c4781ca0893cff3a64423954ce234a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/cleo-2.1.0-pyhd8ed1ab_0.conda#69569ea8a6d1465193345a40421d138b
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-handling-2.2.0-pyh38be061_0.conda#8a3ae7f6318376aa08ea753367bb7dd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-1.7.1-osx_pyh534df25_0.conda#4ebf180279e2c0274249cafdd29720cf
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/conda-23.11.0-py312h81bd7bf_1.conda#8762fef47fc50d0cc3be18ce381264ec
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-libmamba-solver-23.12.0-pyhd8ed1ab_0.conda#e877d5150e73a0844ea2939be110c3b1
|
||||
https://conda.anaconda.org/conda-forge/osx-arm64/mamba-1.5.6-py312h14bc7db_0.conda#313ba994472a1b9798683efe4c9a28c6
|
||||
@@ -1,113 +0,0 @@
|
||||
# Generated by conda-lock.
|
||||
# platform: win-64
|
||||
# input_hash: ce7b69eb63f85fe9c4f89a148490ec7ea87b2fc66fdef0c7162dcc4e28d78b22
|
||||
@EXPLICIT
|
||||
https://conda.anaconda.org/conda-forge/win-64/ca-certificates-2023.11.17-h56e8100_0.conda#1163114b483f26761f993c709e65271f
|
||||
https://conda.anaconda.org/conda-forge/win-64/intel-openmp-2023.2.0-h57928b3_50497.conda#a401f3cae152deb75bbed766a90a6312
|
||||
https://conda.anaconda.org/conda-forge/win-64/libexpat-2.5.0-h63175ca_1.conda#636cc3cbbd2e28bcfd2f73b2044aac2c
|
||||
https://conda.anaconda.org/conda-forge/noarch/pybind11-abi-4-hd8ed1ab_3.tar.bz2#878f923dd6acc8aeb47a75da6c4098be
|
||||
https://conda.anaconda.org/conda-forge/win-64/python_abi-3.12-4_cp312.conda#17f4ccf6be9ded08bd0a376f489ac1a6
|
||||
https://conda.anaconda.org/conda-forge/noarch/tzdata-2023d-h0c530f3_0.conda#8dee24b8be2d9ff81e7bd4d7d97ff1b0
|
||||
https://conda.anaconda.org/conda-forge/win-64/ucrt-10.0.22621.0-h57928b3_0.tar.bz2#72608f6cd3e5898229c3ea16deb1ac43
|
||||
https://conda.anaconda.org/conda-forge/win-64/vc14_runtime-14.38.33130-h82b7239_18.conda#8be79fdd2725ddf7bbf8a27a4c1f79ba
|
||||
https://conda.anaconda.org/conda-forge/win-64/vc-14.3-hcf57466_18.conda#20e1e652a4c740fa719002a8449994a2
|
||||
https://conda.anaconda.org/conda-forge/win-64/vs2015_runtime-14.38.33130-hcb4865c_18.conda#10d42885e3ed84e575b454db30f1aa93
|
||||
https://conda.anaconda.org/conda-forge/win-64/bzip2-1.0.8-hcfcfb64_5.conda#26eb8ca6ea332b675e11704cce84a3be
|
||||
https://conda.anaconda.org/conda-forge/win-64/fmt-10.1.1-h181d51b_1.conda#78dcab83827f41410cf1e70d39d3b36e
|
||||
https://conda.anaconda.org/conda-forge/win-64/libffi-3.4.2-h8ffe710_5.tar.bz2#2c96d1b6915b408893f9472569dee135
|
||||
https://conda.anaconda.org/conda-forge/win-64/libiconv-1.17-hcfcfb64_2.conda#e1eb10b1cca179f2baa3601e4efc8712
|
||||
https://conda.anaconda.org/conda-forge/win-64/libsqlite-3.44.2-hcfcfb64_0.conda#4a5f5ab56cbf3ccd08d71a1168061213
|
||||
https://conda.anaconda.org/conda-forge/win-64/libzlib-1.2.13-hcfcfb64_5.conda#5fdb9c6a113b6b6cb5e517fd972d5f41
|
||||
https://conda.anaconda.org/conda-forge/win-64/lz4-c-1.9.4-hcfcfb64_0.conda#e34720eb20a33fc3bfb8451dd837ab7a
|
||||
https://conda.anaconda.org/conda-forge/win-64/lzo-2.10-he774522_1000.tar.bz2#d5cf4b7eaa52316f135eed9e8548ad57
|
||||
https://conda.anaconda.org/conda-forge/win-64/openssl-3.2.0-hcfcfb64_1.conda#d10167022f99bad12ee07dea022d5830
|
||||
https://conda.anaconda.org/conda-forge/win-64/pthreads-win32-2.9.1-hfa6e2cd_3.tar.bz2#e2da8758d7d51ff6aa78a14dfb9dbed4
|
||||
https://conda.anaconda.org/conda-forge/win-64/reproc-14.2.4.post0-hcfcfb64_1.conda#887478162e563ea09451b19c22b1605b
|
||||
https://conda.anaconda.org/conda-forge/win-64/tk-8.6.13-h5226925_1.conda#fc048363eb8f03cd1737600a5d08aafe
|
||||
https://conda.anaconda.org/conda-forge/win-64/xz-5.2.6-h8d14728_0.tar.bz2#515d77642eaa3639413c6b1bc3f94219
|
||||
https://conda.anaconda.org/conda-forge/win-64/yaml-cpp-0.8.0-h63175ca_0.conda#9032e2129ea7afcc1a8e3d85715a931d
|
||||
https://conda.anaconda.org/conda-forge/win-64/krb5-1.21.2-heb0366b_0.conda#6e8b0f22b4eef3b3cb3849bb4c3d47f9
|
||||
https://conda.anaconda.org/conda-forge/win-64/libsolv-0.7.27-h12be248_0.conda#a62f8a595db21c4886cedd46cc842d63
|
||||
https://conda.anaconda.org/conda-forge/win-64/libssh2-1.11.0-h7dfc565_0.conda#dc262d03aae04fe26825062879141a41
|
||||
https://conda.anaconda.org/conda-forge/win-64/libxml2-2.11.6-hc3477c8_0.conda#08ffbb4c22dd3622e122058368f8b708
|
||||
https://conda.anaconda.org/conda-forge/win-64/python-3.12.1-h2628c8c_1_cpython.conda#19f49a5c0aea545792ad88bb40dc1ec9
|
||||
https://conda.anaconda.org/conda-forge/win-64/reproc-cpp-14.2.4.post0-h63175ca_1.conda#12fcd53cef836a4128c65c464ebb09d7
|
||||
https://conda.anaconda.org/conda-forge/win-64/zstd-1.5.5-h12be248_0.conda#792bb5da68bf0a6cac6a6072ecb8dbeb
|
||||
https://conda.anaconda.org/conda-forge/noarch/archspec-0.2.2-pyhd8ed1ab_0.conda#0dc2fce00a160271714647c019e3a8a8
|
||||
https://conda.anaconda.org/conda-forge/noarch/boltons-23.1.1-pyhd8ed1ab_0.conda#56febe65315cc388a5d20adf2b39a74d
|
||||
https://conda.anaconda.org/conda-forge/win-64/brotli-python-1.1.0-py312h53d5487_1.conda#d01a6667b99f0e8ad4097af66c938e62
|
||||
https://conda.anaconda.org/conda-forge/noarch/certifi-2023.11.17-pyhd8ed1ab_0.conda#2011bcf45376341dd1d690263fdbc789
|
||||
https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.3.2-pyhd8ed1ab_0.conda#7f4a9e3fcff3f6356ae99244a014da6a
|
||||
https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2#3faab06a954c2a04039983f2c4a50d99
|
||||
https://conda.anaconda.org/conda-forge/noarch/crashtest-0.4.1-pyhd8ed1ab_0.tar.bz2#709a2295dd907bb34afb57d54320642f
|
||||
https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda#db16c66b759a64dc5183d69cc3745a52
|
||||
https://conda.anaconda.org/conda-forge/noarch/distro-1.9.0-pyhd8ed1ab_0.conda#bbdb409974cd6cb30071b1d978302726
|
||||
https://conda.anaconda.org/conda-forge/noarch/filelock-3.13.1-pyhd8ed1ab_0.conda#0c1729b74a8152fde6a38ba0a2ab9f45
|
||||
https://conda.anaconda.org/conda-forge/noarch/idna-3.6-pyhd8ed1ab_0.conda#1a76f09108576397c41c0b0c5bd84134
|
||||
https://conda.anaconda.org/conda-forge/win-64/jsonpointer-2.4-py312h2e8e312_3.conda#9d9572e257bf4559f20629efb0d3511d
|
||||
https://conda.anaconda.org/conda-forge/win-64/libarchive-3.7.2-h6f8411a_0.conda#ef46bb4b1613b308b957a25407ff6f5b
|
||||
https://conda.anaconda.org/conda-forge/win-64/libcurl-8.5.0-hd5e4a3a_0.conda#c95eb3d60266dd47b8eb864e10d6bcf3
|
||||
https://conda.anaconda.org/conda-forge/win-64/libhwloc-2.9.3-default_haede6df_1009.conda#87da045f6d26ce9fe20ad76a18f6a18a
|
||||
https://conda.anaconda.org/conda-forge/win-64/menuinst-2.0.2-py312h53d5487_0.conda#ca8ca67bb6733fb295abd3c4e749ae13
|
||||
https://conda.anaconda.org/conda-forge/noarch/more-itertools-10.2.0-pyhd8ed1ab_0.conda#d5c98e9706fdc5328d49a9bf2ce5fb42
|
||||
https://conda.anaconda.org/conda-forge/win-64/msgpack-python-1.0.7-py312h0d7def4_0.conda#d99e74b66f04a1413cff5161f65cd4c9
|
||||
https://conda.anaconda.org/conda-forge/noarch/packaging-23.2-pyhd8ed1ab_0.conda#79002079284aa895f883c6b7f3f88fd6
|
||||
https://conda.anaconda.org/conda-forge/noarch/pkginfo-1.9.6-pyhd8ed1ab_0.conda#be1e9f1c65a1ed0f2ae9352fec99db64
|
||||
https://conda.anaconda.org/conda-forge/noarch/pluggy-1.3.0-pyhd8ed1ab_0.conda#2390bd10bed1f3fdc7a537fb5a447d8d
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-core-1.8.1-pyhd8ed1ab_0.conda#a013d99ae50670b823c511f7274d2d2a
|
||||
https://conda.anaconda.org/conda-forge/noarch/ptyprocess-0.7.0-pyhd3deb0d_0.tar.bz2#359eeb6536da0e687af562ed265ec263
|
||||
https://conda.anaconda.org/conda-forge/win-64/pycosat-0.6.6-py312he70551f_0.conda#619f8a019eaeffff3c9507fd2f5769c2
|
||||
https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2#076becd9e05608f8dc72757d5f3a91ff
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-fastjsonschema-2.19.1-pyhd8ed1ab_0.conda#4d3ceee3af4b0f9a1f48f57176bf8625
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-installer-0.7.0-pyhd8ed1ab_0.conda#65dea78f903d686c8b0c2feaf0e15e1f
|
||||
https://conda.anaconda.org/conda-forge/win-64/pywin32-ctypes-0.2.2-py312h2e8e312_1.conda#93a37178188cd6521e5410763a18aaf4
|
||||
https://conda.anaconda.org/conda-forge/win-64/ruamel.yaml.clib-0.2.7-py312he70551f_2.conda#ef47a90d50c6d69c9697038f9c01a6cb
|
||||
https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda#40695fdfd15a92121ed2922900d0308b
|
||||
https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda#d08db09a552699ee9e7eec56b4eb3899
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomli-2.0.1-pyhd8ed1ab_0.tar.bz2#5844808ffab9ebdb694585b50ba02a96
|
||||
https://conda.anaconda.org/conda-forge/noarch/tomlkit-0.12.3-pyha770c72_0.conda#074d0ce7a6261ab8b497c3518796ef3e
|
||||
https://conda.anaconda.org/conda-forge/noarch/trove-classifiers-2024.1.8-pyhd8ed1ab_0.conda#b120d43603f9b021d252fb7754b35557
|
||||
https://conda.anaconda.org/conda-forge/noarch/truststore-0.8.0-pyhd8ed1ab_0.conda#08316d001eca8854392cf2837828ea11
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.9.0-pyha770c72_0.conda#a92a6440c3fe7052d63244f3aba2a4a7
|
||||
https://conda.anaconda.org/conda-forge/noarch/wheel-0.42.0-pyhd8ed1ab_0.conda#1cdea58981c5cbc17b51973bcaddcea7
|
||||
https://conda.anaconda.org/conda-forge/noarch/win_inet_pton-1.1.0-pyhd8ed1ab_6.tar.bz2#30878ecc4bd36e8deeea1e3c151b2e0b
|
||||
https://conda.anaconda.org/conda-forge/noarch/zipp-3.17.0-pyhd8ed1ab_0.conda#2e4d6bc0b14e10f895fc6791a7d9b26a
|
||||
https://conda.anaconda.org/conda-forge/win-64/cffi-1.16.0-py312he70551f_0.conda#5a51096925d52332c62bfd8904899055
|
||||
https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.1-pyha770c72_0.conda#746623a787e06191d80a2133e5daff17
|
||||
https://conda.anaconda.org/conda-forge/noarch/jaraco.classes-3.3.0-pyhd8ed1ab_0.conda#e9f79248d30e942f7c358ff21a1790f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/jsonpatch-1.33-pyhd8ed1ab_0.conda#bfdb7c5c6ad1077c82a69a8642c87aff
|
||||
https://conda.anaconda.org/conda-forge/win-64/libmamba-1.5.6-h3f09ed1_0.conda#b9773f18a59065a8933ba439fe60e2c3
|
||||
https://conda.anaconda.org/conda-forge/noarch/pexpect-4.8.0-pyh1a96a4e_2.tar.bz2#330448ce4403cc74990ac07c555942a1
|
||||
https://conda.anaconda.org/conda-forge/noarch/pip-23.3.2-pyhd8ed1ab_0.conda#8591c748f98dcc02253003533bc2e4b1
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-plugin-export-1.6.0-pyhd8ed1ab_0.conda#1f2184db9f337d1074b1d5769165cac9
|
||||
https://conda.anaconda.org/conda-forge/noarch/pyproject_hooks-1.0.0-pyhd8ed1ab_0.conda#21de50391d584eb7f4441b9de1ad773f
|
||||
https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyh0701188_6.tar.bz2#56cd9fe388baac0e90c7149cfac95b60
|
||||
https://conda.anaconda.org/conda-forge/win-64/ruamel.yaml-0.18.5-py312he70551f_0.conda#e4d62d455007c8ffc251431a52bd9319
|
||||
https://conda.anaconda.org/conda-forge/win-64/tbb-2021.11.0-h91493d7_0.conda#517c08eba817fb0e56cfd411ed198261
|
||||
https://conda.anaconda.org/conda-forge/noarch/tqdm-4.66.1-pyhd8ed1ab_0.conda#03c97908b976498dcae97eb4e4f3149c
|
||||
https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.9.0-hd8ed1ab_0.conda#c16524c1b7227dc80b36b4fa6f77cc86
|
||||
https://conda.anaconda.org/conda-forge/win-64/keyring-24.3.0-py312h2e8e312_0.conda#b2ad5f984537e2705416e9de60e9bf52
|
||||
https://conda.anaconda.org/conda-forge/win-64/libmambapy-1.5.6-py312h66cf91f_0.conda#efd9aba451517607304b1934ed4ee494
|
||||
https://conda.anaconda.org/conda-forge/win-64/mkl-2023.2.0-h6a75c08_50497.conda#064cea9f45531e7b53584acf4bd8b044
|
||||
https://conda.anaconda.org/conda-forge/noarch/platformdirs-3.11.0-pyhd8ed1ab_0.conda#8f567c0a74aa44cf732f15773b4083b0
|
||||
https://conda.anaconda.org/conda-forge/noarch/python-build-1.0.3-pyhd8ed1ab_0.conda#d9ccabf228cb98419ca3d5694b25e1a2
|
||||
https://conda.anaconda.org/conda-forge/noarch/urllib3-2.1.0-pyhd8ed1ab_0.conda#f8ced8ee63830dec7ecc1be048d1470a
|
||||
https://conda.anaconda.org/conda-forge/win-64/zstandard-0.22.0-py312h01d794b_0.conda#36f4394759b1d5de1699446cadb2c8f5
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-streaming-0.9.0-pyhd8ed1ab_0.conda#38253361efb303deead3eab39ae9269b
|
||||
https://conda.anaconda.org/conda-forge/win-64/dulwich-0.21.7-py312he70551f_0.conda#1e0108590564c5c3b7235bb735d1b334
|
||||
https://conda.anaconda.org/conda-forge/win-64/libblas-3.9.0-20_win64_mkl.conda#6cad6cd2fbdeef4d651b8f752a4da960
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-2.31.0-pyhd8ed1ab_0.conda#a30144e4156cdbb236f99ebb49828f8b
|
||||
https://conda.anaconda.org/conda-forge/noarch/virtualenv-20.25.0-pyhd8ed1ab_0.conda#c119653cba436d8183c27bf6d190e587
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-0.13.1-pyhd8ed1ab_0.conda#174bd699bb5aa9e2622eb4b288276ff8
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-package-handling-2.2.0-pyh38be061_0.conda#8a3ae7f6318376aa08ea753367bb7dd6
|
||||
https://conda.anaconda.org/conda-forge/win-64/libcblas-3.9.0-20_win64_mkl.conda#e6d36cfcb2f2dff0f659d2aa0813eb2d
|
||||
https://conda.anaconda.org/conda-forge/win-64/liblapack-3.9.0-20_win64_mkl.conda#9510d07424d70fcac553d86b3e4a7c14
|
||||
https://conda.anaconda.org/conda-forge/noarch/requests-toolbelt-1.0.0-pyhd8ed1ab_0.conda#99c98318c8646b08cc764f90ce98906e
|
||||
https://conda.anaconda.org/conda-forge/noarch/cachecontrol-with-filecache-0.13.1-pyhd8ed1ab_0.conda#8c4781ca0893cff3a64423954ce234a1
|
||||
https://conda.anaconda.org/conda-forge/win-64/numpy-1.26.3-py312h8753938_0.conda#ced1f13bc58bd594257fcd3b1912c450
|
||||
https://conda.anaconda.org/conda-forge/win-64/rapidfuzz-3.6.1-py312h53d5487_0.conda#b01f0ddbb8061d4632b736cc73a5f6aa
|
||||
https://conda.anaconda.org/conda-forge/noarch/cleo-2.1.0-pyhd8ed1ab_0.conda#69569ea8a6d1465193345a40421d138b
|
||||
https://conda.anaconda.org/conda-forge/noarch/poetry-1.7.1-win_pyh7428d3b_0.conda#40353a0da2dabf3c044136c802ff77bb
|
||||
https://conda.anaconda.org/conda-forge/win-64/conda-23.11.0-py312h2e8e312_1.conda#741f165f5dd50d11461b15c123b93782
|
||||
https://conda.anaconda.org/conda-forge/noarch/conda-libmamba-solver-23.12.0-pyhd8ed1ab_0.conda#e877d5150e73a0844ea2939be110c3b1
|
||||
https://conda.anaconda.org/conda-forge/win-64/mamba-1.5.6-py312h5494d5c_0.conda#2b99a1797b991c1c70d54775b8588fc9
|
||||
@@ -0,0 +1,87 @@
|
||||
# Pre-Refactor Finalise Functionality Map
|
||||
|
||||
This document maps the functionality in the original `old_finalise.py` file, organized by major functional areas with specific line ranges.
|
||||
|
||||
## Class Definition and Initialization
|
||||
|
||||
- **Class Definition**: Lines 23-23
|
||||
- **Initialization and Configuration**: Lines 23-140
|
||||
- Logging setup: Lines 46-64
|
||||
- FFmpeg path and command setup: Lines 67-77
|
||||
- Configuration parameters: Lines 79-107
|
||||
- Feature flags: Lines 109-114
|
||||
- File naming conventions: Lines 116-137
|
||||
- Codec detection: Line 129
|
||||
|
||||
## Configuration and Validation
|
||||
|
||||
- **Input Files Validation**: Lines 142-171
|
||||
- **Output Filenames Preparation**: Lines 173-187
|
||||
- **User Interaction Utilities**: Lines 189-210
|
||||
- **Feature Validation**: Lines 212-271
|
||||
|
||||
## YouTube Integration
|
||||
|
||||
- **YouTube Authentication**: Lines 273-292
|
||||
- **YouTube Channel ID Retrieval**: Lines 294-305
|
||||
- **Video Existence Check**: Lines 307-345
|
||||
- **Video Deletion**: Lines 347-364
|
||||
- **Title Handling**: Lines 366-371
|
||||
- **Video Upload**: Lines 373-434
|
||||
|
||||
## Folder Organization and Branding
|
||||
|
||||
- **Brand Code Generation**: Lines 436-454
|
||||
- **Discord Notifications**: Lines 456-460
|
||||
- **File Organization**: Lines 589-607
|
||||
- **Public Share Directory Management**: Lines 609-652
|
||||
- **Remote Sync (rclone)**: Lines 654-668
|
||||
- **Sharing Link Generation**: Lines 682-702
|
||||
- **Existing Brand Code Extraction**: Lines 704-715
|
||||
|
||||
## File Discovery and Processing
|
||||
|
||||
- **With Vocals File Finding**: Lines 462-502
|
||||
- **Instrumental Audio Selection**: Lines 504-562
|
||||
- **Artist and Title Extraction**: Lines 564-587
|
||||
|
||||
## Video Processing (FFmpeg Operations)
|
||||
|
||||
- **Command Execution Wrapper**: Lines 589-596
|
||||
- **Video Remuxing with Instrumental Audio**: Lines 598-606
|
||||
- **MOV to MP4 Conversion**: Lines 608-616
|
||||
- **Lossless MP4 Encoding**: Lines 618-629
|
||||
- **Lossy MP4 Encoding**: Lines 631-639
|
||||
- **MKV Encoding**: Lines 641-649
|
||||
- **720p Version Encoding**: Lines 651-661
|
||||
- **Concatenation Filter Preparation**: Lines 663-675
|
||||
- **Final Video File Creation**: Lines 677-716
|
||||
|
||||
## CDG/TXT Creation (Karaoke File Formats)
|
||||
|
||||
- **CDG ZIP File Creation**: Lines 718-783
|
||||
- **TXT ZIP File Creation**: Lines 785-816
|
||||
|
||||
## Distribution and Notifications
|
||||
|
||||
- **Discord Notification Posting**: Lines 670-680
|
||||
- **Email Integration**: Lines 738-809
|
||||
- Gmail Authentication: Lines 738-757
|
||||
- Email Draft Creation: Lines 759-783
|
||||
- Email Template Testing: Lines 785-797
|
||||
|
||||
## Codec Detection
|
||||
|
||||
- **AAC Codec Detection**: Lines 799-813
|
||||
|
||||
## Main Processing Flow
|
||||
|
||||
- **Process Method (Main Workflow)**: Lines 815-886
|
||||
- Feature validation: Line 821
|
||||
- File discovery: Lines 823-827
|
||||
- Output preparation: Lines 829-830
|
||||
- CDG/TXT creation: Lines 832-835
|
||||
- Video processing: Line 837
|
||||
- Optional features execution: Line 839
|
||||
- Result compilation: Lines 841-861
|
||||
- Email notification: Line 863
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['karaoke_prep/utils/gen_cli.py'],
|
||||
['karaoke_gen/utils/gen_cli.py'],
|
||||
pathex=[],
|
||||
binaries=[('platform/ffmpeg.exe', '.')],
|
||||
datas=[],
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
"""
|
||||
Karaoke Generator package.
|
||||
|
||||
This package provides tools for generating karaoke videos with synchronized lyrics.
|
||||
It handles the entire process from downloading audio and lyrics to creating the final
|
||||
video with title screens, synchronized lyrics, and distribution options.
|
||||
"""
|
||||
|
||||
__version__ = "0.50.0"
|
||||
|
||||
# Import core components
|
||||
from karaoke_gen.controller import KaraokeController
|
||||
from karaoke_gen.core import ProjectConfig, Track, KaraokeGenError
|
||||
|
||||
# Import services
|
||||
from karaoke_gen.services import (
|
||||
MainService,
|
||||
AudioService,
|
||||
LyricsService,
|
||||
MediaService,
|
||||
VideoService,
|
||||
DistributionService,
|
||||
)
|
||||
|
||||
# Import utility functions
|
||||
from karaoke_gen.utils import (
|
||||
# Config utilities
|
||||
load_config_file,
|
||||
save_config_file,
|
||||
get_config_value,
|
||||
set_config_value,
|
||||
merge_configs,
|
||||
validate_required_config_keys,
|
||||
get_nested_config_value,
|
||||
set_nested_config_value,
|
||||
|
||||
# File utilities
|
||||
sanitize_filename,
|
||||
ensure_directory_exists,
|
||||
backup_existing_files,
|
||||
file_exists,
|
||||
copy_file,
|
||||
move_file,
|
||||
delete_file,
|
||||
create_zip_file,
|
||||
execute_command,
|
||||
|
||||
# Logging utilities
|
||||
setup_logger,
|
||||
get_log_level_from_string,
|
||||
configure_logger_from_config,
|
||||
log_section,
|
||||
log_subsection,
|
||||
log_dict,
|
||||
log_exception,
|
||||
|
||||
# Path utilities
|
||||
normalize_path,
|
||||
join_paths,
|
||||
get_absolute_path,
|
||||
get_relative_path,
|
||||
get_parent_directory,
|
||||
get_filename,
|
||||
get_filename_without_extension,
|
||||
get_file_extension,
|
||||
create_directory,
|
||||
delete_directory,
|
||||
list_files,
|
||||
list_directories,
|
||||
get_file_info,
|
||||
find_files_by_extension,
|
||||
copy_directory,
|
||||
move_directory,
|
||||
get_directory_size,
|
||||
|
||||
# String utilities
|
||||
slugify,
|
||||
truncate_string,
|
||||
extract_artist_and_title,
|
||||
format_duration,
|
||||
format_filesize,
|
||||
strip_html_tags,
|
||||
normalize_whitespace,
|
||||
extract_urls,
|
||||
replace_placeholders,
|
||||
generate_random_string,
|
||||
|
||||
# Validation utilities
|
||||
is_url,
|
||||
is_file,
|
||||
is_directory,
|
||||
prompt_user_confirmation_or_raise_exception,
|
||||
prompt_user_bool,
|
||||
validate_input_parameters_for_features,
|
||||
|
||||
# Date utilities
|
||||
get_current_timestamp,
|
||||
get_current_date,
|
||||
get_current_time,
|
||||
format_date,
|
||||
parse_date,
|
||||
get_date_components,
|
||||
add_days,
|
||||
days_between,
|
||||
is_date_in_range,
|
||||
get_month_name,
|
||||
get_day_of_week,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Version
|
||||
"__version__",
|
||||
|
||||
# Core components
|
||||
"KaraokeController",
|
||||
"ProjectConfig",
|
||||
"Track",
|
||||
"KaraokeGenError",
|
||||
|
||||
# Services
|
||||
"MainService",
|
||||
"AudioService",
|
||||
"LyricsService",
|
||||
"MediaService",
|
||||
"VideoService",
|
||||
"DistributionService",
|
||||
|
||||
# Config utilities
|
||||
"load_config_file",
|
||||
"save_config_file",
|
||||
"get_config_value",
|
||||
"set_config_value",
|
||||
"merge_configs",
|
||||
"validate_required_config_keys",
|
||||
"get_nested_config_value",
|
||||
"set_nested_config_value",
|
||||
|
||||
# File utilities
|
||||
"sanitize_filename",
|
||||
"ensure_directory_exists",
|
||||
"backup_existing_files",
|
||||
"file_exists",
|
||||
"copy_file",
|
||||
"move_file",
|
||||
"delete_file",
|
||||
"create_zip_file",
|
||||
"execute_command",
|
||||
|
||||
# Logging utilities
|
||||
"setup_logger",
|
||||
"get_log_level_from_string",
|
||||
"configure_logger_from_config",
|
||||
"log_section",
|
||||
"log_subsection",
|
||||
"log_dict",
|
||||
"log_exception",
|
||||
|
||||
# Path utilities
|
||||
"normalize_path",
|
||||
"join_paths",
|
||||
"get_absolute_path",
|
||||
"get_relative_path",
|
||||
"get_parent_directory",
|
||||
"get_filename",
|
||||
"get_filename_without_extension",
|
||||
"get_file_extension",
|
||||
"create_directory",
|
||||
"delete_directory",
|
||||
"list_files",
|
||||
"list_directories",
|
||||
"get_file_info",
|
||||
"find_files_by_extension",
|
||||
"copy_directory",
|
||||
"move_directory",
|
||||
"get_directory_size",
|
||||
|
||||
# String utilities
|
||||
"slugify",
|
||||
"truncate_string",
|
||||
"extract_artist_and_title",
|
||||
"format_duration",
|
||||
"format_filesize",
|
||||
"strip_html_tags",
|
||||
"normalize_whitespace",
|
||||
"extract_urls",
|
||||
"replace_placeholders",
|
||||
"generate_random_string",
|
||||
|
||||
# Validation utilities
|
||||
"is_url",
|
||||
"is_file",
|
||||
"is_directory",
|
||||
"prompt_user_confirmation_or_raise_exception",
|
||||
"prompt_user_bool",
|
||||
"validate_input_parameters_for_features",
|
||||
|
||||
# Date utilities
|
||||
"get_current_timestamp",
|
||||
"get_current_date",
|
||||
"get_current_time",
|
||||
"format_date",
|
||||
"parse_date",
|
||||
"get_date_components",
|
||||
"add_days",
|
||||
"days_between",
|
||||
"is_date_in_range",
|
||||
"get_month_name",
|
||||
"get_day_of_week",
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Main entry point for the karaoke generator.
|
||||
"""
|
||||
|
||||
from karaoke_gen.cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
Command-line interface module for the karaoke_gen package.
|
||||
|
||||
This module provides the command-line interface for the karaoke generator.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from typing import Dict, Any
|
||||
|
||||
from karaoke_gen.cli.parser import parse_args, create_parser
|
||||
from karaoke_gen.cli.commands import execute_command, get_command, Command, ProcessCommand, TestEmailTemplateCommand, BulkProcessCommand
|
||||
|
||||
__all__ = [
|
||||
"main",
|
||||
"parse_args",
|
||||
"create_parser",
|
||||
"execute_command",
|
||||
"get_command",
|
||||
"Command",
|
||||
"ProcessCommand",
|
||||
"TestEmailTemplateCommand",
|
||||
"BulkProcessCommand",
|
||||
]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
Main entry point for the CLI.
|
||||
"""
|
||||
args = parse_args()
|
||||
asyncio.run(execute_command(args))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Main entry point for running the CLI as a module.
|
||||
"""
|
||||
|
||||
from karaoke_gen.cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -7,16 +7,30 @@ import csv
|
||||
import asyncio
|
||||
import json
|
||||
import sys
|
||||
from karaoke_prep import KaraokePrep
|
||||
from karaoke_prep.karaoke_finalise import KaraokeFinalise
|
||||
from typing import Dict, Any, List
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.controller import KaraokeController
|
||||
from karaoke_gen.utils.logging import setup_logger
|
||||
|
||||
# Global logger
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO) # Set initial log level
|
||||
|
||||
|
||||
async def process_track_prep(row, args, logger, log_formatter):
|
||||
"""First phase: Process a track through prep stage only, without video rendering"""
|
||||
async def process_track_prep(row: Dict[str, str], args: Dict[str, Any], log_formatter: logging.Formatter) -> bool:
|
||||
"""
|
||||
First phase: Process a track through prep stage only, without video rendering.
|
||||
|
||||
Args:
|
||||
row: The CSV row containing track information
|
||||
args: The parsed command-line arguments
|
||||
log_formatter: The log formatter to use
|
||||
|
||||
Returns:
|
||||
True if processing was successful, False otherwise
|
||||
"""
|
||||
original_dir = os.getcwd()
|
||||
try:
|
||||
artist = row["Artist"].strip()
|
||||
@@ -26,20 +40,36 @@ async def process_track_prep(row, args, logger, log_formatter):
|
||||
|
||||
logger.info(f"Initial prep phase for track: {artist} - {title}")
|
||||
|
||||
kprep = KaraokePrep(
|
||||
# Create configuration
|
||||
config = ProjectConfig(
|
||||
# Basic inputs
|
||||
artist=artist,
|
||||
title=title,
|
||||
input_media=guide_file,
|
||||
existing_instrumental=instrumental_file,
|
||||
style_params_json=args.style_params_json,
|
||||
|
||||
# Workflow control
|
||||
prep_only=True, # Only run prep phase
|
||||
render_video=False, # No video rendering in first phase
|
||||
|
||||
# Logging & Debugging
|
||||
logger=logger,
|
||||
log_level=args.log_level,
|
||||
dry_run=args.dry_run,
|
||||
render_video=False, # First phase: no video rendering
|
||||
log_level=args.get("log_level", logging.INFO),
|
||||
log_formatter=log_formatter,
|
||||
dry_run=args.get("dry_run", False),
|
||||
|
||||
# Input/Output Configuration
|
||||
output_dir=args.get("output_dir", "."),
|
||||
create_track_subfolders=True,
|
||||
|
||||
# Style Configuration
|
||||
style_params_json=args.get("style_params_json"),
|
||||
)
|
||||
|
||||
tracks = await kprep.process()
|
||||
|
||||
# Create controller and process
|
||||
controller = KaraokeController(config)
|
||||
tracks = await controller.process()
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Failed initial prep for {artist} - {title}: {str(e)}")
|
||||
@@ -48,10 +78,18 @@ async def process_track_prep(row, args, logger, log_formatter):
|
||||
os.chdir(original_dir)
|
||||
|
||||
|
||||
async def process_track_render(row, args, logger, log_formatter):
|
||||
"""Second phase: Re-run prep with video rendering and run finalise"""
|
||||
# This is mostly the same as the original process_track function
|
||||
# but with render_video=True and includes finalisation
|
||||
async def process_track_render(row: Dict[str, str], args: Dict[str, Any], log_formatter: logging.Formatter) -> bool:
|
||||
"""
|
||||
Second phase: Re-run prep with video rendering and run finalise.
|
||||
|
||||
Args:
|
||||
row: The CSV row containing track information
|
||||
args: The parsed command-line arguments
|
||||
log_formatter: The log formatter to use
|
||||
|
||||
Returns:
|
||||
True if processing was successful, False otherwise
|
||||
"""
|
||||
original_dir = os.getcwd()
|
||||
try:
|
||||
artist = row["Artist"].strip()
|
||||
@@ -61,86 +99,52 @@ async def process_track_render(row, args, logger, log_formatter):
|
||||
|
||||
logger.info(f"Render phase for track: {artist} - {title}")
|
||||
|
||||
kprep = KaraokePrep(
|
||||
# Create configuration for the render phase
|
||||
config = ProjectConfig(
|
||||
# Basic inputs
|
||||
artist=artist,
|
||||
title=title,
|
||||
input_media=guide_file,
|
||||
existing_instrumental=instrumental_file,
|
||||
style_params_json=args.style_params_json,
|
||||
logger=logger,
|
||||
log_level=args.log_level,
|
||||
dry_run=args.dry_run,
|
||||
|
||||
# Workflow control
|
||||
render_video=True,
|
||||
create_track_subfolders=True,
|
||||
skip_transcription_review=True,
|
||||
|
||||
# Logging & Debugging
|
||||
logger=logger,
|
||||
log_level=args.get("log_level", logging.INFO),
|
||||
log_formatter=log_formatter,
|
||||
dry_run=args.get("dry_run", False),
|
||||
|
||||
# Input/Output Configuration
|
||||
output_dir=args.get("output_dir", "."),
|
||||
create_track_subfolders=True,
|
||||
|
||||
# Style Configuration
|
||||
style_params_json=args.get("style_params_json"),
|
||||
|
||||
# Finalisation Configuration
|
||||
enable_cdg=args.get("enable_cdg", False),
|
||||
enable_txt=args.get("enable_txt", False),
|
||||
brand_prefix=args.get("brand_prefix"),
|
||||
organised_dir=args.get("organised_dir"),
|
||||
organised_dir_rclone_root=args.get("organised_dir_rclone_root"),
|
||||
public_share_dir=args.get("public_share_dir"),
|
||||
youtube_client_secrets_file=args.get("youtube_client_secrets_file"),
|
||||
youtube_description_file=args.get("youtube_description_file"),
|
||||
rclone_destination=args.get("rclone_destination"),
|
||||
discord_webhook_url=args.get("discord_webhook_url"),
|
||||
email_template_file=args.get("email_template_file"),
|
||||
non_interactive=True, # Always run in non-interactive mode for bulk processing
|
||||
)
|
||||
|
||||
tracks = await kprep.process()
|
||||
|
||||
# Step 2: For each track, run KaraokeFinalise
|
||||
for track in tracks:
|
||||
logger.info(f"Starting finalisation phase for {track['artist']} - {track['title']}...")
|
||||
|
||||
# Look for the track directory, trying different possible formats
|
||||
possible_dirs = [
|
||||
os.path.join(args.output_dir, f"{track['artist']} - {track['title']}"),
|
||||
os.path.join(args.output_dir, f"{artist} - {title}"),
|
||||
os.path.join(args.output_dir, f"{artist.replace(' ', ' ')} - {title}"),
|
||||
]
|
||||
|
||||
track_dir = None
|
||||
for possible_dir in possible_dirs:
|
||||
if os.path.exists(possible_dir):
|
||||
track_dir = possible_dir
|
||||
break
|
||||
|
||||
if track_dir is None:
|
||||
logger.error(f"Track directory not found. Tried: {possible_dirs}")
|
||||
continue
|
||||
|
||||
logger.info(f"Changing to directory: {track_dir}")
|
||||
os.chdir(track_dir)
|
||||
|
||||
# Load CDG styles if CDG generation is enabled
|
||||
cdg_styles = None
|
||||
if args.enable_cdg:
|
||||
if not args.style_params_json:
|
||||
logger.error("CDG styles JSON file path (--style_params_json) is required when --enable_cdg is used")
|
||||
sys.exit(1)
|
||||
try:
|
||||
with open(args.style_params_json, "r") as f:
|
||||
style_params = json.loads(f.read())
|
||||
cdg_styles = style_params["cdg"]
|
||||
except FileNotFoundError:
|
||||
logger.error(f"CDG styles configuration file not found: {args.style_params_json}")
|
||||
sys.exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in CDG styles configuration file: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Initialize KaraokeFinalise
|
||||
kfinalise = KaraokeFinalise(
|
||||
log_formatter=log_formatter,
|
||||
log_level=args.log_level,
|
||||
dry_run=args.dry_run,
|
||||
enable_cdg=args.enable_cdg,
|
||||
enable_txt=args.enable_txt,
|
||||
cdg_styles=cdg_styles,
|
||||
non_interactive=True,
|
||||
)
|
||||
|
||||
try:
|
||||
final_track = kfinalise.process()
|
||||
logger.info(f"Successfully completed auto processing for: {track['artist']} - {track['title']}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error during finalisation: {str(e)}")
|
||||
raise e
|
||||
|
||||
# Always return to the original directory after processing
|
||||
os.chdir(original_dir)
|
||||
|
||||
|
||||
# Create controller and process
|
||||
controller = KaraokeController(config)
|
||||
tracks = await controller.process()
|
||||
|
||||
logger.info(f"Successfully completed auto processing for: {artist} - {title}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed render/finalise for {artist} - {title}: {str(e)}")
|
||||
return False
|
||||
@@ -148,8 +152,15 @@ async def process_track_render(row, args, logger, log_formatter):
|
||||
os.chdir(original_dir)
|
||||
|
||||
|
||||
def update_csv_status(csv_path, row_index, new_status):
|
||||
"""Update the status of a processed row in the CSV file"""
|
||||
def update_csv_status(csv_path: str, row_index: int, new_status: str) -> None:
|
||||
"""
|
||||
Update the status of a processed row in the CSV file.
|
||||
|
||||
Args:
|
||||
csv_path: The path to the CSV file
|
||||
row_index: The index of the row to update
|
||||
new_status: The new status to set
|
||||
"""
|
||||
# Read all rows
|
||||
with open(csv_path, "r") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
@@ -165,7 +176,10 @@ def update_csv_status(csv_path, row_index, new_status):
|
||||
writer.writerows(rows)
|
||||
|
||||
|
||||
async def async_main():
|
||||
async def async_main() -> None:
|
||||
"""
|
||||
Main async function for bulk processing.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Process multiple karaoke tracks in bulk from a CSV file.",
|
||||
formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=54),
|
||||
@@ -203,6 +217,44 @@ async def async_main():
|
||||
action="store_true",
|
||||
help="Optional: Enable TXT ZIP generation during finalisation. Example: --enable_txt",
|
||||
)
|
||||
|
||||
# Distribution-specific arguments
|
||||
parser.add_argument(
|
||||
"--brand_prefix",
|
||||
help="Optional: Your brand prefix to calculate the next sequential number. Example: --brand_prefix=BRAND",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--organised_dir",
|
||||
help="Optional: Target directory where the processed folder will be moved. Example: --organised_dir='/path/to/Tracks-Organized'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--organised_dir_rclone_root",
|
||||
help="Optional: Rclone path which maps to your organised_dir. Example: --organised_dir_rclone_root='dropbox:Media/Karaoke/Tracks-Organized'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--public_share_dir",
|
||||
help="Optional: Public share directory for final files. Example: --public_share_dir='/path/to/Tracks-PublicShare'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--youtube_client_secrets_file",
|
||||
help="Optional: Path to youtube client secrets file. Example: --youtube_client_secrets_file='/path/to/client_secret.json'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--youtube_description_file",
|
||||
help="Optional: Path to youtube description template. Example: --youtube_description_file='/path/to/description.txt'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--rclone_destination",
|
||||
help="Optional: Rclone destination for public_share_dir sync. Example: --rclone_destination='googledrive:KaraokeFolder'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--discord_webhook_url",
|
||||
help="Optional: Discord webhook URL for notifications. Example: --discord_webhook_url='https://discord.com/api/webhooks/...'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--email_template_file",
|
||||
help="Optional: Path to email template file. Example: --email_template_file='/path/to/template.txt'",
|
||||
)
|
||||
|
||||
# Logging & Debugging
|
||||
parser.add_argument(
|
||||
@@ -229,6 +281,9 @@ async def async_main():
|
||||
log_level = getattr(logging, args.log_level.upper())
|
||||
args.log_level = log_level # Store the numeric log level in args
|
||||
|
||||
# Convert args to dictionary for easier access
|
||||
args_dict = vars(args)
|
||||
|
||||
logger.info(f"Starting bulk processing with input CSV: {args.input_csv}")
|
||||
|
||||
# Read CSV
|
||||
@@ -243,7 +298,7 @@ async def async_main():
|
||||
logger.info(f"Skipping {row['Artist']} - {row['Title']} (Status: {row['Status']})")
|
||||
continue
|
||||
|
||||
success = await process_track_prep(row, args, logger, log_formatter)
|
||||
success = await process_track_prep(row, args_dict, log_formatter)
|
||||
if not args.dry_run:
|
||||
if success:
|
||||
update_csv_status(args.input_csv, i, "Prep_Complete")
|
||||
@@ -257,7 +312,7 @@ async def async_main():
|
||||
logger.info(f"Skipping {row['Artist']} - {row['Title']} (Status: {row['Status']})")
|
||||
continue
|
||||
|
||||
success = await process_track_render(row, args, logger, log_formatter)
|
||||
success = await process_track_render(row, args_dict, log_formatter)
|
||||
if not args.dry_run:
|
||||
if success:
|
||||
update_csv_status(args.input_csv, i, "Completed")
|
||||
@@ -265,7 +320,10 @@ async def async_main():
|
||||
update_csv_status(args.input_csv, i, "Render_Failed")
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""
|
||||
Main entry point for bulk processing.
|
||||
"""
|
||||
# Set up logging only once
|
||||
global log_formatter # Make log_formatter accessible to other functions
|
||||
log_handler = logging.StreamHandler()
|
||||
@@ -0,0 +1,441 @@
|
||||
import os
|
||||
import logging
|
||||
import asyncio
|
||||
import time
|
||||
import pyperclip
|
||||
import json
|
||||
import warnings
|
||||
from typing import Dict, Any, List, Optional
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.controller import KaraokeController
|
||||
from karaoke_gen.cli.bulk_cli import async_main as bulk_async_main
|
||||
|
||||
|
||||
class Command(ABC):
|
||||
"""Base class for all commands."""
|
||||
|
||||
@abstractmethod
|
||||
async def execute(self, args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Execute the command.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class ProcessCommand(Command):
|
||||
"""Command for processing a track or tracks."""
|
||||
|
||||
async def execute(self, args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Execute the process command.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
"""
|
||||
# Set up logging
|
||||
logger = logging.getLogger(__name__)
|
||||
log_handler = logging.StreamHandler()
|
||||
log_formatter = logging.Formatter(
|
||||
fmt="%(asctime)s.%(msecs)03d - %(levelname)s - %(module)s - %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
log_handler.setFormatter(log_formatter)
|
||||
logger.addHandler(log_handler)
|
||||
|
||||
log_level = getattr(logging, args.get("log_level", "INFO").upper())
|
||||
logger.setLevel(log_level)
|
||||
|
||||
# Parse input arguments
|
||||
input_media, artist, title, filename_pattern = self._parse_input_args(args, logger)
|
||||
|
||||
# Set up environment variables for lyrics-only mode
|
||||
if args.get("lyrics_only"):
|
||||
args["skip_separation"] = True
|
||||
os.environ["KARAOKE_GEN_SKIP_AUDIO_SEPARATION"] = "1"
|
||||
os.environ["KARAOKE_GEN_SKIP_TITLE_END_SCREENS"] = "1"
|
||||
logger.info("Lyrics-only mode enabled: skipping audio separation and title/end screen generation")
|
||||
|
||||
# Create configuration
|
||||
config = self._create_config(args, input_media, artist, title, filename_pattern, log_formatter, log_level, logger)
|
||||
|
||||
# Create controller
|
||||
controller = KaraokeController(config)
|
||||
|
||||
# Process tracks
|
||||
tracks = await controller.process()
|
||||
|
||||
# Display results
|
||||
self._display_results(tracks, args, logger)
|
||||
|
||||
def _parse_input_args(self, args: Dict[str, Any], logger: logging.Logger) -> tuple:
|
||||
"""
|
||||
Parse input arguments.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
logger: The logger
|
||||
|
||||
Returns:
|
||||
Tuple of (input_media, artist, title, filename_pattern)
|
||||
"""
|
||||
input_media, artist, title, filename_pattern = None, None, None, None
|
||||
|
||||
if not args.get("args"):
|
||||
logger.error("No input arguments provided")
|
||||
exit(1)
|
||||
|
||||
# Allow 3 forms of positional arguments:
|
||||
# 1. URL or Media File only (may be single track URL, playlist URL, or local file)
|
||||
# 2. Artist and Title only
|
||||
# 3. URL, Artist, and Title
|
||||
if args["args"] and (self._is_url(args["args"][0]) or self._is_file(args["args"][0])):
|
||||
input_media = args["args"][0]
|
||||
if len(args["args"]) > 2:
|
||||
artist = args["args"][1]
|
||||
title = args["args"][2]
|
||||
elif len(args["args"]) > 1:
|
||||
artist = args["args"][1]
|
||||
else:
|
||||
logger.warning("Input media provided without Artist and Title, both will be guessed from title")
|
||||
|
||||
elif os.path.isdir(args["args"][0]):
|
||||
if not args.get("filename_pattern"):
|
||||
logger.error("Filename pattern is required when processing a folder.")
|
||||
exit(1)
|
||||
if len(args["args"]) <= 1:
|
||||
logger.error("Second parameter provided must be Artist name; Artist is required when processing a folder.")
|
||||
exit(1)
|
||||
|
||||
input_media = args["args"][0]
|
||||
artist = args["args"][1]
|
||||
filename_pattern = args.get("filename_pattern")
|
||||
|
||||
elif len(args["args"]) > 1:
|
||||
artist = args["args"][0]
|
||||
title = args["args"][1]
|
||||
logger.warning(f"No input media provided, the top YouTube search result for {artist} - {title} will be used.")
|
||||
|
||||
else:
|
||||
logger.error("Invalid input arguments")
|
||||
exit(1)
|
||||
|
||||
return input_media, artist, title, filename_pattern
|
||||
|
||||
def _is_url(self, string: str) -> bool:
|
||||
"""
|
||||
Check if a string is a URL.
|
||||
|
||||
Args:
|
||||
string: The string to check
|
||||
|
||||
Returns:
|
||||
True if the string is a URL, False otherwise
|
||||
"""
|
||||
return string.startswith("http://") or string.startswith("https://")
|
||||
|
||||
def _is_file(self, string: str) -> bool:
|
||||
"""
|
||||
Check if a string is a file.
|
||||
|
||||
Args:
|
||||
string: The string to check
|
||||
|
||||
Returns:
|
||||
True if the string is a file, False otherwise
|
||||
"""
|
||||
return os.path.isfile(string)
|
||||
|
||||
def _create_config(self, args: Dict[str, Any], input_media: Optional[str], artist: Optional[str],
|
||||
title: Optional[str], filename_pattern: Optional[str], log_formatter: logging.Formatter,
|
||||
log_level: int, logger: logging.Logger) -> ProjectConfig:
|
||||
"""
|
||||
Create a project configuration.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
input_media: The input media
|
||||
artist: The artist
|
||||
title: The title
|
||||
filename_pattern: The filename pattern
|
||||
log_formatter: The log formatter
|
||||
log_level: The log level
|
||||
logger: The logger
|
||||
|
||||
Returns:
|
||||
The project configuration
|
||||
"""
|
||||
# Load CDG styles if CDG generation is enabled
|
||||
cdg_styles = None
|
||||
if args.get("enable_cdg") and args.get("style_params_json"):
|
||||
try:
|
||||
with open(args.get("style_params_json"), "r") as f:
|
||||
style_params = json.loads(f.read())
|
||||
cdg_styles = style_params.get("cdg")
|
||||
except FileNotFoundError:
|
||||
logger.error(f"CDG styles configuration file not found: {args.get('style_params_json')}")
|
||||
exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in CDG styles configuration file: {e}")
|
||||
exit(1)
|
||||
|
||||
return ProjectConfig(
|
||||
# Basic inputs
|
||||
input_media=input_media,
|
||||
artist=artist,
|
||||
title=title,
|
||||
filename_pattern=filename_pattern,
|
||||
|
||||
# Workflow control
|
||||
prep_only=args.get("prep_only", False),
|
||||
finalise_only=args.get("finalise_only", False),
|
||||
skip_transcription=args.get("skip_transcription", False),
|
||||
skip_separation=args.get("skip_separation", False),
|
||||
skip_lyrics=args.get("skip_lyrics", False),
|
||||
lyrics_only=args.get("lyrics_only", False),
|
||||
edit_lyrics=args.get("edit_lyrics", False),
|
||||
|
||||
# Logging & Debugging
|
||||
dry_run=args.get("dry_run", False),
|
||||
logger=logger,
|
||||
log_level=log_level,
|
||||
log_formatter=log_formatter,
|
||||
render_bounding_boxes=args.get("render_bounding_boxes", False),
|
||||
|
||||
# Input/Output Configuration
|
||||
output_dir=args.get("output_dir", "."),
|
||||
create_track_subfolders=args.get("no_track_subfolders", True),
|
||||
lossless_output_format=args.get("lossless_output_format", "FLAC"),
|
||||
output_png=args.get("output_png", True),
|
||||
output_jpg=args.get("output_jpg", True),
|
||||
|
||||
# Audio Processing Configuration
|
||||
clean_instrumental_model=args.get("clean_instrumental_model", "model_bs_roformer_ep_317_sdr_12.9755.ckpt"),
|
||||
backing_vocals_models=args.get("backing_vocals_models", ["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"]),
|
||||
other_stems_models=args.get("other_stems_models", ["htdemucs_6s.yaml"]),
|
||||
model_file_dir=args.get("model_file_dir", os.path.join(os.path.dirname(os.path.dirname(__file__)), "models")),
|
||||
existing_instrumental=args.get("existing_instrumental"),
|
||||
instrumental_format=args.get("instrumental_format", "flac"),
|
||||
|
||||
# Lyrics Configuration
|
||||
lyrics_artist=args.get("lyrics_artist"),
|
||||
lyrics_title=args.get("lyrics_title"),
|
||||
lyrics_file=args.get("lyrics_file"),
|
||||
skip_transcription_review=args.get("skip_transcription_review", False),
|
||||
subtitle_offset_ms=args.get("subtitle_offset_ms", 0),
|
||||
|
||||
# Style Configuration
|
||||
style_params_json=args.get("style_params_json"),
|
||||
|
||||
# Finalisation Configuration
|
||||
enable_cdg=args.get("enable_cdg", False),
|
||||
enable_txt=args.get("enable_txt", False),
|
||||
brand_prefix=args.get("brand_prefix"),
|
||||
organised_dir=args.get("organised_dir"),
|
||||
organised_dir_rclone_root=args.get("organised_dir_rclone_root"),
|
||||
public_share_dir=args.get("public_share_dir"),
|
||||
youtube_client_secrets_file=args.get("youtube_client_secrets_file"),
|
||||
youtube_description_file=args.get("youtube_description_file"),
|
||||
rclone_destination=args.get("rclone_destination"),
|
||||
discord_webhook_url=args.get("discord_webhook_url"),
|
||||
email_template_file=args.get("email_template_file"),
|
||||
cdg_styles=cdg_styles,
|
||||
keep_brand_code=args.get("keep_brand_code", False),
|
||||
non_interactive=args.get("yes", False),
|
||||
)
|
||||
|
||||
def _display_results(self, tracks: List[Track], args: Dict[str, Any], logger: logging.Logger) -> None:
|
||||
"""
|
||||
Display the results of processing.
|
||||
|
||||
Args:
|
||||
tracks: The processed tracks
|
||||
args: The parsed command-line arguments
|
||||
logger: The logger
|
||||
"""
|
||||
# If prep-only mode, display detailed output
|
||||
if args.get("prep_only"):
|
||||
logger.info(f"Karaoke Prep complete! Output files:")
|
||||
|
||||
for track in tracks:
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {track.artist} - {track.title}")
|
||||
logger.info(f" Input Media: {track.input_media}")
|
||||
logger.info(f" Input WAV Audio: {track.input_audio_wav}")
|
||||
logger.info(f" Input Still Image: {track.input_still_image}")
|
||||
logger.info(f" Lyrics: {track.lyrics}")
|
||||
logger.info(f" Processed Lyrics: {track.processed_lyrics}")
|
||||
|
||||
logger.info(f" Separated Audio:")
|
||||
|
||||
# Clean Instrumental
|
||||
if track.separated_audio and "clean_instrumental" in track.separated_audio:
|
||||
logger.info(f" Clean Instrumental Model:")
|
||||
for stem_type, file_path in track.separated_audio["clean_instrumental"].items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Other Stems
|
||||
if track.separated_audio and "other_stems" in track.separated_audio:
|
||||
logger.info(f" Other Stems Models:")
|
||||
for model, stems in track.separated_audio["other_stems"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
for stem_type, file_path in stems.items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Backing Vocals
|
||||
if track.separated_audio and "backing_vocals" in track.separated_audio:
|
||||
logger.info(f" Backing Vocals Models:")
|
||||
for model, stems in track.separated_audio["backing_vocals"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
for stem_type, file_path in stems.items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Combined Instrumentals
|
||||
if track.separated_audio and "combined_instrumentals" in track.separated_audio:
|
||||
logger.info(f" Combined Instrumentals:")
|
||||
for model, file_path in track.separated_audio["combined_instrumentals"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
logger.info(f" Combined Instrumental: {file_path}")
|
||||
|
||||
logger.info("Preparation phase complete.")
|
||||
return
|
||||
|
||||
# For finalise-only or full workflow, display summary of outputs
|
||||
for track in tracks:
|
||||
logger.info(f"Karaoke processing complete! Output files:")
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {track.artist} - {track.title}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Working Files:")
|
||||
logger.info(f" Video With Vocals: {track.video_with_vocals}")
|
||||
logger.info(f" Video With Instrumental: {track.video_with_instrumental}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Final Videos:")
|
||||
logger.info(f" Lossless 4K MP4 (PCM): {track.final_video}")
|
||||
logger.info(f" Lossless 4K MKV (FLAC): {track.final_video_mkv}")
|
||||
logger.info(f" Lossy 4K MP4 (AAC): {track.final_video_lossy}")
|
||||
logger.info(f" Lossy 720p MP4 (AAC): {track.final_video_720p}")
|
||||
|
||||
if hasattr(track, "final_karaoke_cdg_zip") or hasattr(track, "final_karaoke_txt_zip"):
|
||||
logger.info(f"")
|
||||
logger.info(f"Karaoke Files:")
|
||||
|
||||
if hasattr(track, "final_karaoke_cdg_zip") and track.final_karaoke_cdg_zip:
|
||||
logger.info(f" CDG+MP3 ZIP: {track.final_karaoke_cdg_zip}")
|
||||
|
||||
if hasattr(track, "final_karaoke_txt_zip") and track.final_karaoke_txt_zip:
|
||||
logger.info(f" TXT+MP3 ZIP: {track.final_karaoke_txt_zip}")
|
||||
|
||||
if hasattr(track, "brand_code") and track.brand_code:
|
||||
logger.info(f"")
|
||||
logger.info(f"Organization:")
|
||||
logger.info(f" Brand Code: {track.brand_code}")
|
||||
logger.info(f" New Directory: {track.new_brand_code_dir_path}")
|
||||
|
||||
if (hasattr(track, "youtube_url") and track.youtube_url) or (hasattr(track, "brand_code_dir_sharing_link") and track.brand_code_dir_sharing_link):
|
||||
logger.info(f"")
|
||||
logger.info(f"Sharing:")
|
||||
|
||||
if hasattr(track, "brand_code_dir_sharing_link") and track.brand_code_dir_sharing_link:
|
||||
logger.info(f" Folder Link: {track.brand_code_dir_sharing_link}")
|
||||
try:
|
||||
time.sleep(1) # Brief pause between clipboard operations
|
||||
pyperclip.copy(track.brand_code_dir_sharing_link)
|
||||
logger.info(f" (Folder link copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy folder link to clipboard: {str(e)}")
|
||||
|
||||
if hasattr(track, "youtube_url") and track.youtube_url:
|
||||
logger.info(f" YouTube URL: {track.youtube_url}")
|
||||
try:
|
||||
pyperclip.copy(track.youtube_url)
|
||||
logger.info(f" (YouTube URL copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy YouTube URL to clipboard: {str(e)}")
|
||||
|
||||
|
||||
class TestEmailTemplateCommand(Command):
|
||||
"""Command for testing the email template."""
|
||||
|
||||
async def execute(self, args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Execute the test email template command.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
"""
|
||||
# Set up logging
|
||||
logger = logging.getLogger(__name__)
|
||||
log_handler = logging.StreamHandler()
|
||||
log_formatter = logging.Formatter(
|
||||
fmt="%(asctime)s.%(msecs)03d - %(levelname)s - %(module)s - %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
log_handler.setFormatter(log_formatter)
|
||||
logger.addHandler(log_handler)
|
||||
|
||||
log_level = getattr(logging, args.get("log_level", "INFO").upper())
|
||||
logger.setLevel(log_level)
|
||||
|
||||
logger.info("Testing email template functionality...")
|
||||
|
||||
# Create configuration
|
||||
config = ProjectConfig(
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
email_template_file=args.get("email_template_file"),
|
||||
)
|
||||
|
||||
# Create controller
|
||||
controller = KaraokeController(config)
|
||||
|
||||
# Test email template
|
||||
await controller.distribution_service._test_email_template()
|
||||
|
||||
|
||||
class BulkProcessCommand(Command):
|
||||
"""Command for bulk processing tracks."""
|
||||
|
||||
async def execute(self, args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Execute the bulk process command.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
"""
|
||||
# Execute the bulk CLI
|
||||
await bulk_async_main()
|
||||
|
||||
|
||||
def get_command(args: Dict[str, Any]) -> Command:
|
||||
"""
|
||||
Get the appropriate command based on the arguments.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
|
||||
Returns:
|
||||
The command to execute
|
||||
"""
|
||||
if args.get("test_email_template"):
|
||||
return TestEmailTemplateCommand()
|
||||
elif args.get("bulk"):
|
||||
return BulkProcessCommand()
|
||||
else:
|
||||
return ProcessCommand()
|
||||
|
||||
|
||||
async def execute_command(args: Dict[str, Any]) -> None:
|
||||
"""
|
||||
Execute the appropriate command based on the arguments.
|
||||
|
||||
Args:
|
||||
args: The parsed command-line arguments
|
||||
"""
|
||||
command = get_command(args)
|
||||
await command.execute(args)
|
||||
@@ -0,0 +1,287 @@
|
||||
import argparse
|
||||
import logging
|
||||
import pkg_resources
|
||||
import tempfile
|
||||
import os
|
||||
from typing import Dict, Any
|
||||
|
||||
|
||||
def create_parser() -> argparse.ArgumentParser:
|
||||
"""
|
||||
Create the command-line argument parser.
|
||||
|
||||
Returns:
|
||||
The argument parser
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video.",
|
||||
formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=54),
|
||||
)
|
||||
|
||||
# Basic information
|
||||
parser.add_argument(
|
||||
"args",
|
||||
nargs="*",
|
||||
help="[Media or playlist URL] [Artist] [Title] of song to process. If URL is provided, Artist and Title are optional but increase chance of fetching the correct lyrics. If Artist and Title are provided with no URL, the top YouTube search result will be fetched.",
|
||||
)
|
||||
|
||||
package_version = pkg_resources.get_distribution("karaoke-gen").version
|
||||
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {package_version}")
|
||||
|
||||
# Workflow control
|
||||
workflow_group = parser.add_argument_group("Workflow Control")
|
||||
workflow_group.add_argument(
|
||||
"--prep-only",
|
||||
action="store_true",
|
||||
help="Only run the preparation phase (download audio, lyrics, separate stems, create title screens). Example: --prep-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--finalise-only",
|
||||
action="store_true",
|
||||
help="Only run the finalisation phase (remux, encode, organize). Must be run in a directory prepared by the prep phase. Example: --finalise-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--bulk",
|
||||
action="store_true",
|
||||
help="Process multiple tracks in bulk from a CSV file. Example: --bulk",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--input_csv",
|
||||
help="Path to CSV file containing tracks to process when using --bulk. CSV should have columns: Artist,Title,Mixed Audio Filename,Instrumental Audio Filename,Status. Example: --input_csv=/path/to/tracks.csv",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-transcription",
|
||||
action="store_true",
|
||||
help="Skip automatic lyrics transcription/synchronization. Use this to fall back to manual syncing. Example: --skip-transcription",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-separation",
|
||||
action="store_true",
|
||||
help="Skip audio separation process. Example: --skip-separation",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-lyrics",
|
||||
action="store_true",
|
||||
help="Skip fetching and processing lyrics. Example: --skip-lyrics",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--lyrics-only",
|
||||
action="store_true",
|
||||
help="Only process lyrics, skipping audio separation and title/end screen generation. Example: --lyrics-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--edit-lyrics",
|
||||
action="store_true",
|
||||
help="Edit lyrics of an existing track. This will backup existing outputs, re-run the lyrics transcription process, and update all outputs. Example: --edit-lyrics",
|
||||
)
|
||||
|
||||
# Logging & Debugging
|
||||
debug_group = parser.add_argument_group("Logging & Debugging")
|
||||
debug_group.add_argument(
|
||||
"--log_level",
|
||||
default="info",
|
||||
help="Optional: logging level, e.g. info, debug, warning (default: %(default)s). Example: --log_level=debug",
|
||||
)
|
||||
debug_group.add_argument(
|
||||
"--dry_run",
|
||||
action="store_true",
|
||||
help="Optional: perform a dry run without making any changes. Example: --dry_run",
|
||||
)
|
||||
debug_group.add_argument(
|
||||
"--render_bounding_boxes",
|
||||
action="store_true",
|
||||
help="Optional: render bounding boxes around text regions for debugging. Example: --render_bounding_boxes",
|
||||
)
|
||||
|
||||
# Input/Output Configuration
|
||||
io_group = parser.add_argument_group("Input/Output Configuration")
|
||||
io_group.add_argument(
|
||||
"--filename_pattern",
|
||||
help="Required if processing a folder: Python regex pattern to extract track names from filenames. Must contain a named group 'title'. Example: --filename_pattern='(?P<index>\\d+) - (?P<title>.+).mp3'",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_dir",
|
||||
default=".",
|
||||
help="Optional: directory to write output files (default: <current dir>). Example: --output_dir=/app/karaoke",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--no_track_subfolders",
|
||||
action="store_false",
|
||||
dest="no_track_subfolders",
|
||||
help="Optional: do NOT create a named subfolder for each track. Example: --no_track_subfolders",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--lossless_output_format",
|
||||
default="FLAC",
|
||||
help="Optional: lossless output format for separated audio (default: FLAC). Example: --lossless_output_format=WAV",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_png",
|
||||
type=lambda x: (str(x).lower() == "true"),
|
||||
default=True,
|
||||
help="Optional: output PNG format for title and end images (default: %(default)s). Example: --output_png=False",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_jpg",
|
||||
type=lambda x: (str(x).lower() == "true"),
|
||||
default=True,
|
||||
help="Optional: output JPG format for title and end images (default: %(default)s). Example: --output_jpg=False",
|
||||
)
|
||||
|
||||
# Audio Processing Configuration
|
||||
audio_group = parser.add_argument_group("Audio Processing Configuration")
|
||||
audio_group.add_argument(
|
||||
"--clean_instrumental_model",
|
||||
default="model_bs_roformer_ep_317_sdr_12.9755.ckpt",
|
||||
help="Optional: Model for clean instrumental separation (default: %(default)s).",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--backing_vocals_models",
|
||||
nargs="+",
|
||||
default=["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"],
|
||||
help="Optional: List of models for backing vocals separation (default: %(default)s).",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--other_stems_models",
|
||||
nargs="+",
|
||||
default=["htdemucs_6s.yaml"],
|
||||
help="Optional: List of models for other stems separation (default: %(default)s).",
|
||||
)
|
||||
|
||||
default_model_dir_unix = "/tmp/audio-separator-models/"
|
||||
if os.name == "posix" and os.path.exists(default_model_dir_unix):
|
||||
default_model_dir = default_model_dir_unix
|
||||
else:
|
||||
# Use tempfile to get the platform-independent temp directory
|
||||
default_model_dir = os.path.join(tempfile.gettempdir(), "audio-separator-models")
|
||||
|
||||
audio_group.add_argument(
|
||||
"--model_file_dir",
|
||||
default=default_model_dir,
|
||||
help="Optional: model files directory (default: %(default)s). Example: --model_file_dir=/app/models",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--existing_instrumental",
|
||||
help="Optional: Path to an existing instrumental audio file. If provided, audio separation will be skipped.",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--instrumental_format",
|
||||
default="flac",
|
||||
help="Optional: format / file extension for instrumental track to use for remux (default: %(default)s). Example: --instrumental_format=mp3",
|
||||
)
|
||||
|
||||
# Lyrics Configuration
|
||||
lyrics_group = parser.add_argument_group("Lyrics Configuration")
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_artist",
|
||||
help="Optional: Override the artist name used for lyrics search. Example: --lyrics_artist='The Beatles'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_title",
|
||||
help="Optional: Override the song title used for lyrics search. Example: --lyrics_title='Hey Jude'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_file",
|
||||
help="Optional: Path to a file containing lyrics to use instead of fetching from online. Example: --lyrics_file='/path/to/lyrics.txt'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--subtitle_offset_ms",
|
||||
type=int,
|
||||
default=0,
|
||||
help="Optional: Adjust subtitle timing by N milliseconds (+ve delays, -ve advances). Example: --subtitle_offset_ms=500",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--skip_transcription_review",
|
||||
action="store_true",
|
||||
help="Optional: Skip the review step after transcription. Example: --skip_transcription_review",
|
||||
)
|
||||
|
||||
# Style Configuration
|
||||
style_group = parser.add_argument_group("Style Configuration")
|
||||
style_group.add_argument(
|
||||
"--style_params_json",
|
||||
help="Optional: Path to JSON file containing style configuration. Example: --style_params_json='/path/to/style_params.json'",
|
||||
)
|
||||
|
||||
# Finalisation Configuration
|
||||
finalise_group = parser.add_argument_group("Finalisation Configuration")
|
||||
finalise_group.add_argument(
|
||||
"--enable_cdg",
|
||||
action="store_true",
|
||||
help="Optional: Enable CDG ZIP generation during finalisation. Example: --enable_cdg",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--enable_txt",
|
||||
action="store_true",
|
||||
help="Optional: Enable TXT ZIP generation during finalisation. Example: --enable_txt",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--brand_prefix",
|
||||
help="Optional: Your brand prefix to calculate the next sequential number. Example: --brand_prefix=BRAND",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--organised_dir",
|
||||
help="Optional: Target directory where the processed folder will be moved. Example: --organised_dir='/path/to/Tracks-Organized'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--organised_dir_rclone_root",
|
||||
help="Optional: Rclone path which maps to your organised_dir. Example: --organised_dir_rclone_root='dropbox:Media/Karaoke/Tracks-Organized'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--public_share_dir",
|
||||
help="Optional: Public share directory for final files. Example: --public_share_dir='/path/to/Tracks-PublicShare'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--youtube_client_secrets_file",
|
||||
help="Optional: Path to youtube client secrets file. Example: --youtube_client_secrets_file='/path/to/client_secret.json'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--youtube_description_file",
|
||||
help="Optional: Path to youtube description template. Example: --youtube_description_file='/path/to/description.txt'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--rclone_destination",
|
||||
help="Optional: Rclone destination for public_share_dir sync. Example: --rclone_destination='googledrive:KaraokeFolder'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--discord_webhook_url",
|
||||
help="Optional: Discord webhook URL for notifications. Example: --discord_webhook_url='https://discord.com/api/webhooks/...'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--email_template_file",
|
||||
help="Optional: Path to email template file. Example: --email_template_file='/path/to/template.txt'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--keep-brand-code",
|
||||
action="store_true",
|
||||
help="Optional: Use existing brand code from current directory instead of generating new one. Example: --keep-brand-code",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"-y",
|
||||
"--yes",
|
||||
action="store_true",
|
||||
help="Optional: Run in non-interactive mode, assuming yes to all prompts. Example: -y",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--test_email_template",
|
||||
action="store_true",
|
||||
help="Optional: Test the email template functionality with fake data. Example: --test_email_template",
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def parse_args() -> Dict[str, Any]:
|
||||
"""
|
||||
Parse command-line arguments.
|
||||
|
||||
Returns:
|
||||
Dictionary of parsed arguments
|
||||
"""
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
# Convert args to dictionary
|
||||
args_dict = vars(args)
|
||||
|
||||
return args_dict
|
||||
@@ -0,0 +1,273 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from typing import List, Optional
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import KaraokeGenError
|
||||
|
||||
|
||||
class KaraokeController:
|
||||
"""
|
||||
Main controller for the karaoke generation process.
|
||||
This class orchestrates the entire workflow by delegating to specialized services.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the controller with the given configuration.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Services will be imported and initialized lazily to avoid circular imports
|
||||
self._audio_service = None
|
||||
self._lyrics_service = None
|
||||
self._media_service = None
|
||||
self._video_service = None
|
||||
self._distribution_service = None
|
||||
|
||||
@property
|
||||
def audio_service(self):
|
||||
"""Lazy-loaded audio service"""
|
||||
if self._audio_service is None:
|
||||
from karaoke_gen.services.audio import AudioService
|
||||
self._audio_service = AudioService(self.config)
|
||||
return self._audio_service
|
||||
|
||||
@property
|
||||
def lyrics_service(self):
|
||||
"""Lazy-loaded lyrics service"""
|
||||
if self._lyrics_service is None:
|
||||
from karaoke_gen.services.lyrics import LyricsService
|
||||
self._lyrics_service = LyricsService(self.config)
|
||||
return self._lyrics_service
|
||||
|
||||
@property
|
||||
def media_service(self):
|
||||
"""Lazy-loaded media service"""
|
||||
if self._media_service is None:
|
||||
from karaoke_gen.services.media import MediaService
|
||||
self._media_service = MediaService(self.config)
|
||||
return self._media_service
|
||||
|
||||
@property
|
||||
def video_service(self):
|
||||
"""Lazy-loaded video service"""
|
||||
if self._video_service is None:
|
||||
from karaoke_gen.services.video import VideoService
|
||||
self._video_service = VideoService(self.config)
|
||||
return self._video_service
|
||||
|
||||
@property
|
||||
def distribution_service(self):
|
||||
"""Lazy-loaded distribution service"""
|
||||
if self._distribution_service is None:
|
||||
from karaoke_gen.services.distribution.service import DistributionService
|
||||
self._distribution_service = DistributionService(self.config)
|
||||
return self._distribution_service
|
||||
|
||||
async def process_track(self, track: Track) -> Track:
|
||||
"""
|
||||
Process a single track through the entire workflow.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The processed track with updated information
|
||||
"""
|
||||
self.logger.info(f"Processing track: {track.base_name}")
|
||||
|
||||
try:
|
||||
# Setup output directory
|
||||
track = await self._setup_output_directory(track)
|
||||
|
||||
# Media acquisition and preparation
|
||||
if track.is_url:
|
||||
track = await self.media_service.download_media(track)
|
||||
elif track.is_file:
|
||||
track = await self.media_service.process_media(track)
|
||||
|
||||
# Skip further processing if we're only doing lyrics
|
||||
if self.config.lyrics_only:
|
||||
track = await self.lyrics_service.process_lyrics(track)
|
||||
return track
|
||||
|
||||
# Audio processing (if not skipped)
|
||||
if not self.config.skip_separation:
|
||||
track = await self.audio_service.separate_audio(track)
|
||||
|
||||
# Lyrics processing (if not skipped)
|
||||
if not self.config.skip_lyrics:
|
||||
track = await self.lyrics_service.process_lyrics(track)
|
||||
|
||||
# Video generation
|
||||
track = await self.video_service.process_video(track)
|
||||
|
||||
# Distribution (if not prep_only)
|
||||
if not self.config.prep_only:
|
||||
track = await self.distribution_service.distribute(track)
|
||||
|
||||
self.logger.info(f"Successfully processed track: {track.base_name}")
|
||||
return track
|
||||
|
||||
except KaraokeGenError as e:
|
||||
self.logger.error(f"Error processing track {track.base_name}: {str(e)}")
|
||||
raise
|
||||
|
||||
async def _setup_output_directory(self, track: Track) -> Track:
|
||||
"""
|
||||
Set up the output directory for the track.
|
||||
|
||||
Args:
|
||||
track: The track to set up the output directory for
|
||||
|
||||
Returns:
|
||||
The track with updated output directory information
|
||||
"""
|
||||
if self.config.create_track_subfolders and track.artist and track.title:
|
||||
# Create a subfolder for the track
|
||||
track_dir_name = f"{track.artist} - {track.title}"
|
||||
track_dir_name = self._sanitize_filename(track_dir_name)
|
||||
track_output_dir = os.path.join(self.config.output_dir, track_dir_name)
|
||||
|
||||
# Create the directory if it doesn't exist
|
||||
if not os.path.exists(track_output_dir) and not self.config.dry_run:
|
||||
os.makedirs(track_output_dir, exist_ok=True)
|
||||
self.logger.info(f"Created output directory: {track_output_dir}")
|
||||
else:
|
||||
# Use the output directory directly
|
||||
track_output_dir = self.config.output_dir
|
||||
|
||||
track.track_output_dir = track_output_dir
|
||||
return track
|
||||
|
||||
def _sanitize_filename(self, filename: str) -> str:
|
||||
"""
|
||||
Sanitize a filename by removing invalid characters.
|
||||
|
||||
Args:
|
||||
filename: The filename to sanitize
|
||||
|
||||
Returns:
|
||||
The sanitized filename
|
||||
"""
|
||||
# Replace characters that are invalid in filenames
|
||||
invalid_chars = ['<', '>', ':', '"', '/', '\\', '|', '?', '*']
|
||||
for char in invalid_chars:
|
||||
filename = filename.replace(char, '_')
|
||||
return filename
|
||||
|
||||
async def process_tracks(self, tracks: List[Track] = None) -> List[Track]:
|
||||
"""
|
||||
Process multiple tracks.
|
||||
|
||||
Args:
|
||||
tracks: List of tracks to process. If None, a track will be created from the config.
|
||||
|
||||
Returns:
|
||||
List of processed tracks
|
||||
"""
|
||||
if tracks is None:
|
||||
# Create a track from the configuration
|
||||
track = Track(
|
||||
artist=self.config.artist,
|
||||
title=self.config.title,
|
||||
input_media=self.config.input_media
|
||||
)
|
||||
tracks = [track]
|
||||
|
||||
processed_tracks = []
|
||||
for track in tracks:
|
||||
processed_track = await self.process_track(track)
|
||||
processed_tracks.append(processed_track)
|
||||
|
||||
return processed_tracks
|
||||
|
||||
async def process(self) -> List[Track]:
|
||||
"""
|
||||
Process tracks based on the configuration.
|
||||
This is the main entry point for the controller.
|
||||
|
||||
Returns:
|
||||
List of processed tracks
|
||||
"""
|
||||
# Handle edit lyrics mode
|
||||
if self.config.edit_lyrics:
|
||||
return await self._handle_edit_lyrics_mode()
|
||||
|
||||
# Handle finalise only mode
|
||||
if self.config.finalise_only:
|
||||
return await self._handle_finalise_only_mode()
|
||||
|
||||
# Normal processing
|
||||
return await self.process_tracks()
|
||||
|
||||
async def _handle_edit_lyrics_mode(self) -> List[Track]:
|
||||
"""
|
||||
Handle edit lyrics mode.
|
||||
|
||||
Returns:
|
||||
List of processed tracks
|
||||
"""
|
||||
self.logger.info("Running in edit-lyrics mode...")
|
||||
|
||||
# Get the current directory name to extract artist and title
|
||||
current_dir = os.path.basename(os.getcwd())
|
||||
self.logger.info(f"Current directory: {current_dir}")
|
||||
|
||||
# Extract artist and title from directory name
|
||||
if " - " not in current_dir:
|
||||
raise ValueError("Current directory name does not contain ' - ' separator. Cannot extract artist and title.")
|
||||
|
||||
parts = current_dir.split(" - ")
|
||||
if len(parts) == 2:
|
||||
artist, title = parts
|
||||
elif len(parts) >= 3:
|
||||
# Handle brand code format: "BRAND-XXXX - Artist - Title"
|
||||
artist = parts[1]
|
||||
title = " - ".join(parts[2:])
|
||||
else:
|
||||
raise ValueError(f"Could not parse artist and title from directory name: {current_dir}")
|
||||
|
||||
self.logger.info(f"Extracted artist: {artist}, title: {title}")
|
||||
|
||||
# Create a track
|
||||
track = Track(
|
||||
artist=artist,
|
||||
title=title,
|
||||
track_output_dir=os.getcwd()
|
||||
)
|
||||
|
||||
# Backup existing outputs and get the input audio file
|
||||
track = await self.lyrics_service.backup_and_prepare_for_edit(track)
|
||||
|
||||
# Process lyrics
|
||||
track = await self.lyrics_service.process_lyrics(track)
|
||||
|
||||
# Distribute
|
||||
track = await self.distribution_service.distribute(track, replace_existing=True)
|
||||
|
||||
return [track]
|
||||
|
||||
async def _handle_finalise_only_mode(self) -> List[Track]:
|
||||
"""
|
||||
Handle finalise only mode.
|
||||
|
||||
Returns:
|
||||
List of processed tracks
|
||||
"""
|
||||
self.logger.info("Running in finalise-only mode...")
|
||||
|
||||
# Create a track with the current directory
|
||||
track = Track(track_output_dir=os.getcwd())
|
||||
|
||||
# Distribute
|
||||
track = await self.distribution_service.distribute(track)
|
||||
|
||||
return [track]
|
||||
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Core module for the karaoke_gen package.
|
||||
|
||||
This module contains the core domain models and exceptions.
|
||||
"""
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import KaraokeGenError
|
||||
|
||||
__all__ = ["ProjectConfig", "Track", "KaraokeGenError"]
|
||||
@@ -0,0 +1,83 @@
|
||||
class KaraokeGenError(Exception):
|
||||
"""Base exception for all karaoke generator errors"""
|
||||
pass
|
||||
|
||||
|
||||
class MediaError(KaraokeGenError):
|
||||
"""Exception raised for errors related to media handling"""
|
||||
pass
|
||||
|
||||
|
||||
class DownloadError(MediaError):
|
||||
"""Exception raised when a download fails"""
|
||||
pass
|
||||
|
||||
|
||||
class ConversionError(MediaError):
|
||||
"""Exception raised when a media conversion fails"""
|
||||
pass
|
||||
|
||||
|
||||
class LyricsError(KaraokeGenError):
|
||||
"""Exception raised for errors related to lyrics processing"""
|
||||
pass
|
||||
|
||||
|
||||
class LyricsFetchError(LyricsError):
|
||||
"""Exception raised when lyrics fetching fails"""
|
||||
pass
|
||||
|
||||
|
||||
class TranscriptionError(LyricsError):
|
||||
"""Exception raised when lyrics transcription fails"""
|
||||
pass
|
||||
|
||||
|
||||
class SynchronizationError(LyricsError):
|
||||
"""Exception raised when lyrics synchronization fails"""
|
||||
pass
|
||||
|
||||
|
||||
class FormattingError(LyricsError):
|
||||
"""Exception raised when lyrics formatting fails"""
|
||||
pass
|
||||
|
||||
|
||||
class AudioError(KaraokeGenError):
|
||||
"""Exception raised for errors related to audio processing"""
|
||||
pass
|
||||
|
||||
|
||||
class SeparationError(AudioError):
|
||||
"""Exception raised when audio separation fails"""
|
||||
pass
|
||||
|
||||
|
||||
class NormalizationError(AudioError):
|
||||
"""Exception raised when audio normalization fails"""
|
||||
pass
|
||||
|
||||
|
||||
class VideoError(KaraokeGenError):
|
||||
"""Exception raised for errors related to video processing"""
|
||||
pass
|
||||
|
||||
|
||||
class RenderingError(VideoError):
|
||||
"""Exception raised when video rendering fails"""
|
||||
pass
|
||||
|
||||
|
||||
class DistributionError(KaraokeGenError):
|
||||
"""Exception raised for errors related to distribution"""
|
||||
pass
|
||||
|
||||
|
||||
class YouTubeError(DistributionError):
|
||||
"""Exception raised when YouTube operations fail"""
|
||||
pass
|
||||
|
||||
|
||||
class UserCancellationError(KaraokeGenError):
|
||||
"""Exception raised when the user cancels an operation"""
|
||||
pass
|
||||
@@ -0,0 +1,107 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, List, Optional, Any
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
||||
@dataclass
|
||||
class ProjectConfig:
|
||||
"""
|
||||
Configuration for a karaoke generation project.
|
||||
This class holds all the configuration parameters for the karaoke generation process.
|
||||
"""
|
||||
# Basic inputs
|
||||
input_media: Optional[str] = None
|
||||
artist: Optional[str] = None
|
||||
title: Optional[str] = None
|
||||
filename_pattern: Optional[str] = None
|
||||
|
||||
# Workflow control
|
||||
prep_only: bool = False
|
||||
finalise_only: bool = False
|
||||
skip_transcription: bool = False
|
||||
skip_separation: bool = False
|
||||
skip_lyrics: bool = False
|
||||
skip_download: bool = False
|
||||
lyrics_only: bool = False
|
||||
edit_lyrics: bool = False
|
||||
|
||||
# Logging & Debugging
|
||||
dry_run: bool = False
|
||||
logger: Optional[logging.Logger] = None
|
||||
log_level: int = logging.DEBUG
|
||||
log_formatter: Optional[logging.Formatter] = None
|
||||
render_bounding_boxes: bool = False
|
||||
|
||||
# Input/Output Configuration
|
||||
output_dir: str = "."
|
||||
create_track_subfolders: bool = True
|
||||
lossless_output_format: str = "flac"
|
||||
output_png: bool = True
|
||||
output_jpg: bool = True
|
||||
|
||||
# Audio Processing Configuration
|
||||
clean_instrumental_model: str = "model_bs_roformer_ep_317_sdr_12.9755.ckpt"
|
||||
backing_vocals_models: List[str] = field(default_factory=lambda: ["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"])
|
||||
other_stems_models: List[str] = field(default_factory=lambda: ["htdemucs_6s.yaml"])
|
||||
model_file_dir: str = field(default_factory=lambda: os.path.join(tempfile.gettempdir(), "audio-separator-models"))
|
||||
existing_instrumental: Optional[str] = None
|
||||
instrumental_format: str = "flac"
|
||||
|
||||
# Lyrics Configuration
|
||||
lyrics_artist: Optional[str] = None
|
||||
lyrics_title: Optional[str] = None
|
||||
lyrics_file: Optional[str] = None
|
||||
skip_transcription_review: bool = False
|
||||
render_video: bool = True
|
||||
subtitle_offset_ms: int = 0
|
||||
|
||||
# Style Configuration
|
||||
style_params_json: Optional[str] = None
|
||||
|
||||
# Video Configuration
|
||||
title_screen_duration: float = 5.0
|
||||
end_screen_duration: float = 5.0
|
||||
title_fade_in: float = 1.0
|
||||
title_fade_out: float = 1.0
|
||||
end_fade_in: float = 1.0
|
||||
end_fade_out: float = 1.0
|
||||
|
||||
# Finalisation Configuration
|
||||
enable_cdg: bool = False
|
||||
enable_txt: bool = False
|
||||
brand_prefix: Optional[str] = None
|
||||
organised_dir: Optional[str] = None
|
||||
organised_dir_rclone_root: Optional[str] = None
|
||||
public_share_dir: Optional[str] = None
|
||||
youtube_client_secrets_file: Optional[str] = None
|
||||
youtube_description_file: Optional[str] = None
|
||||
rclone_destination: Optional[str] = None
|
||||
discord_webhook_url: Optional[str] = None
|
||||
email_template_file: Optional[str] = None
|
||||
cdg_styles: Optional[Dict[str, Any]] = None
|
||||
keep_brand_code: bool = False
|
||||
non_interactive: bool = False
|
||||
|
||||
def __post_init__(self):
|
||||
"""Perform post-initialization setup"""
|
||||
# Set up logger if not provided
|
||||
if self.logger is None:
|
||||
self.logger = logging.getLogger("karaoke_gen")
|
||||
handler = logging.StreamHandler()
|
||||
if self.log_formatter is None:
|
||||
self.log_formatter = logging.Formatter(
|
||||
fmt="%(asctime)s.%(msecs)03d - %(levelname)s - %(module)s - %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
handler.setFormatter(self.log_formatter)
|
||||
self.logger.addHandler(handler)
|
||||
self.logger.setLevel(self.log_level)
|
||||
|
||||
# If lyrics_artist/title not specified, use the main artist/title
|
||||
if self.lyrics_artist is None and self.artist is not None:
|
||||
self.lyrics_artist = self.artist
|
||||
|
||||
if self.lyrics_title is None and self.title is not None:
|
||||
self.lyrics_title = self.title
|
||||
@@ -0,0 +1,116 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, List, Optional, Any
|
||||
import os
|
||||
|
||||
|
||||
@dataclass
|
||||
class Track:
|
||||
"""
|
||||
Represents a track being processed through the karaoke generation pipeline.
|
||||
This class holds all the data related to a single track throughout its lifecycle.
|
||||
"""
|
||||
# Basic track information
|
||||
artist: Optional[str] = None
|
||||
title: Optional[str] = None
|
||||
input_media: Optional[str] = None
|
||||
|
||||
# Media source information
|
||||
extractor: Optional[str] = "Original" # Default to "Original" for local files
|
||||
media_id: Optional[str] = None
|
||||
|
||||
# Paths to generated files
|
||||
track_output_dir: Optional[str] = None
|
||||
input_audio_wav: Optional[str] = None
|
||||
input_still_image: Optional[str] = None
|
||||
|
||||
# Lyrics information
|
||||
lyrics: Optional[str] = None
|
||||
processed_lyrics: Optional[str] = None
|
||||
|
||||
# Separated audio files
|
||||
separated_audio: Dict[str, Any] = field(default_factory=lambda: {
|
||||
"clean_instrumental": {},
|
||||
"other_stems": {},
|
||||
"backing_vocals": {},
|
||||
"combined_instrumentals": {}
|
||||
})
|
||||
|
||||
# Video files
|
||||
title_video: Optional[str] = None
|
||||
end_video: Optional[str] = None
|
||||
video_with_lyrics: Optional[str] = None
|
||||
video_with_instrumental: Optional[str] = None
|
||||
|
||||
# Final output files
|
||||
final_video: Optional[str] = None
|
||||
final_video_mkv: Optional[str] = None
|
||||
final_video_lossy: Optional[str] = None
|
||||
final_video_720p: Optional[str] = None
|
||||
final_karaoke_cdg_zip: Optional[str] = None
|
||||
final_karaoke_txt_zip: Optional[str] = None
|
||||
|
||||
# Distribution information
|
||||
brand_code: Optional[str] = None
|
||||
new_brand_code_dir_path: Optional[str] = None
|
||||
youtube_url: Optional[str] = None
|
||||
brand_code_dir_sharing_link: Optional[str] = None
|
||||
|
||||
# Metadata
|
||||
metadata: Dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
@property
|
||||
def base_name(self) -> str:
|
||||
"""Returns the base name for the track (artist - title)"""
|
||||
if self.artist and self.title:
|
||||
return f"{self.artist} - {self.title}"
|
||||
return os.path.basename(self.input_media) if self.input_media else "unknown"
|
||||
|
||||
@property
|
||||
def is_url(self) -> bool:
|
||||
"""Returns True if the input_media is a URL"""
|
||||
if not self.input_media:
|
||||
return False
|
||||
return self.input_media.startswith("http://") or self.input_media.startswith("https://")
|
||||
|
||||
@property
|
||||
def is_file(self) -> bool:
|
||||
"""Returns True if the input_media is a file"""
|
||||
if not self.input_media:
|
||||
return False
|
||||
return os.path.isfile(self.input_media)
|
||||
|
||||
@property
|
||||
def is_directory(self) -> bool:
|
||||
"""Returns True if the input_media is a directory"""
|
||||
if not self.input_media:
|
||||
return False
|
||||
return os.path.isdir(self.input_media)
|
||||
|
||||
@property
|
||||
def instrumental(self) -> Optional[str]:
|
||||
"""Returns the path to the instrumental audio file"""
|
||||
if self.separated_audio and "clean_instrumental" in self.separated_audio:
|
||||
return self.separated_audio["clean_instrumental"].get("instrumental")
|
||||
return None
|
||||
|
||||
@property
|
||||
def duration(self) -> float:
|
||||
"""Returns the duration of the track in seconds"""
|
||||
if self.metadata and "duration" in self.metadata:
|
||||
return self.metadata["duration"]
|
||||
return 0.0
|
||||
|
||||
@property
|
||||
def audio_file(self) -> Optional[str]:
|
||||
"""Returns the path to the input audio file (WAV)"""
|
||||
return self.input_audio_wav
|
||||
|
||||
@property
|
||||
def wav_file(self) -> Optional[str]:
|
||||
"""Alias for input_audio_wav"""
|
||||
return self.input_audio_wav
|
||||
|
||||
@property
|
||||
def video_with_vocals(self) -> Optional[str]:
|
||||
"""Alias for video_with_lyrics for backward compatibility"""
|
||||
return self.video_with_lyrics
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,24 @@
|
||||
"""
|
||||
Services module for the karaoke_gen package.
|
||||
|
||||
This module contains the various services used by the karaoke generator.
|
||||
"""
|
||||
|
||||
# Import and re-export service modules
|
||||
from karaoke_gen.services.audio import AudioService
|
||||
from karaoke_gen.services.lyrics import LyricsService
|
||||
from karaoke_gen.services.media import MediaService
|
||||
from karaoke_gen.services.video import VideoService
|
||||
from karaoke_gen.services.distribution import DistributionService
|
||||
|
||||
# Import main service
|
||||
from karaoke_gen.services.main import MainService
|
||||
|
||||
__all__ = [
|
||||
"MainService",
|
||||
"AudioService",
|
||||
"LyricsService",
|
||||
"MediaService",
|
||||
"VideoService",
|
||||
"DistributionService",
|
||||
]
|
||||
@@ -0,0 +1,5 @@
|
||||
from karaoke_gen.services.audio.service import AudioService
|
||||
from karaoke_gen.services.audio.converter import AudioConverter
|
||||
from karaoke_gen.services.audio.separator import AudioSeparator
|
||||
from karaoke_gen.services.audio.normalizer import AudioNormalizer
|
||||
from karaoke_gen.services.audio.mixer import AudioMixer
|
||||
@@ -0,0 +1,91 @@
|
||||
import os
|
||||
import subprocess
|
||||
import asyncio
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import AudioError
|
||||
|
||||
|
||||
class AudioConverter:
|
||||
"""
|
||||
Handles audio format conversion operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the audio converter.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
async def convert_to_wav(self, track):
|
||||
"""
|
||||
Convert the input audio to WAV format.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Converting audio to WAV for {track.base_name}")
|
||||
|
||||
# Determine input file
|
||||
input_file = track.input_media
|
||||
if not os.path.isfile(input_file):
|
||||
raise AudioError(f"Input file not found: {input_file}")
|
||||
|
||||
# Determine output file
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name}"
|
||||
)
|
||||
output_wav = f"{output_filename_no_extension}.wav"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_wav):
|
||||
self.logger.info(f"WAV file already exists: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
return track
|
||||
|
||||
# Build ffmpeg command
|
||||
command = f'{self.ffmpeg_base_command} -i "{input_file}" -vn -acodec pcm_s16le -ar 44100 -ac 2 "{output_wav}"'
|
||||
|
||||
# Execute command
|
||||
if not self.config.dry_run:
|
||||
self.logger.debug(f"Executing command: {command}")
|
||||
try:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise AudioError(f"Failed to convert audio to WAV: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully converted audio to WAV: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
except Exception as e:
|
||||
raise AudioError(f"Failed to convert audio to WAV: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would convert audio to WAV: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
return track
|
||||
@@ -0,0 +1,283 @@
|
||||
import os
|
||||
import asyncio
|
||||
import subprocess
|
||||
from typing import List, Optional
|
||||
from pydub import AudioSegment
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import AudioError
|
||||
|
||||
|
||||
class AudioMixer:
|
||||
"""
|
||||
Handles audio mixing operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the audio mixer.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = "ffmpeg -hide_banner"
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
async def mix_audio_files(self, input_files: List[str], output_file: str, weights: Optional[List[float]] = None):
|
||||
"""
|
||||
Mix multiple audio files into a single output file.
|
||||
|
||||
Args:
|
||||
input_files: List of input audio file paths
|
||||
output_file: Output file path
|
||||
weights: Optional list of weights for each input file (default: equal weights)
|
||||
|
||||
Returns:
|
||||
The path to the mixed audio file
|
||||
"""
|
||||
self.logger.info(f"Mixing {len(input_files)} audio files into {output_file}")
|
||||
|
||||
# Validate inputs
|
||||
if not input_files:
|
||||
raise AudioError("No input files provided for mixing")
|
||||
|
||||
for input_file in input_files:
|
||||
if not os.path.isfile(input_file):
|
||||
raise AudioError(f"Input file not found: {input_file}")
|
||||
|
||||
# Set default weights if not provided
|
||||
if weights is None:
|
||||
weights = [1.0] * len(input_files)
|
||||
|
||||
# Ensure weights match input files
|
||||
if len(weights) != len(input_files):
|
||||
raise AudioError(f"Number of weights ({len(weights)}) does not match number of input files ({len(input_files)})")
|
||||
|
||||
# Build ffmpeg command
|
||||
input_args = " ".join([f'-i "{input_file}"' for input_file in input_files])
|
||||
weight_str = " ".join([str(w) for w in weights])
|
||||
|
||||
filter_complex = f'"'
|
||||
for i in range(len(input_files)):
|
||||
filter_complex += f"[{i}:a]"
|
||||
filter_complex += f"amix=inputs={len(input_files)}:duration=longest:weights={weight_str}[outa]"
|
||||
filter_complex += f'"'
|
||||
|
||||
output_format = os.path.splitext(output_file)[1][1:].lower()
|
||||
if not output_format:
|
||||
output_format = self.config.lossless_output_format.lower()
|
||||
|
||||
ffmpeg_command = (
|
||||
f'{self.ffmpeg_base_command} {input_args} '
|
||||
f'-filter_complex {filter_complex} '
|
||||
f'-map "[outa]" -c:a {output_format} "{output_file}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
if not self.config.dry_run:
|
||||
self.logger.debug(f"Running command: {ffmpeg_command}")
|
||||
|
||||
try:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
ffmpeg_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise AudioError(f"Failed to mix audio files: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully mixed audio files to {output_file}")
|
||||
return output_file
|
||||
|
||||
except Exception as e:
|
||||
raise AudioError(f"Error mixing audio files: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would mix audio files to {output_file}")
|
||||
return output_file
|
||||
|
||||
async def mix_audio(self, track):
|
||||
"""
|
||||
Mix audio for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated mixed audio information
|
||||
"""
|
||||
self.logger.info(f"Mixing audio for {track.base_name}")
|
||||
|
||||
# Skip if no separated audio
|
||||
if not track.separated_audio["clean_instrumental"].get("instrumental"):
|
||||
self.logger.info("No instrumental available for mixing, skipping")
|
||||
return track
|
||||
|
||||
# Mix instrumental with backing vocals if available
|
||||
if track.separated_audio["backing_vocals"]:
|
||||
for model, paths in track.separated_audio["backing_vocals"].items():
|
||||
if "backing_vocals" not in paths:
|
||||
continue
|
||||
|
||||
instrumental_path = track.separated_audio["clean_instrumental"]["instrumental"]
|
||||
backing_vocals_path = paths["backing_vocals"]
|
||||
|
||||
output_path = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Karaoke Mix {model}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Mixed audio for model {model} already exists")
|
||||
track.metadata[f"karaoke_mix_{model}"] = output_path
|
||||
continue
|
||||
|
||||
# Mix files
|
||||
try:
|
||||
mixed_path = await self.mix_audio_files(
|
||||
[instrumental_path, backing_vocals_path],
|
||||
output_path,
|
||||
weights=[1.0, 0.8] # Slightly reduce backing vocals volume
|
||||
)
|
||||
|
||||
track.metadata[f"karaoke_mix_{model}"] = mixed_path
|
||||
self.logger.info(f"Created karaoke mix for model {model}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create karaoke mix for model {model}: {str(e)}")
|
||||
|
||||
return track
|
||||
|
||||
async def generate_combined_instrumentals(self, track, stems_dir):
|
||||
"""
|
||||
Generate combined instrumental tracks by mixing different stems.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
stems_dir: The directory containing stems
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Generating combined instrumentals for {track.base_name}")
|
||||
|
||||
# Skip if no clean instrumental
|
||||
if not track.separated_audio.get("clean_instrumental", {}).get("instrumental"):
|
||||
self.logger.info("No clean instrumental available, skipping combined instrumentals")
|
||||
track.separated_audio["combined_instrumentals"] = {}
|
||||
return track
|
||||
|
||||
# Initialize combined instrumentals
|
||||
track.separated_audio["combined_instrumentals"] = {}
|
||||
|
||||
# Get clean instrumental path
|
||||
instrumental_path = track.separated_audio["clean_instrumental"]["instrumental"]
|
||||
|
||||
# Get backing vocals path if available
|
||||
backing_vocals_path = None
|
||||
for model_name, stems in track.separated_audio.get("backing_vocals", {}).items():
|
||||
if stems.get("backing_vocals"):
|
||||
backing_vocals_path = stems["backing_vocals"]
|
||||
break
|
||||
|
||||
# Generate instrumental with backing vocals if available
|
||||
if backing_vocals_path:
|
||||
output_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{track.base_name} (Instrumental with Backing Vocals).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Instrumental with backing vocals already exists: {output_path}")
|
||||
track.separated_audio["combined_instrumentals"]["instrumental_with_backing_vocals"] = output_path
|
||||
else:
|
||||
# Mix instrumental and backing vocals
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
await self._mix_audio_files(
|
||||
[instrumental_path, backing_vocals_path],
|
||||
output_path
|
||||
)
|
||||
track.separated_audio["combined_instrumentals"]["instrumental_with_backing_vocals"] = output_path
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to mix instrumental with backing vocals: {str(e)}")
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would mix instrumental with backing vocals: {output_path}")
|
||||
track.separated_audio["combined_instrumentals"]["instrumental_with_backing_vocals"] = output_path
|
||||
|
||||
# Generate other combined instrumentals from demucs stems if available
|
||||
demucs_stems = {}
|
||||
for model_name, stems in track.separated_audio.get("other_stems", {}).items():
|
||||
if "demucs" in model_name.lower():
|
||||
demucs_stems = stems
|
||||
break
|
||||
|
||||
if demucs_stems:
|
||||
# Mix drums + bass + other (no vocals)
|
||||
if all(stem in demucs_stems for stem in ["drums", "bass", "other"]):
|
||||
output_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{track.base_name} (Demucs Instrumental).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Demucs instrumental already exists: {output_path}")
|
||||
track.separated_audio["combined_instrumentals"]["demucs_instrumental"] = output_path
|
||||
else:
|
||||
# Mix drums, bass, and other
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
await self._mix_audio_files(
|
||||
[demucs_stems["drums"], demucs_stems["bass"], demucs_stems["other"]],
|
||||
output_path
|
||||
)
|
||||
track.separated_audio["combined_instrumentals"]["demucs_instrumental"] = output_path
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to mix demucs instrumental: {str(e)}")
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would mix demucs instrumental: {output_path}")
|
||||
track.separated_audio["combined_instrumentals"]["demucs_instrumental"] = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def _mix_audio_files(self, input_paths, output_path):
|
||||
"""
|
||||
Mix multiple audio files together.
|
||||
|
||||
Args:
|
||||
input_paths: List of input audio file paths
|
||||
output_path: Output audio file path
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Load first audio file
|
||||
mixed = AudioSegment.from_file(input_paths[0])
|
||||
|
||||
# Mix in additional audio files
|
||||
for path in input_paths[1:]:
|
||||
audio = AudioSegment.from_file(path)
|
||||
mixed = mixed.overlay(audio)
|
||||
|
||||
# Export mixed audio
|
||||
mixed.export(output_path, format=os.path.splitext(output_path)[1][1:])
|
||||
|
||||
self.logger.info(f"Successfully mixed audio files: {output_path}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to mix audio files: {str(e)}")
|
||||
raise AudioError(f"Failed to mix audio files: {str(e)}") from e
|
||||
@@ -0,0 +1,308 @@
|
||||
import os
|
||||
import asyncio
|
||||
import subprocess
|
||||
from pydub import AudioSegment
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import AudioError
|
||||
|
||||
|
||||
class AudioNormalizer:
|
||||
"""
|
||||
Handles audio normalization operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the audio normalizer.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
async def normalize_audio_file(self, input_path, output_path, target_level=0.0):
|
||||
"""
|
||||
Normalize an audio file to a target level.
|
||||
|
||||
Args:
|
||||
input_path: The input audio file path
|
||||
output_path: The output audio file path
|
||||
target_level: The target level in dB (default: 0.0)
|
||||
|
||||
Returns:
|
||||
The path to the normalized audio file
|
||||
"""
|
||||
self.logger.info(f"Normalizing audio file: {input_path}")
|
||||
|
||||
# Validate input
|
||||
if not os.path.isfile(input_path):
|
||||
raise AudioError(f"Input file not found: {input_path}")
|
||||
|
||||
if os.path.getsize(input_path) == 0:
|
||||
raise AudioError(f"Input file is empty: {input_path}")
|
||||
|
||||
# Skip if dry run
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"[DRY RUN] Would normalize audio file: {input_path}")
|
||||
return output_path
|
||||
|
||||
try:
|
||||
# Load audio file
|
||||
audio = AudioSegment.from_file(input_path)
|
||||
|
||||
# Calculate the peak amplitude
|
||||
peak_amplitude = float(audio.max_dBFS)
|
||||
|
||||
# Calculate the necessary gain
|
||||
gain_db = target_level - peak_amplitude
|
||||
|
||||
# Apply gain
|
||||
normalized_audio = audio.apply_gain(gain_db)
|
||||
|
||||
# Ensure the audio is not completely silent
|
||||
if normalized_audio.rms == 0:
|
||||
self.logger.warning(f"Normalized audio is silent for {input_path}. Using original audio.")
|
||||
normalized_audio = audio
|
||||
|
||||
# Export normalized audio
|
||||
normalized_audio.export(
|
||||
output_path,
|
||||
format=self.config.lossless_output_format.lower()
|
||||
)
|
||||
|
||||
self.logger.info(f"Normalized audio saved to: {output_path}")
|
||||
self.logger.debug(f"Original peak: {peak_amplitude} dB, Applied gain: {gain_db} dB")
|
||||
|
||||
return output_path
|
||||
|
||||
except Exception as e:
|
||||
raise AudioError(f"Failed to normalize audio file: {str(e)}") from e
|
||||
|
||||
async def normalize_audio(self, track):
|
||||
"""
|
||||
Normalize audio for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with normalized audio
|
||||
"""
|
||||
self.logger.info(f"Normalizing audio for {track.base_name}")
|
||||
|
||||
files_to_normalize = []
|
||||
|
||||
# Add clean instrumental
|
||||
if track.separated_audio["clean_instrumental"].get("instrumental"):
|
||||
files_to_normalize.append(
|
||||
("clean_instrumental", track.separated_audio["clean_instrumental"]["instrumental"])
|
||||
)
|
||||
|
||||
# Add combined instrumentals
|
||||
for model, path in track.separated_audio["combined_instrumentals"].items():
|
||||
files_to_normalize.append(("combined_instrumentals", path))
|
||||
|
||||
# Add karaoke mixes
|
||||
for key, path in track.metadata.items():
|
||||
if key.startswith("karaoke_mix_") and os.path.isfile(path):
|
||||
files_to_normalize.append(("karaoke_mix", path))
|
||||
|
||||
# Skip if no files to normalize
|
||||
if not files_to_normalize:
|
||||
self.logger.info("No files to normalize, skipping")
|
||||
return track
|
||||
|
||||
# Normalize each file
|
||||
for key, file_path in files_to_normalize:
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
# Normalize in-place
|
||||
await self.normalize_audio_file(file_path, file_path)
|
||||
|
||||
# Verify the normalized file
|
||||
if os.path.getsize(file_path) > 0:
|
||||
self.logger.info(f"Successfully normalized: {file_path}")
|
||||
else:
|
||||
raise AudioError("Normalized file is empty")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error during normalization of {file_path}: {e}")
|
||||
self.logger.warning(f"Normalization failed for {file_path}. Original file remains unchanged.")
|
||||
else:
|
||||
self.logger.warning(f"File not found for normalization: {file_path}")
|
||||
|
||||
self.logger.info("Audio normalization process completed")
|
||||
return track
|
||||
|
||||
async def normalize_audio_files(self, track):
|
||||
"""
|
||||
Normalize all separated audio files.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Normalizing audio files for {track.base_name}")
|
||||
|
||||
# Skip if no separated audio
|
||||
if not track.separated_audio:
|
||||
self.logger.info("No separated audio to normalize")
|
||||
return track
|
||||
|
||||
# Normalize clean instrumental
|
||||
if track.separated_audio.get("clean_instrumental"):
|
||||
instrumental_path = track.separated_audio["clean_instrumental"].get("instrumental")
|
||||
if instrumental_path and os.path.isfile(instrumental_path):
|
||||
normalized_path = self._get_normalized_path(instrumental_path)
|
||||
await self._normalize_audio(instrumental_path, normalized_path)
|
||||
track.separated_audio["clean_instrumental"]["instrumental"] = normalized_path
|
||||
|
||||
vocals_path = track.separated_audio["clean_instrumental"].get("vocals")
|
||||
if vocals_path and os.path.isfile(vocals_path):
|
||||
normalized_path = self._get_normalized_path(vocals_path)
|
||||
await self._normalize_audio(vocals_path, normalized_path)
|
||||
track.separated_audio["clean_instrumental"]["vocals"] = normalized_path
|
||||
|
||||
# Normalize backing vocals
|
||||
for model_name, stems in track.separated_audio.get("backing_vocals", {}).items():
|
||||
lead_vocals_path = stems.get("lead_vocals")
|
||||
if lead_vocals_path and os.path.isfile(lead_vocals_path):
|
||||
normalized_path = self._get_normalized_path(lead_vocals_path)
|
||||
await self._normalize_audio(lead_vocals_path, normalized_path)
|
||||
track.separated_audio["backing_vocals"][model_name]["lead_vocals"] = normalized_path
|
||||
|
||||
backing_vocals_path = stems.get("backing_vocals")
|
||||
if backing_vocals_path and os.path.isfile(backing_vocals_path):
|
||||
normalized_path = self._get_normalized_path(backing_vocals_path)
|
||||
await self._normalize_audio(backing_vocals_path, normalized_path)
|
||||
track.separated_audio["backing_vocals"][model_name]["backing_vocals"] = normalized_path
|
||||
|
||||
# Normalize other stems
|
||||
for model_name, stems in track.separated_audio.get("other_stems", {}).items():
|
||||
for stem_name, stem_path in stems.items():
|
||||
if stem_path and os.path.isfile(stem_path):
|
||||
normalized_path = self._get_normalized_path(stem_path)
|
||||
await self._normalize_audio(stem_path, normalized_path)
|
||||
track.separated_audio["other_stems"][model_name][stem_name] = normalized_path
|
||||
|
||||
# Normalize combined instrumentals
|
||||
for name, path in track.separated_audio.get("combined_instrumentals", {}).items():
|
||||
if path and os.path.isfile(path):
|
||||
normalized_path = self._get_normalized_path(path)
|
||||
await self._normalize_audio(path, normalized_path)
|
||||
track.separated_audio["combined_instrumentals"][name] = normalized_path
|
||||
|
||||
return track
|
||||
|
||||
def _get_normalized_path(self, input_path):
|
||||
"""
|
||||
Get the path for the normalized audio file.
|
||||
|
||||
Args:
|
||||
input_path: The input audio file path
|
||||
|
||||
Returns:
|
||||
The path for the normalized audio file
|
||||
"""
|
||||
# Replace extension with .normalized.ext
|
||||
base, ext = os.path.splitext(input_path)
|
||||
return f"{base}.normalized{ext}"
|
||||
|
||||
async def _normalize_audio(self, input_path, output_path, target_level=-14.0):
|
||||
"""
|
||||
Normalize an audio file to a target loudness level.
|
||||
|
||||
Args:
|
||||
input_path: The input audio file path
|
||||
output_path: The output audio file path
|
||||
target_level: The target loudness level in LUFS
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.debug(f"Normalized audio already exists: {output_path}")
|
||||
return True
|
||||
|
||||
# Skip if input doesn't exist
|
||||
if not os.path.isfile(input_path):
|
||||
self.logger.warning(f"Input audio file not found: {input_path}")
|
||||
return False
|
||||
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{input_path}" '
|
||||
f'-af loudnorm=I={target_level}:TP=-1.0:LRA=11.0:print_format=json '
|
||||
f'-f null -'
|
||||
)
|
||||
|
||||
# Execute command to get loudness stats
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
self.logger.debug(f"Analyzing audio loudness: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
self.logger.error(f"Failed to analyze audio loudness: {stderr.decode()}")
|
||||
return False
|
||||
|
||||
# Extract loudnorm stats from stderr
|
||||
stderr_text = stderr.decode()
|
||||
stats_start = stderr_text.rfind("{")
|
||||
stats_end = stderr_text.rfind("}") + 1
|
||||
|
||||
if stats_start >= 0 and stats_end > stats_start:
|
||||
loudness_stats = stderr_text[stats_start:stats_end]
|
||||
|
||||
# Build second pass command with measured stats
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{input_path}" '
|
||||
f'-af loudnorm=I={target_level}:TP=-1.0:LRA=11.0:measured_I={target_level}:measured_TP=-1.0:measured_LRA=11.0:measured_thresh=-25.0:offset=0.0:linear=true:print_format=json '
|
||||
f'"{output_path}"'
|
||||
)
|
||||
|
||||
# Execute second pass command
|
||||
self.logger.debug(f"Normalizing audio: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
self.logger.error(f"Failed to normalize audio: {stderr.decode()}")
|
||||
return False
|
||||
|
||||
self.logger.info(f"Successfully normalized audio: {output_path}")
|
||||
return True
|
||||
else:
|
||||
self.logger.error("Failed to extract loudness stats from ffmpeg output")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to normalize audio: {str(e)}")
|
||||
return False
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would normalize audio: {output_path}")
|
||||
return True
|
||||
@@ -0,0 +1,724 @@
|
||||
import os
|
||||
import asyncio
|
||||
import json
|
||||
import time
|
||||
import fcntl
|
||||
import errno
|
||||
import tempfile
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import AudioError
|
||||
import platform
|
||||
import subprocess
|
||||
import logging
|
||||
from typing import Dict, List, Optional, Any
|
||||
import re
|
||||
|
||||
|
||||
class AudioSeparator:
|
||||
"""
|
||||
Handles audio stem separation operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the audio separator.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Initialize separator lazily to avoid circular imports
|
||||
self._separator = None
|
||||
|
||||
@property
|
||||
def separator(self):
|
||||
"""Lazy-loaded separator instance"""
|
||||
if self._separator is None:
|
||||
# Import here to avoid circular imports
|
||||
from audio_separator.separator import Separator
|
||||
|
||||
self._separator = Separator(
|
||||
log_level=self.config.log_level,
|
||||
log_formatter=self.config.log_formatter,
|
||||
model_file_dir=self.config.model_file_dir,
|
||||
output_format=self.config.lossless_output_format,
|
||||
)
|
||||
|
||||
return self._separator
|
||||
|
||||
async def separate_clean_instrumental(self, track, input_audio, stems_dir):
|
||||
"""
|
||||
Separate clean instrumental from a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
input_audio: The input audio file
|
||||
stems_dir: The directory to store stems
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Separating clean instrumental for {track.base_name}")
|
||||
|
||||
# Skip if existing instrumental is provided
|
||||
if self.config.existing_instrumental:
|
||||
self.logger.info(f"Using existing instrumental: {self.config.existing_instrumental}")
|
||||
track.separated_audio["clean_instrumental"] = {
|
||||
"instrumental": self.config.existing_instrumental,
|
||||
"vocals": None
|
||||
}
|
||||
return track
|
||||
|
||||
# Acquire lock for audio separation
|
||||
with self._acquire_lock(track.base_name):
|
||||
artist_title = track.base_name
|
||||
|
||||
# Define output paths
|
||||
instrumental_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} (Clean Instrumental).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
vocals_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} (Clean Vocals).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(instrumental_path) and os.path.isfile(vocals_path):
|
||||
self.logger.info(f"Clean instrumental and vocals already exist")
|
||||
track.separated_audio["clean_instrumental"] = {
|
||||
"instrumental": instrumental_path,
|
||||
"vocals": vocals_path
|
||||
}
|
||||
return track
|
||||
|
||||
# Perform separation
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
self.logger.info(f"Separating clean instrumental using model: {self.config.clean_instrumental_model}")
|
||||
|
||||
# Load model first
|
||||
self.separator.load_model(model_filename=self.config.clean_instrumental_model)
|
||||
|
||||
# Convert input_audio to absolute path
|
||||
input_audio_abs = os.path.abspath(input_audio)
|
||||
|
||||
# Call separate with the absolute path to the audio file
|
||||
output_files = self.separator.separate(input_audio_abs)
|
||||
|
||||
# Process the output files
|
||||
result = {}
|
||||
for file in output_files:
|
||||
# The file path returned by separator.separate()
|
||||
# may already be the full path or just the filename
|
||||
file_name = os.path.basename(file)
|
||||
file_path = file # Use the path as returned by separator
|
||||
|
||||
if "(Vocals)" in file_name:
|
||||
if os.path.exists(file_path) and not os.path.exists(vocals_path):
|
||||
shutil.move(file_path, vocals_path)
|
||||
result["vocals"] = vocals_path
|
||||
elif "(Instrumental)" in file_name:
|
||||
if os.path.exists(file_path) and not os.path.exists(instrumental_path):
|
||||
shutil.move(file_path, instrumental_path)
|
||||
result["instrumental"] = instrumental_path
|
||||
|
||||
# Update track with separation results
|
||||
track.separated_audio["clean_instrumental"] = result
|
||||
|
||||
self.logger.info(f"Successfully separated clean instrumental")
|
||||
|
||||
except Exception as e:
|
||||
raise AudioError(f"Failed to separate clean instrumental: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would separate clean instrumental")
|
||||
track.separated_audio["clean_instrumental"] = {
|
||||
"instrumental": instrumental_path,
|
||||
"vocals": vocals_path
|
||||
}
|
||||
|
||||
return track
|
||||
|
||||
async def separate_other_stems(self, track, input_audio, stems_dir):
|
||||
"""
|
||||
Separate other stems from the input audio.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
input_audio: The input audio file
|
||||
stems_dir: The directory to store stems
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Separating other stems for {track.base_name}")
|
||||
|
||||
# Skip if no models are specified
|
||||
if not self.config.other_stems_models:
|
||||
self.logger.info("No other stems models specified, skipping")
|
||||
track.separated_audio["other_stems"] = {}
|
||||
return track
|
||||
|
||||
# Acquire lock for audio separation
|
||||
with self._acquire_lock(track.base_name):
|
||||
artist_title = track.base_name
|
||||
|
||||
# Initialize results
|
||||
track.separated_audio["other_stems"] = {}
|
||||
|
||||
# Process each model
|
||||
for model_name in self.config.other_stems_models:
|
||||
self.logger.info(f"Separating stems using model: {model_name}")
|
||||
|
||||
# Define output paths based on model
|
||||
if "demucs" in model_name.lower():
|
||||
stems = ["drums", "bass", "other", "vocals"]
|
||||
output_paths = {
|
||||
stem: os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} ({stem.capitalize()} {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
) for stem in stems
|
||||
}
|
||||
else:
|
||||
# Default to 2-stem separation
|
||||
stems = ["instrumental", "vocals"]
|
||||
output_paths = {
|
||||
stem: os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} ({model_name} {stem.capitalize()}).{self.config.lossless_output_format.lower()}"
|
||||
) for stem in stems
|
||||
}
|
||||
|
||||
# Check if all output files already exist
|
||||
if all(os.path.isfile(path) for path in output_paths.values()):
|
||||
self.logger.info(f"All stems for model {model_name} already exist")
|
||||
track.separated_audio["other_stems"][model_name] = output_paths
|
||||
continue
|
||||
|
||||
# Perform separation
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Load model first
|
||||
self.separator.load_model(model_filename=model_name)
|
||||
|
||||
# Convert input_audio to absolute path
|
||||
input_audio_abs = os.path.abspath(input_audio)
|
||||
|
||||
# Call separate with the absolute path to the audio file
|
||||
output_files = self.separator.separate(input_audio_abs)
|
||||
|
||||
# Process the output files
|
||||
result = {}
|
||||
for file in output_files:
|
||||
# The file path returned by separator.separate()
|
||||
# may already be the full path or just the filename
|
||||
file_name = os.path.basename(file)
|
||||
file_path = file
|
||||
|
||||
if "demucs" in model_name.lower():
|
||||
# Extract stem name from demucs output
|
||||
if "_(Drums)_" in file_name or "_drums." in file_name.lower():
|
||||
stem_path = output_paths["drums"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["drums"] = stem_path
|
||||
elif "_(Bass)_" in file_name or "_bass." in file_name.lower():
|
||||
stem_path = output_paths["bass"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["bass"] = stem_path
|
||||
elif "_(Other)_" in file_name or "_other." in file_name.lower():
|
||||
stem_path = output_paths["other"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["other"] = stem_path
|
||||
elif "_(Vocals)_" in file_name or "_vocals." in file_name.lower():
|
||||
stem_path = output_paths["vocals"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["vocals"] = stem_path
|
||||
elif "_(Guitar)_" in file_name:
|
||||
# For additional stems like guitar and piano, add them to the other stems too
|
||||
stem_name = "guitar"
|
||||
stem_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} ({stem_name.capitalize()} {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result[stem_name] = stem_path
|
||||
elif "_(Piano)_" in file_name:
|
||||
stem_name = "piano"
|
||||
stem_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} ({stem_name.capitalize()} {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result[stem_name] = stem_path
|
||||
else:
|
||||
# Try to extract stem name for any other stems that might be present
|
||||
try:
|
||||
# Extract stem name from patterns like "_(StemName)_"
|
||||
stem_match = re.search(r"_\(([^)]+)\)_", file_name)
|
||||
if stem_match:
|
||||
stem_name = stem_match.group(1)
|
||||
stem_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} ({stem_name} {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result[stem_name.lower()] = stem_path
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Could not process stem file {file_name}: {e}")
|
||||
else:
|
||||
# Handle 2-stem models
|
||||
if "(Vocals)" in file_name:
|
||||
stem_path = output_paths["vocals"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["vocals"] = stem_path
|
||||
elif "(Instrumental)" in file_name:
|
||||
stem_path = output_paths["instrumental"]
|
||||
if os.path.exists(file_path) and not os.path.exists(stem_path):
|
||||
shutil.move(file_path, stem_path)
|
||||
result["instrumental"] = stem_path
|
||||
|
||||
# Update track with separation results
|
||||
track.separated_audio["other_stems"][model_name] = result
|
||||
|
||||
self.logger.info(f"Successfully separated stems using model: {model_name}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to separate stems using model {model_name}: {str(e)}")
|
||||
# Continue with other models
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would separate stems using model: {model_name}")
|
||||
track.separated_audio["other_stems"][model_name] = output_paths
|
||||
|
||||
return track
|
||||
|
||||
async def separate_backing_vocals(self, track, stems_dir):
|
||||
"""
|
||||
Separate backing vocals from the clean vocals.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
stems_dir: The directory to store stems
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Separating backing vocals for {track.base_name}")
|
||||
|
||||
# Skip if no models are specified or no clean vocals
|
||||
if not self.config.backing_vocals_models or not track.separated_audio["clean_instrumental"].get("vocals"):
|
||||
self.logger.info("No backing vocals models specified or no clean vocals available, skipping")
|
||||
track.separated_audio["backing_vocals"] = {}
|
||||
return track
|
||||
|
||||
# Get vocals path
|
||||
vocals_path = track.separated_audio["clean_instrumental"]["vocals"]
|
||||
|
||||
# Acquire lock for audio separation
|
||||
with self._acquire_lock(track.base_name):
|
||||
artist_title = track.base_name
|
||||
|
||||
# Initialize results
|
||||
track.separated_audio["backing_vocals"] = {}
|
||||
|
||||
# Process each model
|
||||
for model_name in self.config.backing_vocals_models:
|
||||
self.logger.info(f"Separating backing vocals using model: {model_name}")
|
||||
|
||||
# Define output paths
|
||||
lead_vocals_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} (Lead Vocals {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
backing_vocals_path = os.path.join(
|
||||
stems_dir,
|
||||
f"{artist_title} (Backing Vocals {model_name}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Check if output files already exist
|
||||
if os.path.isfile(lead_vocals_path) and os.path.isfile(backing_vocals_path):
|
||||
self.logger.info(f"Backing vocals for model {model_name} already exist")
|
||||
track.separated_audio["backing_vocals"][model_name] = {
|
||||
"lead_vocals": lead_vocals_path,
|
||||
"backing_vocals": backing_vocals_path
|
||||
}
|
||||
continue
|
||||
|
||||
# Perform separation
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Load model first
|
||||
self.separator.load_model(model_filename=model_name)
|
||||
|
||||
# Convert vocals_path to absolute path
|
||||
vocals_path_abs = os.path.abspath(vocals_path)
|
||||
|
||||
# Call separate with the absolute path to the audio file
|
||||
output_files = self.separator.separate(vocals_path_abs)
|
||||
|
||||
# Process the output files
|
||||
result = {}
|
||||
for file in output_files:
|
||||
# The file path returned by separator.separate()
|
||||
# may already be the full path or just the filename
|
||||
file_name = os.path.basename(file)
|
||||
file_path = file # Use the path as returned by separator
|
||||
|
||||
if "(Vocals)" in file_name:
|
||||
# This is the lead vocals
|
||||
if os.path.exists(file_path) and not os.path.exists(lead_vocals_path):
|
||||
shutil.move(file_path, lead_vocals_path)
|
||||
result["lead_vocals"] = lead_vocals_path
|
||||
elif "(Instrumental)" in file_name:
|
||||
# This is the backing vocals
|
||||
if os.path.exists(file_path) and not os.path.exists(backing_vocals_path):
|
||||
shutil.move(file_path, backing_vocals_path)
|
||||
result["backing_vocals"] = backing_vocals_path
|
||||
|
||||
# Update track with separation results
|
||||
track.separated_audio["backing_vocals"][model_name] = result
|
||||
|
||||
self.logger.info(f"Successfully separated backing vocals using model: {model_name}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to separate backing vocals using model {model_name}: {str(e)}")
|
||||
# Continue with other models
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would separate backing vocals using model: {model_name}")
|
||||
track.separated_audio["backing_vocals"][model_name] = {
|
||||
"lead_vocals": lead_vocals_path,
|
||||
"backing_vocals": backing_vocals_path
|
||||
}
|
||||
|
||||
return track
|
||||
|
||||
async def separate_audio(self, track):
|
||||
"""
|
||||
Orchestrate the entire audio separation process.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Starting audio separation process for {track.base_name}")
|
||||
|
||||
# Skip if requested
|
||||
if self.config.skip_separation:
|
||||
self.logger.info("Skipping audio separation as requested")
|
||||
track.separated_audio = {
|
||||
"clean_instrumental": {},
|
||||
"backing_vocals": {},
|
||||
"other_stems": {},
|
||||
"combined_instrumentals": {}
|
||||
}
|
||||
return track
|
||||
|
||||
# Create stems directory
|
||||
stems_dir = os.path.join(track.track_output_dir, "stems")
|
||||
os.makedirs(stems_dir, exist_ok=True)
|
||||
self.logger.info(f"Created stems directory: {stems_dir}")
|
||||
|
||||
# Check for existing instrumental
|
||||
if self.config.existing_instrumental:
|
||||
self.logger.info(f"Using existing instrumental file: {self.config.existing_instrumental}")
|
||||
existing_instrumental_extension = os.path.splitext(self.config.existing_instrumental)[1]
|
||||
|
||||
instrumental_path = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Instrumental Custom){existing_instrumental_extension}"
|
||||
)
|
||||
|
||||
if not os.path.exists(instrumental_path):
|
||||
shutil.copy2(self.config.existing_instrumental, instrumental_path)
|
||||
|
||||
track.separated_audio["clean_instrumental"] = {
|
||||
"instrumental": instrumental_path,
|
||||
"vocals": None
|
||||
}
|
||||
return track
|
||||
|
||||
# Perform separation steps
|
||||
try:
|
||||
# Step 1: Separate clean instrumental
|
||||
track = await self.separate_clean_instrumental(track, track.input_audio_wav, stems_dir)
|
||||
|
||||
# Step 2: Separate other stems
|
||||
track = await self.separate_other_stems(track, track.input_audio_wav, stems_dir)
|
||||
|
||||
# Step 3: Separate backing vocals
|
||||
track = await self.separate_backing_vocals(track, stems_dir)
|
||||
|
||||
# Step 4: Generate combined instrumentals
|
||||
track = await self.generate_combined_instrumentals(track, stems_dir)
|
||||
|
||||
# Step 5: Normalize audio files
|
||||
track = await self.normalize_audio_files(track)
|
||||
|
||||
self.logger.info("Audio separation process completed successfully")
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
raise AudioError(f"Error during audio separation: {str(e)}") from e
|
||||
|
||||
async def generate_combined_instrumentals(self, track, stems_dir):
|
||||
"""
|
||||
Generate combined instrumental tracks with backing vocals.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
stems_dir: The directory to store stems
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Generating combined instrumental tracks with backing vocals for {track.base_name}")
|
||||
|
||||
# Skip if no backing vocals or clean instrumental
|
||||
if (not track.separated_audio["backing_vocals"] or
|
||||
not track.separated_audio["clean_instrumental"].get("instrumental")):
|
||||
self.logger.info("No backing vocals or clean instrumental available, skipping")
|
||||
track.separated_audio["combined_instrumentals"] = {}
|
||||
return track
|
||||
|
||||
instrumental_path = track.separated_audio["clean_instrumental"]["instrumental"]
|
||||
track.separated_audio["combined_instrumentals"] = {}
|
||||
|
||||
# Process each backing vocals model
|
||||
for model, paths in track.separated_audio["backing_vocals"].items():
|
||||
if "backing_vocals" not in paths:
|
||||
continue
|
||||
|
||||
backing_vocals_path = paths["backing_vocals"]
|
||||
combined_path = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Instrumental +BV {model}).{self.config.lossless_output_format.lower()}"
|
||||
)
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(combined_path):
|
||||
self.logger.info(f"Combined instrumental for model {model} already exists")
|
||||
track.separated_audio["combined_instrumentals"][model] = combined_path
|
||||
continue
|
||||
|
||||
# Perform mixing
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
from karaoke_gen.services.audio.mixer import AudioMixer
|
||||
mixer = AudioMixer(self.config)
|
||||
|
||||
# Mix instrumental and backing vocals
|
||||
await mixer.mix_audio_files(
|
||||
[instrumental_path, backing_vocals_path],
|
||||
combined_path,
|
||||
weights=[1, 1]
|
||||
)
|
||||
|
||||
track.separated_audio["combined_instrumentals"][model] = combined_path
|
||||
self.logger.info(f"Successfully created combined instrumental for model {model}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create combined instrumental for model {model}: {str(e)}")
|
||||
# Continue with other models
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would create combined instrumental for model {model}")
|
||||
track.separated_audio["combined_instrumentals"][model] = combined_path
|
||||
|
||||
return track
|
||||
|
||||
async def normalize_audio_files(self, track):
|
||||
"""
|
||||
Normalize audio levels for instrumental and combined tracks.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with normalized audio files
|
||||
"""
|
||||
self.logger.info(f"Normalizing audio files for {track.base_name}")
|
||||
|
||||
files_to_normalize = []
|
||||
|
||||
# Add clean instrumental
|
||||
if track.separated_audio["clean_instrumental"].get("instrumental"):
|
||||
files_to_normalize.append(
|
||||
("clean_instrumental", track.separated_audio["clean_instrumental"]["instrumental"])
|
||||
)
|
||||
|
||||
# Add combined instrumentals
|
||||
for model, path in track.separated_audio["combined_instrumentals"].items():
|
||||
files_to_normalize.append(("combined_instrumentals", path))
|
||||
|
||||
# Skip if no files to normalize
|
||||
if not files_to_normalize:
|
||||
self.logger.info("No files to normalize, skipping")
|
||||
return track
|
||||
|
||||
# Normalize each file
|
||||
for key, file_path in files_to_normalize:
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
from karaoke_gen.services.audio.normalizer import AudioNormalizer
|
||||
normalizer = AudioNormalizer(self.config)
|
||||
|
||||
# Normalize in-place
|
||||
await normalizer.normalize_audio_file(file_path, file_path)
|
||||
|
||||
# Verify the normalized file
|
||||
if os.path.getsize(file_path) > 0:
|
||||
self.logger.info(f"Successfully normalized: {file_path}")
|
||||
else:
|
||||
raise AudioError("Normalized file is empty")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error during normalization of {file_path}: {e}")
|
||||
self.logger.warning(f"Normalization failed for {file_path}. Original file remains unchanged.")
|
||||
else:
|
||||
self.logger.warning(f"File not found for normalization: {file_path}")
|
||||
|
||||
self.logger.info("Audio normalization process completed")
|
||||
return track
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the audio separator.
|
||||
"""
|
||||
self.logger.info("Cleaning up audio separator resources")
|
||||
|
||||
# Release any locks
|
||||
for lock in self._locks.values():
|
||||
if lock.locked():
|
||||
lock.release()
|
||||
|
||||
# Close any open resources
|
||||
if hasattr(self, 'demucs_model') and self.demucs_model:
|
||||
# Clean up demucs model resources if needed
|
||||
pass
|
||||
|
||||
if hasattr(self, 'spleeter_model') and self.spleeter_model:
|
||||
# Clean up spleeter model resources if needed
|
||||
pass
|
||||
|
||||
self.logger.info("Audio separator cleanup complete")
|
||||
|
||||
def _acquire_lock(self, track_name):
|
||||
"""
|
||||
Acquire a lock for audio separation.
|
||||
|
||||
Args:
|
||||
track_name: The name of the track being processed
|
||||
|
||||
Returns:
|
||||
A context manager for the lock
|
||||
"""
|
||||
class LockContextManager:
|
||||
def __init__(self, separator, track_name):
|
||||
self.separator = separator
|
||||
self.track_name = track_name
|
||||
self.lock_file = None
|
||||
self.lock_file_path = os.path.join(tempfile.gettempdir(), "audio_separator.lock")
|
||||
|
||||
def __enter__(self):
|
||||
# Try to acquire lock
|
||||
while True:
|
||||
try:
|
||||
# First check if there's a stale lock
|
||||
if os.path.exists(self.lock_file_path):
|
||||
try:
|
||||
with open(self.lock_file_path, "r") as f:
|
||||
lock_data = json.load(f)
|
||||
pid = lock_data.get("pid")
|
||||
start_time = datetime.fromisoformat(lock_data.get("start_time"))
|
||||
running_track = lock_data.get("track")
|
||||
|
||||
# Check if the process is still running
|
||||
if pid and self.separator._is_process_running(pid):
|
||||
# Process is still running
|
||||
self.separator.logger.info(f"Waiting for another separation process to complete: {running_track}")
|
||||
time.sleep(5)
|
||||
continue
|
||||
else:
|
||||
# Stale lock, remove it
|
||||
self.separator.logger.info(f"Removing stale lock file")
|
||||
os.remove(self.lock_file_path)
|
||||
except (json.JSONDecodeError, KeyError, ValueError):
|
||||
# Invalid lock file, remove it
|
||||
self.separator.logger.info(f"Removing invalid lock file")
|
||||
os.remove(self.lock_file_path)
|
||||
|
||||
# Create lock file
|
||||
lock_data = {
|
||||
"pid": os.getpid(),
|
||||
"start_time": datetime.now().isoformat(),
|
||||
"track": self.track_name
|
||||
}
|
||||
|
||||
with open(self.lock_file_path, "w") as f:
|
||||
json.dump(lock_data, f)
|
||||
|
||||
self.lock_file = self.lock_file_path
|
||||
self.separator.logger.info(f"Acquired lock for {self.track_name}")
|
||||
return self
|
||||
except Exception as e:
|
||||
self.separator.logger.error(f"Error acquiring lock: {str(e)}")
|
||||
time.sleep(5)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
# Release lock
|
||||
if self.lock_file and os.path.exists(self.lock_file):
|
||||
try:
|
||||
os.remove(self.lock_file)
|
||||
self.separator.logger.info(f"Released lock for {self.track_name}")
|
||||
except Exception as e:
|
||||
self.separator.logger.error(f"Error releasing lock: {str(e)}")
|
||||
|
||||
return LockContextManager(self, track_name)
|
||||
|
||||
def _is_process_running(self, pid):
|
||||
"""
|
||||
Check if a process with the given PID is running.
|
||||
|
||||
Args:
|
||||
pid: The process ID to check
|
||||
|
||||
Returns:
|
||||
True if the process is running, False otherwise
|
||||
"""
|
||||
try:
|
||||
# For Unix/Linux/Mac
|
||||
if os.name == 'posix':
|
||||
# Send signal 0 to the process - this doesn't actually send a signal,
|
||||
# but it does error checking to see if the process exists
|
||||
os.kill(pid, 0)
|
||||
return True
|
||||
# For Windows
|
||||
elif os.name == 'nt':
|
||||
import ctypes
|
||||
kernel32 = ctypes.windll.kernel32
|
||||
SYNCHRONIZE = 0x00100000
|
||||
process = kernel32.OpenProcess(SYNCHRONIZE, False, pid)
|
||||
if process != 0:
|
||||
kernel32.CloseHandle(process)
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
# Fallback for other OS
|
||||
return False
|
||||
except OSError:
|
||||
return False
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error checking if process {pid} is running: {str(e)}")
|
||||
return False
|
||||
@@ -0,0 +1,90 @@
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import AudioError
|
||||
from karaoke_gen.services.audio.converter import AudioConverter
|
||||
from karaoke_gen.services.audio.separator import AudioSeparator
|
||||
from karaoke_gen.services.audio.normalizer import AudioNormalizer
|
||||
from karaoke_gen.services.audio.mixer import AudioMixer
|
||||
|
||||
|
||||
class AudioService:
|
||||
"""
|
||||
Service for orchestrating the audio processing workflow.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the audio service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Initialize components
|
||||
self.converter = AudioConverter(config)
|
||||
self.separator = AudioSeparator(config)
|
||||
self.normalizer = AudioNormalizer(config)
|
||||
self.mixer = AudioMixer(config)
|
||||
|
||||
async def separate_audio(self, track: Track) -> Track:
|
||||
"""
|
||||
Separate audio for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with separated audio
|
||||
"""
|
||||
self.logger.info(f"Separating audio for {track.base_name}")
|
||||
return await self.separator.separate_audio(track)
|
||||
|
||||
async def process_audio(self, track: Track) -> Track:
|
||||
"""
|
||||
Process audio for a track, including separation, mixing, and normalization.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated audio information
|
||||
"""
|
||||
self.logger.info(f"Processing audio for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Skip if instrumental already exists and we're not forcing regeneration
|
||||
if track.instrumental and os.path.isfile(track.instrumental) and not self.config.force_regenerate:
|
||||
self.logger.info(f"Instrumental already exists for {track.base_name}, skipping audio processing")
|
||||
return track
|
||||
|
||||
# Separate audio
|
||||
track = await self.separator.separate_audio(track)
|
||||
|
||||
# Mix audio
|
||||
track = await self.mixer.mix_audio(track)
|
||||
|
||||
# Normalize audio
|
||||
track = await self.normalizer.normalize_audio(track)
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to process audio for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for audio processing.
|
||||
"""
|
||||
self.logger.info("Cleaning up audio processing resources")
|
||||
|
||||
# Close any open resources
|
||||
await self.separator.cleanup()
|
||||
|
||||
self.logger.info("Audio processing cleanup complete")
|
||||
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
Distribution service module for the karaoke_gen package.
|
||||
|
||||
This module contains the distribution service and related components.
|
||||
"""
|
||||
|
||||
from karaoke_gen.services.distribution.service import DistributionService
|
||||
from karaoke_gen.services.distribution.youtube import YouTubeUploader
|
||||
from karaoke_gen.services.distribution.organizer import FileOrganizer
|
||||
from karaoke_gen.services.distribution.cdg import CDGGenerator
|
||||
from karaoke_gen.services.distribution.txt import TXTGenerator
|
||||
from karaoke_gen.services.distribution.notifier import Notifier
|
||||
|
||||
__all__ = [
|
||||
"DistributionService",
|
||||
"YouTubeUploader",
|
||||
"FileOrganizer",
|
||||
"CDGGenerator",
|
||||
"TXTGenerator",
|
||||
"Notifier",
|
||||
]
|
||||
@@ -0,0 +1,159 @@
|
||||
"""
|
||||
CDG file generation functionality for the distribution service.
|
||||
"""
|
||||
|
||||
import os
|
||||
import zipfile
|
||||
import logging
|
||||
from typing import Optional, Dict, Any, Tuple
|
||||
|
||||
from lyrics_transcriber.output.cdg import CDGGenerator as LyricsTranscriberCDGGenerator
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DistributionError
|
||||
|
||||
|
||||
class CDGGenerator:
|
||||
"""
|
||||
Class for handling CDG file generation.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the CDG generator.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
def create_cdg_zip_file(self, track: Track) -> Track:
|
||||
"""
|
||||
Create a CDG zip file for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated CDG zip file information
|
||||
|
||||
Raises:
|
||||
DistributionError: If creating the CDG zip file fails
|
||||
"""
|
||||
self.logger.info(f"Creating CDG and MP3 files, then zipping them...")
|
||||
|
||||
if not self.config.enable_cdg:
|
||||
self.logger.warning("CDG generation not enabled, skipping")
|
||||
return track
|
||||
|
||||
if not track.processed_lyrics:
|
||||
self.logger.warning("No processed lyrics available, cannot create CDG file")
|
||||
return track
|
||||
|
||||
if not track.instrumental:
|
||||
self.logger.warning("No instrumental audio available, cannot create CDG file")
|
||||
return track
|
||||
|
||||
# Determine the output file paths
|
||||
cdg_zip_file = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke CDG).zip")
|
||||
cdg_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).cdg")
|
||||
mp3_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).mp3")
|
||||
lrc_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# Check if CDG file already exists, if so, ask user to overwrite or skip
|
||||
if os.path.isfile(cdg_zip_file):
|
||||
if self.config.non_interactive:
|
||||
self.logger.info(f"Non-interactive mode, automatically overwriting existing CDG ZIP file: {cdg_zip_file}")
|
||||
else:
|
||||
from karaoke_gen.utils.validation import prompt_user_bool
|
||||
if not prompt_user_bool(
|
||||
f"Found existing CDG ZIP file: {cdg_zip_file}. Overwrite (y) or skip (n)?",
|
||||
):
|
||||
self.logger.info(f"Skipping CDG ZIP file creation, existing file will be used.")
|
||||
track.final_karaoke_cdg_zip = cdg_zip_file
|
||||
return track
|
||||
|
||||
# Check if individual MP3 and CDG files already exist
|
||||
if os.path.isfile(mp3_file) and os.path.isfile(cdg_file):
|
||||
self.logger.info(f"Found existing MP3 and CDG files, creating ZIP file directly")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would create ZIP file from existing MP3 and CDG files")
|
||||
track.final_karaoke_cdg_zip = cdg_zip_file
|
||||
return track
|
||||
|
||||
try:
|
||||
with zipfile.ZipFile(cdg_zip_file, "w") as zipf:
|
||||
zipf.write(mp3_file, os.path.basename(mp3_file))
|
||||
zipf.write(cdg_file, os.path.basename(cdg_file))
|
||||
|
||||
self.logger.info(f"Created CDG ZIP file: {cdg_zip_file}")
|
||||
track.final_karaoke_cdg_zip = cdg_zip_file
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create CDG ZIP file: {str(e)}")
|
||||
raise DistributionError(f"Failed to create CDG ZIP file: {str(e)}")
|
||||
|
||||
# Generate CDG and MP3 files if they don't exist
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would generate CDG and MP3 files")
|
||||
track.final_karaoke_cdg_zip = cdg_zip_file
|
||||
return track
|
||||
|
||||
try:
|
||||
self.logger.info(f"Generating CDG and MP3 files")
|
||||
|
||||
if not self.config.cdg_styles:
|
||||
raise DistributionError("CDG styles configuration is required when enable_cdg is True")
|
||||
|
||||
# Create the LRC file if it doesn't exist
|
||||
if not os.path.isfile(lrc_file) and track.processed_lyrics:
|
||||
with open(lrc_file, "w", encoding="utf-8") as f:
|
||||
f.write(track.processed_lyrics)
|
||||
|
||||
# Use the CDGGenerator from lyrics_transcriber to generate the CDG file
|
||||
generator = LyricsTranscriberCDGGenerator(output_dir=track.track_output_dir, logger=self.logger)
|
||||
|
||||
cdg_file_generated, mp3_file_generated, zip_file_generated = generator.generate_cdg_from_lrc(
|
||||
lrc_file=lrc_file,
|
||||
audio_file=track.instrumental,
|
||||
title=track.title,
|
||||
artist=track.artist,
|
||||
cdg_styles=self.config.cdg_styles,
|
||||
)
|
||||
|
||||
# Rename the generated ZIP file to match our expected naming convention
|
||||
if os.path.isfile(zip_file_generated) and zip_file_generated != cdg_zip_file:
|
||||
os.rename(zip_file_generated, cdg_zip_file)
|
||||
self.logger.info(f"Renamed CDG ZIP file from {zip_file_generated} to {cdg_zip_file}")
|
||||
|
||||
# Verify the CDG ZIP file was created
|
||||
if not os.path.isfile(cdg_zip_file):
|
||||
self.logger.error(f"Failed to find any CDG ZIP file. Listing directory contents:")
|
||||
for file in os.listdir(track.track_output_dir):
|
||||
self.logger.error(f" - {file}")
|
||||
raise DistributionError(f"Failed to create CDG ZIP file: {cdg_zip_file}")
|
||||
|
||||
self.logger.info(f"CDG ZIP file created: {cdg_zip_file}")
|
||||
|
||||
# Extract the CDG ZIP file to get the individual files
|
||||
self.logger.info(f"Extracting CDG ZIP file: {cdg_zip_file}")
|
||||
with zipfile.ZipFile(cdg_zip_file, "r") as zip_ref:
|
||||
zip_ref.extractall(track.track_output_dir)
|
||||
|
||||
# Verify the MP3 file was extracted
|
||||
if os.path.isfile(mp3_file):
|
||||
self.logger.info(f"Found extracted MP3 file: {mp3_file}")
|
||||
else:
|
||||
self.logger.error("Failed to find extracted MP3 file")
|
||||
raise DistributionError("Failed to extract MP3 file from CDG ZIP")
|
||||
|
||||
track.final_karaoke_cdg_zip = cdg_zip_file
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create CDG ZIP file: {str(e)}")
|
||||
raise DistributionError(f"Failed to create CDG ZIP file: {str(e)}")
|
||||
@@ -0,0 +1,285 @@
|
||||
"""
|
||||
Notification functionality for the distribution service.
|
||||
"""
|
||||
|
||||
import os
|
||||
import pickle
|
||||
import logging
|
||||
import base64
|
||||
import requests
|
||||
from typing import Optional, Dict, Any
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from google.auth.transport.requests import Request
|
||||
from googleapiclient.discovery import build
|
||||
from google.oauth2.credentials import Credentials
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DistributionError
|
||||
|
||||
|
||||
class Notifier:
|
||||
"""
|
||||
Class for handling notifications.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the notifier.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
self.gmail_token_file = "/tmp/karaoke-finalise-gmail-token.pickle"
|
||||
self.gmail_service = None
|
||||
|
||||
def post_discord_message(self, message: str, webhook_url: str) -> None:
|
||||
"""
|
||||
Post a message to a Discord channel via webhook.
|
||||
|
||||
Args:
|
||||
message: The message to post
|
||||
webhook_url: The Discord webhook URL
|
||||
|
||||
Raises:
|
||||
DistributionError: If posting the message fails
|
||||
"""
|
||||
self.logger.info(f"Posting message to Discord...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would post message to Discord: {message}")
|
||||
return
|
||||
|
||||
try:
|
||||
data = {"content": message}
|
||||
response = requests.post(webhook_url, json=data)
|
||||
response.raise_for_status() # This will raise an exception if the request failed
|
||||
self.logger.info("Message posted to Discord")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to post message to Discord: {str(e)}")
|
||||
raise DistributionError(f"Failed to post message to Discord: {str(e)}")
|
||||
|
||||
def post_discord_notification(self, track: Track, skip_notifications: bool = False) -> None:
|
||||
"""
|
||||
Post a notification to Discord.
|
||||
|
||||
Args:
|
||||
track: The track to notify about
|
||||
skip_notifications: Whether to skip notifications
|
||||
|
||||
Raises:
|
||||
DistributionError: If posting the notification fails
|
||||
"""
|
||||
self.logger.info(f"Posting Discord notification...")
|
||||
|
||||
if not self.config.discord_webhook_url:
|
||||
self.logger.warning("Discord webhook URL not set, cannot post notification")
|
||||
return
|
||||
|
||||
if skip_notifications:
|
||||
self.logger.info(f"Skipping Discord notification as requested")
|
||||
return
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(
|
||||
f"DRY RUN: Would post Discord notification for YouTube URL {track.youtube_url} using webhook URL: {self.config.discord_webhook_url}"
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
# Create a rich embed for Discord
|
||||
embed = {
|
||||
"title": f"{track.artist} - {track.title}",
|
||||
"description": "New karaoke track available!",
|
||||
"color": 0x00ff00, # Green color
|
||||
"fields": []
|
||||
}
|
||||
|
||||
# Add brand code if available
|
||||
if track.brand_code:
|
||||
embed["fields"].append({
|
||||
"name": "Brand Code",
|
||||
"value": track.brand_code,
|
||||
"inline": True
|
||||
})
|
||||
|
||||
# Add YouTube URL if available
|
||||
if track.youtube_url:
|
||||
embed["fields"].append({
|
||||
"name": "YouTube",
|
||||
"value": track.youtube_url,
|
||||
"inline": True
|
||||
})
|
||||
|
||||
# Add sharing link if available
|
||||
if track.brand_code_dir_sharing_link:
|
||||
embed["fields"].append({
|
||||
"name": "Download",
|
||||
"value": track.brand_code_dir_sharing_link,
|
||||
"inline": True
|
||||
})
|
||||
|
||||
# Create the payload
|
||||
payload = {
|
||||
"embeds": [embed]
|
||||
}
|
||||
|
||||
# Post to Discord
|
||||
response = requests.post(self.config.discord_webhook_url, json=payload)
|
||||
response.raise_for_status()
|
||||
|
||||
self.logger.info("Discord notification posted successfully")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to post Discord notification: {str(e)}")
|
||||
raise DistributionError(f"Failed to post Discord notification: {str(e)}")
|
||||
|
||||
def authenticate_gmail(self) -> Any:
|
||||
"""
|
||||
Authenticate and return a Gmail service object.
|
||||
|
||||
Returns:
|
||||
The authenticated Gmail service
|
||||
|
||||
Raises:
|
||||
DistributionError: If authentication fails
|
||||
"""
|
||||
self.logger.info("Authenticating with Gmail...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info("DRY RUN: Would authenticate with Gmail")
|
||||
return None
|
||||
|
||||
try:
|
||||
creds = None
|
||||
|
||||
# Token file stores the user's access and refresh tokens for Gmail.
|
||||
if os.path.exists(self.gmail_token_file):
|
||||
with open(self.gmail_token_file, "rb") as token:
|
||||
creds = pickle.load(token)
|
||||
|
||||
# If there are no valid credentials, let the user log in.
|
||||
if not creds or not creds.valid:
|
||||
if creds and creds.expired and creds.refresh_token:
|
||||
creds.refresh(Request())
|
||||
else:
|
||||
flow = InstalledAppFlow.from_client_secrets_file(
|
||||
self.config.youtube_client_secrets_file, # Reuse the YouTube client secrets file
|
||||
["https://www.googleapis.com/auth/gmail.compose"]
|
||||
)
|
||||
creds = flow.run_local_server(port=0)
|
||||
|
||||
# Save the credentials for the next run
|
||||
with open(self.gmail_token_file, "wb") as token:
|
||||
pickle.dump(creds, token)
|
||||
|
||||
return build("gmail", "v1", credentials=creds)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to authenticate with Gmail: {str(e)}")
|
||||
raise DistributionError(f"Failed to authenticate with Gmail: {str(e)}")
|
||||
|
||||
def draft_completion_email(self, track: Track) -> None:
|
||||
"""
|
||||
Draft a completion email.
|
||||
|
||||
Args:
|
||||
track: The track to draft an email for
|
||||
|
||||
Raises:
|
||||
DistributionError: If drafting the email fails
|
||||
"""
|
||||
self.logger.info(f"Drafting completion email...")
|
||||
|
||||
if not self.config.email_template_file:
|
||||
self.logger.info("Email template file not provided, skipping email draft creation.")
|
||||
return
|
||||
|
||||
if not track.youtube_url or not track.brand_code_dir_sharing_link:
|
||||
self.logger.warning("YouTube URL or sharing link not available, cannot draft completion email")
|
||||
return
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would draft completion email for {track.artist} - {track.title}")
|
||||
return
|
||||
|
||||
try:
|
||||
# Read the email template
|
||||
with open(self.config.email_template_file, "r", encoding="utf-8") as f:
|
||||
template = f.read()
|
||||
|
||||
# Format the email body
|
||||
email_body = template.format(
|
||||
youtube_url=track.youtube_url,
|
||||
dropbox_url=track.brand_code_dir_sharing_link,
|
||||
artist=track.artist,
|
||||
title=track.title,
|
||||
brand_code=track.brand_code
|
||||
)
|
||||
|
||||
# Create the email subject
|
||||
subject = f"{track.brand_code}: {track.artist} - {track.title}"
|
||||
|
||||
# Create the email message
|
||||
message = MIMEText(email_body)
|
||||
message["subject"] = subject
|
||||
|
||||
# Encode the message
|
||||
raw_message = base64.urlsafe_b64encode(message.as_bytes()).decode("utf-8")
|
||||
|
||||
# Get the Gmail service
|
||||
if not self.gmail_service:
|
||||
self.gmail_service = self.authenticate_gmail()
|
||||
|
||||
# Create the draft
|
||||
draft = self.gmail_service.users().drafts().create(
|
||||
userId="me",
|
||||
body={"message": {"raw": raw_message}}
|
||||
).execute()
|
||||
|
||||
self.logger.info(f"Email draft created with ID: {draft['id']}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to draft completion email: {str(e)}")
|
||||
raise DistributionError(f"Failed to draft completion email: {str(e)}")
|
||||
|
||||
def test_email_template(self) -> None:
|
||||
"""
|
||||
Test the email template by creating a draft with fake data.
|
||||
|
||||
Raises:
|
||||
DistributionError: If testing the email template fails
|
||||
"""
|
||||
self.logger.info(f"Testing email template...")
|
||||
|
||||
if not self.config.email_template_file:
|
||||
self.logger.error("Email template file not provided. Use --email_template_file to specify the file path.")
|
||||
return
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would test email template")
|
||||
return
|
||||
|
||||
try:
|
||||
# Create a fake track
|
||||
fake_track = Track(
|
||||
artist="Test Artist",
|
||||
title="Test Song",
|
||||
brand_code="TEST-0001",
|
||||
youtube_url="https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
brand_code_dir_sharing_link="https://www.dropbox.com/sh/fake/folder/link"
|
||||
)
|
||||
|
||||
# Draft the email
|
||||
self.draft_completion_email(fake_track)
|
||||
|
||||
self.logger.info("Email template test complete. Check your Gmail drafts for the test email.")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to test email template: {str(e)}")
|
||||
raise DistributionError(f"Failed to test email template: {str(e)}")
|
||||
@@ -0,0 +1,329 @@
|
||||
"""
|
||||
File organization functionality for the distribution service.
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
import logging
|
||||
import shlex
|
||||
from typing import Optional, Dict, Any, List
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DistributionError
|
||||
|
||||
|
||||
class FileOrganizer:
|
||||
"""
|
||||
Class for handling file organization operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the file organizer.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
def get_next_brand_code(self) -> str:
|
||||
"""
|
||||
Calculate the next sequence number based on existing directories in the organised_dir.
|
||||
Assumes directories are named with the format: BRAND-XXXX Artist - Title
|
||||
|
||||
Returns:
|
||||
The next brand code
|
||||
|
||||
Raises:
|
||||
DistributionError: If the target directory does not exist
|
||||
"""
|
||||
self.logger.info(f"Getting next brand code for prefix {self.config.brand_prefix}")
|
||||
|
||||
if not self.config.brand_prefix or not self.config.organised_dir:
|
||||
self.logger.warning("Brand prefix or organised directory not set, cannot get next brand code")
|
||||
return None
|
||||
|
||||
if not os.path.isdir(self.config.organised_dir):
|
||||
raise DistributionError(f"Target directory does not exist: {self.config.organised_dir}")
|
||||
|
||||
max_num = 0
|
||||
pattern = re.compile(rf"^{re.escape(self.config.brand_prefix)}-(\d{{4}})")
|
||||
|
||||
for dir_name in os.listdir(self.config.organised_dir):
|
||||
match = pattern.match(dir_name)
|
||||
if match:
|
||||
num = int(match.group(1))
|
||||
max_num = max(max_num, num)
|
||||
|
||||
self.logger.info(f"Next sequence number for brand {self.config.brand_prefix} calculated as: {max_num + 1}")
|
||||
next_seq_number = max_num + 1
|
||||
|
||||
return f"{self.config.brand_prefix}-{next_seq_number:04d}"
|
||||
|
||||
def get_existing_brand_code(self, track: Track) -> str:
|
||||
"""
|
||||
Extract brand code from current directory name.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The existing brand code
|
||||
|
||||
Raises:
|
||||
DistributionError: If the current directory name does not match the expected format
|
||||
"""
|
||||
self.logger.info("Getting existing brand code from current directory")
|
||||
|
||||
if not self.config.brand_prefix:
|
||||
self.logger.warning("Brand prefix not set, cannot get existing brand code")
|
||||
return None
|
||||
|
||||
current_dir = os.path.basename(track.track_output_dir)
|
||||
|
||||
if " - " not in current_dir:
|
||||
raise DistributionError(f"Current directory '{current_dir}' does not match expected format 'BRAND-XXXX - Artist - Title'")
|
||||
|
||||
brand_code = current_dir.split(" - ")[0]
|
||||
if not brand_code or "-" not in brand_code:
|
||||
raise DistributionError(f"Could not extract valid brand code from directory name '{current_dir}'")
|
||||
|
||||
self.logger.info(f"Using existing brand code: {brand_code}")
|
||||
return brand_code
|
||||
|
||||
def move_files_to_brand_code_folder(self, track: Track, brand_code: str) -> Track:
|
||||
"""
|
||||
Move files to a brand code folder.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
brand_code: The brand code to use
|
||||
|
||||
Returns:
|
||||
The track with updated file paths
|
||||
|
||||
Raises:
|
||||
DistributionError: If moving the files fails
|
||||
"""
|
||||
self.logger.info(f"Moving files to new brand-prefixed directory...")
|
||||
|
||||
if not brand_code:
|
||||
self.logger.warning("Brand code not set, cannot move files")
|
||||
return track
|
||||
|
||||
new_brand_code_dir = f"{brand_code} - {track.artist} - {track.title}"
|
||||
new_brand_code_dir_path = os.path.join(self.config.organised_dir, new_brand_code_dir)
|
||||
|
||||
# Store the new directory path in the track
|
||||
track.new_brand_code_dir_path = new_brand_code_dir_path
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would move original directory {track.track_output_dir} to: {new_brand_code_dir_path}")
|
||||
return track
|
||||
|
||||
try:
|
||||
# Create the parent directory if it doesn't exist
|
||||
os.makedirs(os.path.dirname(new_brand_code_dir_path), exist_ok=True)
|
||||
|
||||
# Move the directory
|
||||
shutil.move(track.track_output_dir, new_brand_code_dir_path)
|
||||
|
||||
# Update the track's output directory
|
||||
track.track_output_dir = new_brand_code_dir_path
|
||||
|
||||
# Update file paths
|
||||
if track.final_video:
|
||||
track.final_video = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_video))
|
||||
|
||||
if track.final_video_mkv:
|
||||
track.final_video_mkv = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_video_mkv))
|
||||
|
||||
if track.final_video_lossy:
|
||||
track.final_video_lossy = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_video_lossy))
|
||||
|
||||
if track.final_video_720p:
|
||||
track.final_video_720p = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_video_720p))
|
||||
|
||||
if track.final_karaoke_cdg_zip:
|
||||
track.final_karaoke_cdg_zip = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_karaoke_cdg_zip))
|
||||
|
||||
if track.final_karaoke_txt_zip:
|
||||
track.final_karaoke_txt_zip = os.path.join(new_brand_code_dir_path, os.path.basename(track.final_karaoke_txt_zip))
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to move files to brand code folder: {str(e)}")
|
||||
raise DistributionError(f"Failed to move files to brand code folder: {str(e)}")
|
||||
|
||||
def copy_final_files_to_public_share_dirs(self, track: Track, brand_code: str) -> Track:
|
||||
"""
|
||||
Copy final files to public share directories.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
brand_code: The brand code to use
|
||||
|
||||
Returns:
|
||||
The track with updated file paths
|
||||
|
||||
Raises:
|
||||
DistributionError: If copying the files fails
|
||||
"""
|
||||
self.logger.info(f"Copying final MP4, 720p MP4, and ZIP to public share directory...")
|
||||
|
||||
if not self.config.public_share_dir:
|
||||
self.logger.warning("Public share directory not set, cannot copy files")
|
||||
return track
|
||||
|
||||
if not brand_code:
|
||||
raise DistributionError(f"Brand code not set, refusing to copy to public share directory")
|
||||
|
||||
# Validate public_share_dir is a valid folder with MP4, MP4-720p, and CDG subdirectories
|
||||
if not os.path.isdir(self.config.public_share_dir):
|
||||
raise DistributionError(f"Public share directory does not exist: {self.config.public_share_dir}")
|
||||
|
||||
dest_mp4_dir = os.path.join(self.config.public_share_dir, "MP4")
|
||||
dest_720p_dir = os.path.join(self.config.public_share_dir, "MP4-720p")
|
||||
dest_cdg_dir = os.path.join(self.config.public_share_dir, "CDG")
|
||||
|
||||
# Create directories if they don't exist
|
||||
for dir_path in [dest_mp4_dir, dest_720p_dir, dest_cdg_dir]:
|
||||
if not os.path.isdir(dir_path):
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would create directory: {dir_path}")
|
||||
else:
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
|
||||
# Prepare destination file paths
|
||||
dest_mp4_file = os.path.join(dest_mp4_dir, f"{brand_code} - {track.base_name}.mp4")
|
||||
dest_720p_mp4_file = os.path.join(dest_720p_dir, f"{brand_code} - {track.base_name}.mp4")
|
||||
dest_zip_file = os.path.join(dest_cdg_dir, f"{brand_code} - {track.base_name}.zip")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(
|
||||
f"DRY RUN: Would copy final MP4, 720p MP4, and ZIP to {dest_mp4_file}, {dest_720p_mp4_file}, and {dest_zip_file}"
|
||||
)
|
||||
return track
|
||||
|
||||
try:
|
||||
# Copy files
|
||||
if track.final_video_lossy and os.path.isfile(track.final_video_lossy):
|
||||
shutil.copy2(track.final_video_lossy, dest_mp4_file)
|
||||
|
||||
if track.final_video_720p and os.path.isfile(track.final_video_720p):
|
||||
shutil.copy2(track.final_video_720p, dest_720p_mp4_file)
|
||||
|
||||
if track.final_karaoke_cdg_zip and os.path.isfile(track.final_karaoke_cdg_zip):
|
||||
shutil.copy2(track.final_karaoke_cdg_zip, dest_zip_file)
|
||||
|
||||
self.logger.info(f"Copied final files to public share directory")
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to copy files to public share directory: {str(e)}")
|
||||
raise DistributionError(f"Failed to copy files to public share directory: {str(e)}")
|
||||
|
||||
def sync_public_share_dir_to_rclone_destination(self) -> None:
|
||||
"""
|
||||
Sync public share directory to rclone destination.
|
||||
|
||||
Raises:
|
||||
DistributionError: If syncing fails
|
||||
"""
|
||||
self.logger.info(f"Syncing public share directory to rclone destination...")
|
||||
|
||||
if not self.config.rclone_destination or not self.config.public_share_dir:
|
||||
self.logger.warning("Rclone destination or public share directory not set, cannot sync")
|
||||
return
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would sync {self.config.public_share_dir} to {self.config.rclone_destination}")
|
||||
return
|
||||
|
||||
try:
|
||||
# Delete .DS_Store files recursively before syncing
|
||||
for root, dirs, files in os.walk(self.config.public_share_dir):
|
||||
for file in files:
|
||||
if file == ".DS_Store":
|
||||
file_path = os.path.join(root, file)
|
||||
os.remove(file_path)
|
||||
self.logger.info(f"Deleted .DS_Store file: {file_path}")
|
||||
|
||||
# Build the rclone command
|
||||
rclone_cmd = f"rclone sync -v '{self.config.public_share_dir}' '{self.config.rclone_destination}'"
|
||||
|
||||
# Execute the command
|
||||
self.logger.info(f"Running command: {rclone_cmd}")
|
||||
process = subprocess.run(rclone_cmd, shell=True, check=True, capture_output=True, text=True)
|
||||
|
||||
if process.returncode != 0:
|
||||
raise DistributionError(f"rclone sync failed: {process.stderr}")
|
||||
|
||||
self.logger.info(f"Successfully synced public share directory to rclone destination")
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
self.logger.error(f"Failed to sync to rclone destination. Exit code: {e.returncode}")
|
||||
self.logger.error(f"Command output (stdout): {e.stdout}")
|
||||
self.logger.error(f"Command output (stderr): {e.stderr}")
|
||||
raise DistributionError(f"Failed to sync to rclone destination: {e.stderr}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to sync to rclone destination: {str(e)}")
|
||||
raise DistributionError(f"Failed to sync to rclone destination: {str(e)}")
|
||||
|
||||
def generate_organised_folder_sharing_link(self, track: Track) -> Optional[str]:
|
||||
"""
|
||||
Generate a sharing link for the organised folder.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The sharing link
|
||||
|
||||
Raises:
|
||||
DistributionError: If generating the link fails
|
||||
"""
|
||||
self.logger.info(f"Getting Organised Folder sharing link for new brand code directory...")
|
||||
|
||||
if not self.config.organised_dir_rclone_root or not track.brand_code or not track.new_brand_code_dir_path:
|
||||
self.logger.warning("Organised directory rclone root, brand code, or new brand code directory path not set, cannot generate sharing link")
|
||||
return None
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would get sharing link for {track.new_brand_code_dir_path}")
|
||||
return "https://file-sharing-service.com/example"
|
||||
|
||||
try:
|
||||
# Build the rclone destination path
|
||||
rclone_dest = f"{self.config.organised_dir_rclone_root}/{os.path.basename(track.new_brand_code_dir_path)}"
|
||||
rclone_link_cmd = f"rclone link {shlex.quote(rclone_dest)}"
|
||||
|
||||
# Add a 5-second delay to allow the service to index the folder before generating a link
|
||||
self.logger.info("Waiting 5 seconds before generating link...")
|
||||
time.sleep(5)
|
||||
|
||||
# Execute the command
|
||||
self.logger.info(f"Running command: {rclone_link_cmd}")
|
||||
result = subprocess.run(rclone_link_cmd, shell=True, check=True, capture_output=True, text=True)
|
||||
|
||||
sharing_link = result.stdout.strip()
|
||||
self.logger.info(f"Got organised folder sharing link: {sharing_link}")
|
||||
|
||||
return sharing_link
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
self.logger.error(f"Failed to get organised folder sharing link. Exit code: {e.returncode}")
|
||||
self.logger.error(f"Command output (stdout): {e.stdout}")
|
||||
self.logger.error(f"Command output (stderr): {e.stderr}")
|
||||
raise DistributionError(f"Failed to get organised folder sharing link: {e.stderr}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to get organised folder sharing link: {str(e)}")
|
||||
raise DistributionError(f"Failed to get organised folder sharing link: {str(e)}")
|
||||
@@ -0,0 +1,312 @@
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DistributionError, YouTubeError
|
||||
|
||||
from karaoke_gen.services.distribution.youtube import YouTubeUploader
|
||||
from karaoke_gen.services.distribution.organizer import FileOrganizer
|
||||
from karaoke_gen.services.distribution.cdg import CDGGenerator
|
||||
from karaoke_gen.services.distribution.txt import TXTGenerator
|
||||
from karaoke_gen.services.distribution.notifier import Notifier
|
||||
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
import shutil
|
||||
import glob
|
||||
import re
|
||||
import subprocess
|
||||
from typing import Dict, Any, Optional, List, Tuple
|
||||
|
||||
|
||||
class DistributionService:
|
||||
"""
|
||||
Service for distribution operations including file organization, YouTube uploading, and notifications.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the distribution service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Initialize components
|
||||
self.youtube_uploader = YouTubeUploader(config)
|
||||
self.file_organizer = FileOrganizer(config)
|
||||
self.cdg_generator = CDGGenerator(config)
|
||||
self.txt_generator = TXTGenerator(config)
|
||||
self.notifier = Notifier(config)
|
||||
|
||||
# Detect best available AAC codec
|
||||
self.aac_codec = self._detect_best_aac_codec()
|
||||
|
||||
async def distribute(self, track: Track, replace_existing: bool = False) -> Track:
|
||||
"""
|
||||
Distribute the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
replace_existing: Whether to replace existing files
|
||||
|
||||
Returns:
|
||||
The track with updated distribution information
|
||||
"""
|
||||
self.logger.info(f"Distributing {track.base_name}")
|
||||
|
||||
# Remux and encode output video files
|
||||
track = await self._remux_and_encode_output_video_files(track)
|
||||
|
||||
# Create CDG zip file if enabled
|
||||
if self.config.enable_cdg:
|
||||
track = self.cdg_generator.create_cdg_zip_file(track)
|
||||
|
||||
# Create TXT zip file if enabled
|
||||
if self.config.enable_txt:
|
||||
track = self.txt_generator.create_txt_zip_file(track)
|
||||
|
||||
# Get brand code
|
||||
if self.config.keep_brand_code:
|
||||
track.brand_code = self.file_organizer.get_existing_brand_code(track)
|
||||
else:
|
||||
track.brand_code = self.file_organizer.get_next_brand_code()
|
||||
|
||||
# Move files to brand code folder
|
||||
if track.brand_code and self.config.organised_dir:
|
||||
track = self.file_organizer.move_files_to_brand_code_folder(track, track.brand_code)
|
||||
|
||||
# Copy final files to public share directory
|
||||
if self.config.public_share_dir and track.brand_code:
|
||||
track = self.file_organizer.copy_final_files_to_public_share_dirs(track, track.brand_code)
|
||||
|
||||
# Sync public share directory to rclone destination
|
||||
if self.config.rclone_destination and self.config.public_share_dir:
|
||||
self.file_organizer.sync_public_share_dir_to_rclone_destination()
|
||||
|
||||
# Upload to YouTube
|
||||
if self.config.youtube_client_secrets_file and track.final_video_mkv:
|
||||
thumbnail_file = os.path.join(track.track_output_dir, f"{track.base_name} (Title).jpg")
|
||||
if not os.path.isfile(thumbnail_file):
|
||||
thumbnail_file = None
|
||||
|
||||
track.youtube_url = self.youtube_uploader.upload_video(
|
||||
video_file=track.final_video_mkv,
|
||||
thumbnail_file=thumbnail_file,
|
||||
artist=track.artist,
|
||||
title=track.title,
|
||||
replace_existing=replace_existing
|
||||
)
|
||||
|
||||
# Generate sharing link
|
||||
if self.config.organised_dir_rclone_root and track.brand_code and track.new_brand_code_dir_path:
|
||||
track.brand_code_dir_sharing_link = self.file_organizer.generate_organised_folder_sharing_link(track)
|
||||
|
||||
# Post Discord notification
|
||||
if self.config.discord_webhook_url and track.youtube_url:
|
||||
self.notifier.post_discord_notification(track)
|
||||
|
||||
# Draft completion email
|
||||
if self.config.email_template_file and track.youtube_url and track.brand_code_dir_sharing_link:
|
||||
self.notifier.draft_completion_email(track)
|
||||
|
||||
return track
|
||||
|
||||
async def _remux_and_encode_output_video_files(self, track: Track) -> Track:
|
||||
"""
|
||||
Remux and encode output video files.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video file information
|
||||
"""
|
||||
self.logger.info(f"Remuxing and encoding output video files for {track.base_name}")
|
||||
|
||||
if not track.video_with_lyrics or not track.instrumental:
|
||||
self.logger.warning("No video with lyrics or instrumental audio available, cannot remux/encode")
|
||||
return track
|
||||
|
||||
# Determine output file paths
|
||||
final_video = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke Lossless 4k).mp4")
|
||||
final_video_mkv = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke Lossless 4k).mkv")
|
||||
final_video_lossy = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke Lossy 4k).mp4")
|
||||
final_video_720p = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke Lossy 720p).mp4")
|
||||
|
||||
# Check if output files already exist
|
||||
if os.path.isfile(final_video) and os.path.isfile(final_video_mkv):
|
||||
if self.config.non_interactive:
|
||||
self.logger.info(f"Non-interactive mode, automatically overwriting existing final video files")
|
||||
else:
|
||||
from karaoke_gen.utils.validation import prompt_user_bool
|
||||
if not prompt_user_bool(
|
||||
f"Found existing Final Karaoke output files. Overwrite (y) or skip (n)?",
|
||||
):
|
||||
self.logger.info(f"Skipping Karaoke MP4 remux and Final video renders, existing files will be used.")
|
||||
track.final_video = final_video
|
||||
track.final_video_mkv = final_video_mkv
|
||||
track.final_video_lossy = final_video_lossy
|
||||
track.final_video_720p = final_video_720p
|
||||
return track
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would remux and encode output video files")
|
||||
track.final_video = final_video
|
||||
track.final_video_mkv = final_video_mkv
|
||||
track.final_video_lossy = final_video_lossy
|
||||
track.final_video_720p = final_video_720p
|
||||
return track
|
||||
|
||||
try:
|
||||
# MP4 output flags for better compatibility and streaming
|
||||
mp4_flags = "-pix_fmt yuv420p -movflags +faststart+frag_keyframe+empty_moov"
|
||||
|
||||
# Path to ffmpeg
|
||||
ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Base ffmpeg command
|
||||
ffmpeg_base_command = f"{ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.logger.level == logging.DEBUG:
|
||||
ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
# Add -y if non-interactive
|
||||
if self.config.non_interactive:
|
||||
ffmpeg_base_command += " -y"
|
||||
|
||||
# Create karaoke version with instrumental audio
|
||||
karaoke_mp4 = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).mp4")
|
||||
|
||||
# Remux the video with instrumental audio
|
||||
remux_command = (
|
||||
f'{ffmpeg_base_command} -an -i "{track.video_with_lyrics}" '
|
||||
f'-vn -i "{track.instrumental}" -c:v copy -c:a pcm_s16le "{karaoke_mp4}"'
|
||||
)
|
||||
|
||||
self.logger.info(f"Remuxing video with instrumental audio: {remux_command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
remux_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await process.communicate()
|
||||
|
||||
# Prepare title and end videos
|
||||
title_video = os.path.join(track.track_output_dir, f"{track.base_name} (Title).mov")
|
||||
end_video = os.path.join(track.track_output_dir, f"{track.base_name} (End).mov")
|
||||
|
||||
# Prepare concat filter for combining videos
|
||||
env_mov_input = ""
|
||||
ffmpeg_filter = '-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]"'
|
||||
|
||||
if os.path.isfile(end_video):
|
||||
self.logger.info(f"Found end video: {end_video}, including in final MP4")
|
||||
env_mov_input = f'-i "{end_video}"'
|
||||
ffmpeg_filter = '-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]"'
|
||||
|
||||
# Create lossless MP4
|
||||
lossless_mp4_command = (
|
||||
f'{ffmpeg_base_command} -i "{title_video}" -i "{karaoke_mp4}" {env_mov_input} '
|
||||
f'{ffmpeg_filter} -map "[outv]" -map "[outa]" -c:v libx264 -c:a pcm_s16le '
|
||||
f'{mp4_flags} "{final_video}"'
|
||||
)
|
||||
|
||||
self.logger.info(f"Creating MP4 version with PCM audio: {lossless_mp4_command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
lossless_mp4_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await process.communicate()
|
||||
|
||||
# Create lossy MP4
|
||||
lossy_mp4_command = (
|
||||
f'{ffmpeg_base_command} -i "{final_video}" '
|
||||
f'-c:v copy -c:a {self.aac_codec} -b:a 320k {mp4_flags} "{final_video_lossy}"'
|
||||
)
|
||||
|
||||
self.logger.info(f"Creating MP4 version with AAC audio: {lossy_mp4_command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
lossy_mp4_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await process.communicate()
|
||||
|
||||
# Create MKV with FLAC audio
|
||||
mkv_command = (
|
||||
f'{ffmpeg_base_command} -i "{final_video}" '
|
||||
f'-c:v copy -c:a flac "{final_video_mkv}"'
|
||||
)
|
||||
|
||||
self.logger.info(f"Creating MKV version with FLAC audio: {mkv_command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
mkv_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await process.communicate()
|
||||
|
||||
# Create 720p MP4
|
||||
mp4_720p_command = (
|
||||
f'{ffmpeg_base_command} -i "{final_video}" '
|
||||
f'-c:v libx264 -vf "scale=1280:720" -b:v 200k -preset medium -tune animation '
|
||||
f'-c:a {self.aac_codec} -b:a 128k {mp4_flags} "{final_video_720p}"'
|
||||
)
|
||||
|
||||
self.logger.info(f"Creating 720p version: {mp4_720p_command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
mp4_720p_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
await process.communicate()
|
||||
|
||||
# Update track with file paths
|
||||
track.final_video = final_video
|
||||
track.final_video_mkv = final_video_mkv
|
||||
track.final_video_lossy = final_video_lossy
|
||||
track.final_video_720p = final_video_720p
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to remux and encode output video files: {str(e)}")
|
||||
raise DistributionError(f"Failed to remux and encode output video files: {str(e)}")
|
||||
|
||||
def _detect_best_aac_codec(self) -> str:
|
||||
"""
|
||||
Detect the best available AAC codec (aac_at > libfdk_aac > aac).
|
||||
|
||||
Returns:
|
||||
The best available AAC codec
|
||||
"""
|
||||
self.logger.info("Detecting best available AAC codec...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info("DRY RUN: Would detect best available AAC codec")
|
||||
return "aac"
|
||||
|
||||
try:
|
||||
# Run ffmpeg -codecs to get available codecs
|
||||
codec_check_command = "ffmpeg -codecs"
|
||||
result = subprocess.run(codec_check_command, shell=True, capture_output=True, text=True)
|
||||
output = result.stdout
|
||||
|
||||
if "aac_at" in output:
|
||||
self.logger.info("Using aac_at codec (best quality)")
|
||||
return "aac_at"
|
||||
elif "libfdk_aac" in output:
|
||||
self.logger.info("Using libfdk_aac codec (good quality)")
|
||||
return "libfdk_aac"
|
||||
else:
|
||||
self.logger.info("Using built-in aac codec (basic quality)")
|
||||
return "aac"
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to detect best AAC codec: {str(e)}")
|
||||
return "aac"
|
||||
@@ -0,0 +1,116 @@
|
||||
"""
|
||||
TXT file generation functionality for the distribution service.
|
||||
"""
|
||||
|
||||
import os
|
||||
import zipfile
|
||||
import logging
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
from lyrics_converter import LyricsConverter
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DistributionError
|
||||
|
||||
|
||||
class TXTGenerator:
|
||||
"""
|
||||
Class for handling TXT file generation.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the TXT generator.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
def create_txt_zip_file(self, track: Track) -> Track:
|
||||
"""
|
||||
Create a TXT zip file for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated TXT zip file information
|
||||
|
||||
Raises:
|
||||
DistributionError: If creating the TXT zip file fails
|
||||
"""
|
||||
self.logger.info(f"Creating TXT ZIP file...")
|
||||
|
||||
if not self.config.enable_txt:
|
||||
self.logger.warning("TXT generation not enabled, skipping")
|
||||
return track
|
||||
|
||||
if not track.processed_lyrics:
|
||||
self.logger.warning("No processed lyrics available, cannot create TXT file")
|
||||
return track
|
||||
|
||||
# Determine the output file paths
|
||||
txt_zip_file = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke TXT).zip")
|
||||
txt_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).txt")
|
||||
mp3_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).mp3")
|
||||
lrc_file = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# Check if TXT file already exists, if so, ask user to overwrite or skip
|
||||
if os.path.isfile(txt_zip_file):
|
||||
if self.config.non_interactive:
|
||||
self.logger.info(f"Non-interactive mode, automatically overwriting existing TXT ZIP file: {txt_zip_file}")
|
||||
else:
|
||||
from karaoke_gen.utils.validation import prompt_user_bool
|
||||
if not prompt_user_bool(
|
||||
f"Found existing TXT ZIP file: {txt_zip_file}. Overwrite (y) or skip (n)?",
|
||||
):
|
||||
self.logger.info(f"Skipping TXT ZIP file creation, existing file will be used.")
|
||||
track.final_karaoke_txt_zip = txt_zip_file
|
||||
return track
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would create TXT ZIP file: {txt_zip_file}")
|
||||
track.final_karaoke_txt_zip = txt_zip_file
|
||||
return track
|
||||
|
||||
try:
|
||||
# Create the LRC file if it doesn't exist
|
||||
if not os.path.isfile(lrc_file) and track.processed_lyrics:
|
||||
with open(lrc_file, "w", encoding="utf-8") as f:
|
||||
f.write(track.processed_lyrics)
|
||||
|
||||
# Convert LRC to TXT format
|
||||
self.logger.info(f"Running karaoke-converter to convert MidiCo LRC file {lrc_file} to TXT format")
|
||||
txt_converter = LyricsConverter(output_format="txt", filepath=lrc_file)
|
||||
converted_txt = txt_converter.convert_file()
|
||||
|
||||
# Write the TXT file
|
||||
with open(txt_file, "w", encoding="utf-8") as txt_file_handle:
|
||||
txt_file_handle.write(converted_txt)
|
||||
self.logger.info(f"TXT file written: {txt_file}")
|
||||
|
||||
# Ensure the MP3 file exists
|
||||
if not os.path.isfile(mp3_file):
|
||||
self.logger.warning(f"MP3 file not found: {mp3_file}, cannot create TXT ZIP file")
|
||||
return track
|
||||
|
||||
# Create the ZIP file containing the MP3 and TXT files
|
||||
self.logger.info(f"Creating ZIP file containing {mp3_file} and {txt_file}")
|
||||
with zipfile.ZipFile(txt_zip_file, "w") as zipf:
|
||||
zipf.write(mp3_file, os.path.basename(mp3_file))
|
||||
zipf.write(txt_file, os.path.basename(txt_file))
|
||||
|
||||
# Verify the TXT ZIP file was created
|
||||
if not os.path.isfile(txt_zip_file):
|
||||
raise DistributionError(f"Failed to create TXT ZIP file: {txt_zip_file}")
|
||||
|
||||
self.logger.info(f"TXT ZIP file created: {txt_zip_file}")
|
||||
track.final_karaoke_txt_zip = txt_zip_file
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create TXT ZIP file: {str(e)}")
|
||||
raise DistributionError(f"Failed to create TXT ZIP file: {str(e)}")
|
||||
@@ -0,0 +1,327 @@
|
||||
"""
|
||||
YouTube uploading functionality for the distribution service.
|
||||
"""
|
||||
|
||||
import os
|
||||
import pickle
|
||||
import logging
|
||||
from typing import Optional, Dict, Any, List, Tuple
|
||||
|
||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||
from google.auth.transport.requests import Request
|
||||
from googleapiclient.discovery import build
|
||||
from googleapiclient.http import MediaFileUpload
|
||||
from google.oauth2.credentials import Credentials
|
||||
from thefuzz import fuzz
|
||||
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.exceptions import YouTubeError
|
||||
|
||||
|
||||
class YouTubeUploader:
|
||||
"""
|
||||
Class for handling YouTube uploads and related operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the YouTube uploader.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
self.youtube_url_prefix = "https://www.youtube.com/watch?v="
|
||||
self.youtube_token_file = "/tmp/karaoke-finalise-youtube-token.pickle"
|
||||
|
||||
def authenticate_youtube(self) -> Any:
|
||||
"""
|
||||
Authenticate and return a YouTube service object.
|
||||
|
||||
Returns:
|
||||
The authenticated YouTube service
|
||||
|
||||
Raises:
|
||||
YouTubeError: If authentication fails
|
||||
"""
|
||||
self.logger.info("Authenticating with YouTube...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info("DRY RUN: Would authenticate with YouTube")
|
||||
return None
|
||||
|
||||
try:
|
||||
credentials = None
|
||||
|
||||
# Token file stores the user's access and refresh tokens for YouTube.
|
||||
if os.path.exists(self.youtube_token_file):
|
||||
with open(self.youtube_token_file, "rb") as token:
|
||||
credentials = pickle.load(token)
|
||||
|
||||
# If there are no valid credentials, let the user log in.
|
||||
if not credentials or not credentials.valid:
|
||||
if credentials and credentials.expired and credentials.refresh_token:
|
||||
credentials.refresh(Request())
|
||||
else:
|
||||
flow = InstalledAppFlow.from_client_secrets_file(
|
||||
self.config.youtube_client_secrets_file,
|
||||
scopes=["https://www.googleapis.com/auth/youtube"]
|
||||
)
|
||||
credentials = flow.run_local_server(port=0) # This will open a browser for authentication
|
||||
|
||||
# Save the credentials for the next run
|
||||
with open(self.youtube_token_file, "wb") as token:
|
||||
pickle.dump(credentials, token)
|
||||
|
||||
return build("youtube", "v3", credentials=credentials)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to authenticate with YouTube: {str(e)}")
|
||||
raise YouTubeError(f"Failed to authenticate with YouTube: {str(e)}")
|
||||
|
||||
def get_channel_id(self) -> Optional[str]:
|
||||
"""
|
||||
Get the authenticated user's channel ID.
|
||||
|
||||
Returns:
|
||||
The channel ID or None if not found
|
||||
|
||||
Raises:
|
||||
YouTubeError: If getting the channel ID fails
|
||||
"""
|
||||
self.logger.info("Getting YouTube channel ID...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info("DRY RUN: Would get YouTube channel ID")
|
||||
return "DUMMY_CHANNEL_ID"
|
||||
|
||||
try:
|
||||
youtube = self.authenticate_youtube()
|
||||
|
||||
# Get the authenticated user's channel
|
||||
request = youtube.channels().list(part="snippet", mine=True)
|
||||
response = request.execute()
|
||||
|
||||
# Extract the channel ID
|
||||
if "items" in response:
|
||||
channel_id = response["items"][0]["id"]
|
||||
self.logger.info(f"Found YouTube channel ID: {channel_id}")
|
||||
return channel_id
|
||||
else:
|
||||
self.logger.warning("No YouTube channel found for the authenticated user")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to get YouTube channel ID: {str(e)}")
|
||||
raise YouTubeError(f"Failed to get YouTube channel ID: {str(e)}")
|
||||
|
||||
def check_if_video_title_exists(self, youtube_title: str) -> Tuple[bool, Optional[str]]:
|
||||
"""
|
||||
Check if a video with the given title already exists on the authenticated user's channel.
|
||||
|
||||
Args:
|
||||
youtube_title: The title to check
|
||||
|
||||
Returns:
|
||||
A tuple of (exists, video_id) where exists is True if the video exists and video_id is the ID of the video
|
||||
|
||||
Raises:
|
||||
YouTubeError: If checking for the video fails
|
||||
"""
|
||||
self.logger.info(f"Checking if video with title '{youtube_title}' exists on YouTube channel...")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would check if video with title '{youtube_title}' exists on YouTube channel")
|
||||
return False, None
|
||||
|
||||
try:
|
||||
youtube = self.authenticate_youtube()
|
||||
channel_id = self.get_channel_id()
|
||||
|
||||
if not channel_id:
|
||||
self.logger.warning("No YouTube channel ID found, cannot check for existing videos")
|
||||
return False, None
|
||||
|
||||
self.logger.info(f"Searching YouTube channel {channel_id} for title: {youtube_title}")
|
||||
request = youtube.search().list(
|
||||
part="snippet",
|
||||
channelId=channel_id,
|
||||
q=youtube_title,
|
||||
type="video",
|
||||
maxResults=10
|
||||
)
|
||||
response = request.execute()
|
||||
|
||||
# Check if any videos were found
|
||||
if "items" in response and len(response["items"]) > 0:
|
||||
for item in response["items"]:
|
||||
found_title = item["snippet"]["title"]
|
||||
similarity_score = fuzz.ratio(youtube_title.lower(), found_title.lower())
|
||||
if similarity_score >= 70: # 70% similarity
|
||||
found_id = item["id"]["videoId"]
|
||||
self.logger.info(
|
||||
f"Potential match found on YouTube channel with ID: {found_id} and title: {found_title} (similarity: {similarity_score}%)"
|
||||
)
|
||||
|
||||
# In non-interactive mode, automatically confirm if similarity is high enough
|
||||
if self.config.non_interactive:
|
||||
self.logger.info(f"Non-interactive mode, automatically confirming match with similarity score {similarity_score}%")
|
||||
return True, found_id
|
||||
|
||||
confirmation = input(f"Is '{found_title}' the video you are finalising? (y/n): ").strip().lower()
|
||||
if confirmation == "y":
|
||||
return True, found_id
|
||||
|
||||
self.logger.info(f"No matching video found with title: {youtube_title}")
|
||||
return False, None
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to check if video exists on YouTube: {str(e)}")
|
||||
raise YouTubeError(f"Failed to check if video exists on YouTube: {str(e)}")
|
||||
|
||||
def delete_youtube_video(self, video_id: str) -> bool:
|
||||
"""
|
||||
Delete a YouTube video by its ID.
|
||||
|
||||
Args:
|
||||
video_id: The YouTube video ID to delete
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
|
||||
Raises:
|
||||
YouTubeError: If deleting the video fails
|
||||
"""
|
||||
self.logger.info(f"Deleting YouTube video with ID: {video_id}")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would delete YouTube video with ID: {video_id}")
|
||||
return True
|
||||
|
||||
try:
|
||||
youtube = self.authenticate_youtube()
|
||||
youtube.videos().delete(id=video_id).execute()
|
||||
self.logger.info(f"Successfully deleted YouTube video with ID: {video_id}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to delete YouTube video with ID {video_id}: {e}")
|
||||
return False
|
||||
|
||||
def truncate_to_nearest_word(self, title: str, max_length: int) -> str:
|
||||
"""
|
||||
Truncate a string to the nearest word within the maximum length.
|
||||
|
||||
Args:
|
||||
title: The string to truncate
|
||||
max_length: The maximum length
|
||||
|
||||
Returns:
|
||||
The truncated string
|
||||
"""
|
||||
if len(title) <= max_length:
|
||||
return title
|
||||
|
||||
truncated_title = title[:max_length].rsplit(" ", 1)[0]
|
||||
if len(truncated_title) < max_length:
|
||||
truncated_title += " ..."
|
||||
|
||||
return truncated_title
|
||||
|
||||
def upload_video(
|
||||
self,
|
||||
video_file: str,
|
||||
thumbnail_file: Optional[str],
|
||||
artist: str,
|
||||
title: str,
|
||||
replace_existing: bool = False
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Upload a video to YouTube with the given title and thumbnail.
|
||||
|
||||
Args:
|
||||
video_file: The path to the video file
|
||||
thumbnail_file: The path to the thumbnail file
|
||||
artist: The artist name
|
||||
title: The track title
|
||||
replace_existing: Whether to replace an existing video
|
||||
|
||||
Returns:
|
||||
The YouTube URL of the uploaded video or None if upload failed
|
||||
|
||||
Raises:
|
||||
YouTubeError: If uploading the video fails
|
||||
"""
|
||||
self.logger.info(f"Uploading video to YouTube: {video_file}")
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"DRY RUN: Would upload {video_file} to YouTube with thumbnail {thumbnail_file}")
|
||||
return f"{self.youtube_url_prefix}DUMMY_VIDEO_ID"
|
||||
|
||||
try:
|
||||
youtube_title = f"{artist} - {title} (Karaoke)"
|
||||
|
||||
# Truncate title to the nearest whole word and add ellipsis if needed
|
||||
max_length = 95
|
||||
youtube_title = self.truncate_to_nearest_word(youtube_title, max_length)
|
||||
|
||||
# Check if video already exists
|
||||
exists, video_id = self.check_if_video_title_exists(youtube_title)
|
||||
if exists:
|
||||
if replace_existing:
|
||||
self.logger.info(f"Video already exists on YouTube, deleting before re-upload: {self.youtube_url_prefix}{video_id}")
|
||||
if self.delete_youtube_video(video_id):
|
||||
self.logger.info(f"Successfully deleted existing video, proceeding with upload")
|
||||
else:
|
||||
self.logger.error(f"Failed to delete existing video, aborting upload")
|
||||
return None
|
||||
else:
|
||||
self.logger.warning(f"Video already exists on YouTube, skipping upload: {self.youtube_url_prefix}{video_id}")
|
||||
return f"{self.youtube_url_prefix}{video_id}"
|
||||
|
||||
# Load description from file if available
|
||||
youtube_description = f"Karaoke version of {artist} - {title} created using karaoke-gen python package."
|
||||
if self.config.youtube_description_file and os.path.isfile(self.config.youtube_description_file):
|
||||
with open(self.config.youtube_description_file, "r") as f:
|
||||
youtube_description = f.read()
|
||||
|
||||
youtube_category_id = "10" # Category ID for Music
|
||||
youtube_keywords = ["karaoke", "music", "singing", "instrumental", "lyrics", artist, title]
|
||||
|
||||
self.logger.info(f"Authenticating with YouTube...")
|
||||
youtube = self.authenticate_youtube()
|
||||
|
||||
body = {
|
||||
"snippet": {
|
||||
"title": youtube_title,
|
||||
"description": youtube_description,
|
||||
"tags": youtube_keywords,
|
||||
"categoryId": youtube_category_id,
|
||||
},
|
||||
"status": {"privacyStatus": "public"},
|
||||
}
|
||||
|
||||
# Use MediaFileUpload to handle the video file
|
||||
media_file = MediaFileUpload(video_file, resumable=True)
|
||||
|
||||
# Call the API's videos.insert method to create and upload the video.
|
||||
self.logger.info(f"Uploading video to YouTube...")
|
||||
request = youtube.videos().insert(part="snippet,status", body=body, media_body=media_file)
|
||||
response = request.execute()
|
||||
|
||||
video_id = response.get("id")
|
||||
youtube_url = f"{self.youtube_url_prefix}{video_id}"
|
||||
self.logger.info(f"Uploaded video to YouTube: {youtube_url}")
|
||||
|
||||
# Uploading the thumbnail
|
||||
if thumbnail_file and os.path.isfile(thumbnail_file):
|
||||
media_thumbnail = MediaFileUpload(thumbnail_file, mimetype="image/jpeg")
|
||||
youtube.thumbnails().set(videoId=video_id, media_body=media_thumbnail).execute()
|
||||
self.logger.info(f"Uploaded thumbnail for video ID {video_id}")
|
||||
|
||||
return youtube_url
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to upload video to YouTube: {str(e)}")
|
||||
raise YouTubeError(f"Failed to upload video to YouTube: {str(e)}")
|
||||
@@ -0,0 +1,3 @@
|
||||
from karaoke_gen.services.lyrics.service import LyricsService
|
||||
from karaoke_gen.services.lyrics.transcriber import LyricsTranscriber
|
||||
from karaoke_gen.services.lyrics.formatter import LyricsFormatter
|
||||
@@ -0,0 +1,162 @@
|
||||
import os
|
||||
import glob
|
||||
import shutil
|
||||
import datetime
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import FormattingError
|
||||
|
||||
|
||||
class LyricsFormatter:
|
||||
"""
|
||||
Handles lyrics formatting and backup operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the lyrics formatter.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
async def format_lyrics(self, track):
|
||||
"""
|
||||
Format lyrics for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated formatting information
|
||||
"""
|
||||
self.logger.info(f"Formatting lyrics for {track.base_name}")
|
||||
|
||||
# Skip if no lyrics
|
||||
if not track.lyrics:
|
||||
self.logger.warning("No lyrics found, cannot format")
|
||||
return track
|
||||
|
||||
# Skip if already formatted
|
||||
if track.processed_lyrics and track.processed_lyrics.get("formatted_lyrics"):
|
||||
self.logger.info(f"Lyrics already formatted")
|
||||
return track
|
||||
|
||||
try:
|
||||
# Read lyrics file
|
||||
if isinstance(track.lyrics, str) and os.path.isfile(track.lyrics):
|
||||
with open(track.lyrics, "r", encoding="utf-8") as f:
|
||||
lyrics_text = f.read()
|
||||
else:
|
||||
lyrics_text = track.lyrics
|
||||
|
||||
# Format lyrics
|
||||
formatted_lyrics = self._format_lyrics_text(lyrics_text)
|
||||
|
||||
# Save formatted lyrics
|
||||
formatted_lyrics_file = os.path.join(track.track_output_dir, f"{track.base_name} (Formatted Lyrics).txt")
|
||||
if not self.config.dry_run:
|
||||
with open(formatted_lyrics_file, "w", encoding="utf-8") as f:
|
||||
f.write(formatted_lyrics)
|
||||
|
||||
# Update track
|
||||
if not track.processed_lyrics:
|
||||
track.processed_lyrics = {}
|
||||
|
||||
track.processed_lyrics["formatted_lyrics"] = formatted_lyrics
|
||||
track.processed_lyrics["formatted_lyrics_file"] = formatted_lyrics_file
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
raise FormattingError(f"Failed to format lyrics: {str(e)}") from e
|
||||
|
||||
def _format_lyrics_text(self, lyrics_text):
|
||||
"""
|
||||
Format lyrics text.
|
||||
|
||||
Args:
|
||||
lyrics_text: The lyrics text to format
|
||||
|
||||
Returns:
|
||||
The formatted lyrics text
|
||||
"""
|
||||
# Remove extra whitespace
|
||||
formatted_text = lyrics_text.strip()
|
||||
|
||||
# Split into lines
|
||||
lines = formatted_text.split("\n")
|
||||
|
||||
# Remove empty lines at the beginning and end
|
||||
while lines and not lines[0].strip():
|
||||
lines.pop(0)
|
||||
|
||||
while lines and not lines[-1].strip():
|
||||
lines.pop()
|
||||
|
||||
# Remove duplicate empty lines
|
||||
formatted_lines = []
|
||||
prev_empty = False
|
||||
for line in lines:
|
||||
is_empty = not line.strip()
|
||||
if not (is_empty and prev_empty):
|
||||
formatted_lines.append(line)
|
||||
prev_empty = is_empty
|
||||
|
||||
# Join lines
|
||||
formatted_text = "\n".join(formatted_lines)
|
||||
|
||||
return formatted_text
|
||||
|
||||
async def backup_existing_outputs(self, track):
|
||||
"""
|
||||
Backup existing outputs for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated backup information
|
||||
"""
|
||||
self.logger.info(f"Backing up existing outputs for {track.base_name}")
|
||||
|
||||
# Create backup directory
|
||||
backup_dir = os.path.join(track.track_output_dir, "backup_" + self._get_timestamp())
|
||||
if not self.config.dry_run:
|
||||
os.makedirs(backup_dir, exist_ok=True)
|
||||
|
||||
# Find existing files to backup
|
||||
files_to_backup = []
|
||||
|
||||
# Lyrics files
|
||||
lyrics_files = glob.glob(os.path.join(track.track_output_dir, "*.lrc"))
|
||||
files_to_backup.extend(lyrics_files)
|
||||
|
||||
# Video files
|
||||
video_files = glob.glob(os.path.join(track.track_output_dir, "*.mkv"))
|
||||
video_files.extend(glob.glob(os.path.join(track.track_output_dir, "*.mp4")))
|
||||
files_to_backup.extend(video_files)
|
||||
|
||||
# Subtitle files
|
||||
subtitle_files = glob.glob(os.path.join(track.track_output_dir, "*.srt"))
|
||||
subtitle_files.extend(glob.glob(os.path.join(track.track_output_dir, "*.ass")))
|
||||
files_to_backup.extend(subtitle_files)
|
||||
|
||||
# Backup files
|
||||
for file_path in files_to_backup:
|
||||
if os.path.exists(file_path) and not self.config.dry_run:
|
||||
backup_path = os.path.join(backup_dir, os.path.basename(file_path))
|
||||
shutil.copy2(file_path, backup_path)
|
||||
self.logger.info(f"Backed up {file_path} to {backup_path}")
|
||||
|
||||
return track
|
||||
|
||||
def _get_timestamp(self):
|
||||
"""
|
||||
Get a timestamp string.
|
||||
|
||||
Returns:
|
||||
A timestamp string
|
||||
"""
|
||||
return datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
@@ -0,0 +1,239 @@
|
||||
import logging
|
||||
import os
|
||||
import glob
|
||||
import shutil
|
||||
from typing import Dict, Any, Optional
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import LyricsError
|
||||
from karaoke_gen.services.lyrics.transcriber import LyricsTranscriber
|
||||
from karaoke_gen.services.lyrics.formatter import LyricsFormatter
|
||||
import datetime
|
||||
|
||||
|
||||
class LyricsService:
|
||||
"""
|
||||
Service for lyrics processing operations including transcription.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the lyrics service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Initialize components
|
||||
self.transcriber = LyricsTranscriber(config)
|
||||
self.formatter = LyricsFormatter(config)
|
||||
|
||||
async def process_lyrics(self, track: Track) -> Track:
|
||||
"""
|
||||
Process lyrics for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated lyrics information
|
||||
"""
|
||||
if self.config.skip_lyrics:
|
||||
self.logger.info(f"Skipping lyrics processing for {track.base_name}")
|
||||
return track
|
||||
|
||||
self.logger.info(f"Processing lyrics for {track.base_name}")
|
||||
|
||||
# Check for existing lyrics files
|
||||
track = await self._check_existing_lyrics(track)
|
||||
if track.processed_lyrics:
|
||||
self.logger.info("Found existing lyrics files, skipping transcription")
|
||||
return track
|
||||
|
||||
# The LyricsTranscriber library handles both fetching lyrics and transcribing,
|
||||
# so we don't need to do the fetching separately
|
||||
if not self.config.skip_transcription:
|
||||
track = await self.transcriber.transcribe_lyrics(track)
|
||||
|
||||
return track
|
||||
|
||||
async def _check_existing_lyrics(self, track: Track) -> Track:
|
||||
"""
|
||||
Check for existing lyrics files.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated lyrics information if existing files are found
|
||||
"""
|
||||
self.logger.info(f"Checking for existing lyrics files for {track.base_name}")
|
||||
|
||||
# Check for existing files in parent directory
|
||||
parent_video_path = os.path.join(track.track_output_dir, f"{track.base_name} (With Vocals).mkv")
|
||||
parent_lrc_path = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# Check lyrics directory for existing files
|
||||
lyrics_dir = os.path.join(track.track_output_dir, "lyrics")
|
||||
lyrics_video_path = os.path.join(lyrics_dir, f"{track.base_name} (With Vocals).mkv")
|
||||
lyrics_lrc_path = os.path.join(lyrics_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# If files exist in parent directory, use them
|
||||
if os.path.exists(parent_video_path) and os.path.exists(parent_lrc_path):
|
||||
self.logger.info(f"Found existing video and LRC files in parent directory")
|
||||
track.processed_lyrics = {
|
||||
"lrc_filepath": parent_lrc_path,
|
||||
"ass_filepath": parent_video_path,
|
||||
}
|
||||
return track
|
||||
|
||||
# If files exist in lyrics directory, copy to parent and use them
|
||||
if os.path.exists(lyrics_video_path) and os.path.exists(lyrics_lrc_path):
|
||||
self.logger.info(f"Found existing video and LRC files in lyrics directory, copying to parent")
|
||||
os.makedirs(track.track_output_dir, exist_ok=True)
|
||||
|
||||
# Copy files to parent directory
|
||||
shutil.copy2(lyrics_video_path, parent_video_path)
|
||||
shutil.copy2(lyrics_lrc_path, parent_lrc_path)
|
||||
|
||||
track.processed_lyrics = {
|
||||
"lrc_filepath": parent_lrc_path,
|
||||
"ass_filepath": parent_video_path,
|
||||
}
|
||||
return track
|
||||
|
||||
return track
|
||||
|
||||
async def backup_and_prepare_for_edit(self, track: Track) -> Track:
|
||||
"""
|
||||
Backup existing outputs and prepare for lyrics editing.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated backup information
|
||||
"""
|
||||
self.logger.info(f"Backing up and preparing for lyrics editing for {track.base_name}")
|
||||
|
||||
# Create backup directory
|
||||
backup_dir = os.path.join(track.track_output_dir, "backups")
|
||||
if not os.path.exists(backup_dir):
|
||||
os.makedirs(backup_dir)
|
||||
|
||||
# Create versioned backup directory
|
||||
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
version_dir = os.path.join(backup_dir, f"version_{timestamp}")
|
||||
os.makedirs(version_dir)
|
||||
|
||||
# Backup existing files
|
||||
files_to_backup = []
|
||||
|
||||
# Backup processed lyrics
|
||||
if track.processed_lyrics:
|
||||
for key, value in track.processed_lyrics.items():
|
||||
if isinstance(value, str) and os.path.isfile(value):
|
||||
files_to_backup.append(value)
|
||||
|
||||
# Backup videos
|
||||
for video_attr in ["video_with_lyrics", "final_video"]:
|
||||
video_path = getattr(track, video_attr, None)
|
||||
if video_path and os.path.isfile(video_path):
|
||||
files_to_backup.append(video_path)
|
||||
|
||||
# Copy files to backup directory
|
||||
for file_path in files_to_backup:
|
||||
backup_path = os.path.join(version_dir, os.path.basename(file_path))
|
||||
shutil.copy2(file_path, backup_path)
|
||||
self.logger.info(f"Backed up {file_path} to {backup_path}")
|
||||
|
||||
# Prepare input audio file for editing
|
||||
if track.instrumental and os.path.isfile(track.instrumental):
|
||||
edit_audio = os.path.join(track.track_output_dir, f"{track.base_name} (Edit).wav")
|
||||
shutil.copy2(track.instrumental, edit_audio)
|
||||
track.metadata["edit_audio"] = edit_audio
|
||||
self.logger.info(f"Prepared audio for editing: {edit_audio}")
|
||||
|
||||
# Store backup information
|
||||
track.metadata["backup_dir"] = backup_dir
|
||||
track.metadata["last_backup"] = version_dir
|
||||
|
||||
return track
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the lyrics service.
|
||||
"""
|
||||
self.logger.info("Cleaning up lyrics service resources")
|
||||
|
||||
# Close any open resources
|
||||
if hasattr(self, 'transcriber') and self.transcriber:
|
||||
await self.transcriber.cleanup()
|
||||
|
||||
if hasattr(self, 'formatter') and self.formatter:
|
||||
await self.formatter.cleanup()
|
||||
|
||||
self.logger.info("Lyrics service cleanup complete")
|
||||
|
||||
async def _find_input_audio_file(self, track: Track) -> Track:
|
||||
"""
|
||||
Find the input audio file for lyrics editing.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated input audio information
|
||||
"""
|
||||
self.logger.info(f"Finding input audio file for {track.base_name}")
|
||||
|
||||
# Look for WAV file
|
||||
wav_files = glob.glob(os.path.join(track.track_output_dir, "*.wav"))
|
||||
if wav_files:
|
||||
track.input_audio_wav = wav_files[0]
|
||||
self.logger.info(f"Found input audio file: {track.input_audio_wav}")
|
||||
return track
|
||||
|
||||
# Look for other audio files
|
||||
audio_extensions = ['.mp3', '.flac', '.ogg', '.m4a', '.aac']
|
||||
for ext in audio_extensions:
|
||||
audio_files = glob.glob(os.path.join(track.track_output_dir, f"*{ext}"))
|
||||
if audio_files:
|
||||
# Convert to WAV
|
||||
from karaoke_gen.services.audio.converter import AudioConverter
|
||||
converter = AudioConverter(self.config)
|
||||
track.input_media = audio_files[0]
|
||||
track = await converter.convert_to_wav(track)
|
||||
self.logger.info(f"Converted audio file to WAV: {track.input_audio_wav}")
|
||||
return track
|
||||
|
||||
self.logger.warning(f"No input audio file found for {track.base_name}")
|
||||
return track
|
||||
|
||||
def _get_timestamp(self) -> str:
|
||||
"""
|
||||
Get a timestamp string for backup directory naming.
|
||||
|
||||
Returns:
|
||||
A timestamp string
|
||||
"""
|
||||
return datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
|
||||
def _sanitize_filename(self, filename: str) -> str:
|
||||
"""
|
||||
Sanitize a filename by removing invalid characters.
|
||||
|
||||
Args:
|
||||
filename: The filename to sanitize
|
||||
|
||||
Returns:
|
||||
The sanitized filename
|
||||
"""
|
||||
# Replace problematic characters with underscores
|
||||
for char in ["\\", "/", ":", "*", "?", '"', "<", ">", "|"]:
|
||||
filename = filename.replace(char, "_")
|
||||
# Remove any trailing periods or spaces
|
||||
filename = filename.rstrip(". ")
|
||||
return filename
|
||||
@@ -0,0 +1,177 @@
|
||||
import os
|
||||
import shutil
|
||||
from dotenv import load_dotenv
|
||||
from lyrics_transcriber import LyricsTranscriber as LyricsTranscriberLib
|
||||
from lyrics_transcriber import OutputConfig, TranscriberConfig, LyricsConfig
|
||||
from lyrics_transcriber.core.controller import LyricsControllerResult
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import TranscriptionError
|
||||
|
||||
|
||||
class LyricsTranscriber:
|
||||
"""
|
||||
Handles lyrics transcription and synchronization.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the lyrics transcriber.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
async def transcribe_lyrics(self, track):
|
||||
"""
|
||||
Transcribe lyrics for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated transcription information
|
||||
"""
|
||||
self.logger.info(f"Transcribing lyrics for {track.base_name}")
|
||||
|
||||
if not track.input_audio_wav or not os.path.exists(track.input_audio_wav):
|
||||
self.logger.warning("No input audio file found, cannot transcribe")
|
||||
return track
|
||||
|
||||
try:
|
||||
# Check for existing files first using sanitized names
|
||||
parent_video_path = os.path.join(track.track_output_dir, f"{track.base_name} (With Vocals).mkv")
|
||||
parent_lrc_path = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# Check lyrics directory for existing files
|
||||
lyrics_dir = os.path.join(track.track_output_dir, "lyrics")
|
||||
lyrics_video_path = os.path.join(lyrics_dir, f"{track.base_name} (With Vocals).mkv")
|
||||
lyrics_lrc_path = os.path.join(lyrics_dir, f"{track.base_name} (Karaoke).lrc")
|
||||
|
||||
# If files exist in parent directory, return early
|
||||
if os.path.exists(parent_video_path) and os.path.exists(parent_lrc_path):
|
||||
self.logger.info(f"Found existing video and LRC files in parent directory, skipping transcription")
|
||||
track.processed_lyrics = {
|
||||
"lrc_filepath": parent_lrc_path,
|
||||
"ass_filepath": parent_video_path,
|
||||
}
|
||||
return track
|
||||
|
||||
# If files exist in lyrics directory, copy to parent and return
|
||||
if os.path.exists(lyrics_video_path) and os.path.exists(lyrics_lrc_path):
|
||||
self.logger.info(f"Found existing video and LRC files in lyrics directory, copying to parent")
|
||||
os.makedirs(track.track_output_dir, exist_ok=True)
|
||||
shutil.copy2(lyrics_video_path, parent_video_path)
|
||||
shutil.copy2(lyrics_lrc_path, parent_lrc_path)
|
||||
track.processed_lyrics = {
|
||||
"lrc_filepath": parent_lrc_path,
|
||||
"ass_filepath": parent_video_path,
|
||||
}
|
||||
return track
|
||||
|
||||
# Create lyrics subdirectory for new transcription
|
||||
os.makedirs(lyrics_dir, exist_ok=True)
|
||||
self.logger.info(f"Created lyrics directory: {lyrics_dir}")
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
env_config = {
|
||||
"audioshake_api_token": os.getenv("AUDIOSHAKE_API_TOKEN"),
|
||||
"genius_api_token": os.getenv("GENIUS_API_TOKEN"),
|
||||
"spotify_cookie": os.getenv("SPOTIFY_COOKIE_SP_DC"),
|
||||
"runpod_api_key": os.getenv("RUNPOD_API_KEY"),
|
||||
"whisper_runpod_id": os.getenv("WHISPER_RUNPOD_ID"),
|
||||
}
|
||||
|
||||
# Create config objects for LyricsTranscriber
|
||||
transcriber_config = TranscriberConfig(
|
||||
audioshake_api_token=env_config.get("audioshake_api_token"),
|
||||
)
|
||||
|
||||
# Get lyrics artist and title from config if specified
|
||||
lyrics_artist = self.config.lyrics_artist or track.artist
|
||||
lyrics_title = self.config.lyrics_title or track.title
|
||||
|
||||
lyrics_config = LyricsConfig(
|
||||
genius_api_token=env_config.get("genius_api_token"),
|
||||
spotify_cookie=env_config.get("spotify_cookie"),
|
||||
lyrics_file=self.config.lyrics_file,
|
||||
)
|
||||
|
||||
output_config = OutputConfig(
|
||||
output_styles_json=self.config.style_params_json,
|
||||
output_dir=lyrics_dir,
|
||||
render_video=self.config.render_video,
|
||||
fetch_lyrics=True,
|
||||
run_transcription=not self.config.skip_transcription,
|
||||
run_correction=True,
|
||||
generate_plain_text=True,
|
||||
generate_lrc=True,
|
||||
generate_cdg=True,
|
||||
video_resolution="4k",
|
||||
enable_review=not self.config.skip_transcription_review,
|
||||
subtitle_offset_ms=self.config.subtitle_offset_ms,
|
||||
)
|
||||
|
||||
# Add this log entry to debug the OutputConfig
|
||||
self.logger.info(f"Instantiating LyricsTranscriber with OutputConfig: {output_config}")
|
||||
|
||||
# Initialize transcriber with new config objects
|
||||
transcriber = LyricsTranscriberLib(
|
||||
audio_filepath=track.input_audio_wav,
|
||||
artist=lyrics_artist,
|
||||
title=lyrics_title,
|
||||
transcriber_config=transcriber_config,
|
||||
lyrics_config=lyrics_config,
|
||||
output_config=output_config,
|
||||
logger=self.logger,
|
||||
)
|
||||
|
||||
# Process and get results
|
||||
results: LyricsControllerResult = transcriber.process()
|
||||
self.logger.info(f"Transcriber Results Filepaths:")
|
||||
for key, value in results.__dict__.items():
|
||||
if key.endswith("_filepath"):
|
||||
self.logger.info(f" {key}: {value}")
|
||||
|
||||
# Build output dictionary
|
||||
transcriber_outputs = {}
|
||||
if results.lrc_filepath:
|
||||
transcriber_outputs["lrc_filepath"] = results.lrc_filepath
|
||||
self.logger.info(f"Moving LRC file from {results.lrc_filepath} to {parent_lrc_path}")
|
||||
shutil.copy2(results.lrc_filepath, parent_lrc_path)
|
||||
|
||||
if results.video_filepath:
|
||||
transcriber_outputs["video_filepath"] = results.video_filepath
|
||||
self.logger.info(f"Moving video file from {results.video_filepath} to {parent_video_path}")
|
||||
shutil.copy2(results.video_filepath, parent_video_path)
|
||||
|
||||
if results.ass_filepath:
|
||||
transcriber_outputs["ass_filepath"] = results.ass_filepath
|
||||
|
||||
if results.transcription_corrected:
|
||||
transcriber_outputs["corrected_lyrics_text"] = "\n".join(
|
||||
segment.text for segment in results.transcription_corrected.corrected_segments
|
||||
)
|
||||
transcriber_outputs["corrected_lyrics_text_filepath"] = results.corrected_txt
|
||||
|
||||
if transcriber_outputs:
|
||||
self.logger.info(f"*** Transcriber Filepath Outputs: ***")
|
||||
for key, value in transcriber_outputs.items():
|
||||
if key.endswith("_filepath"):
|
||||
self.logger.info(f" {key}: {value}")
|
||||
|
||||
track.processed_lyrics = transcriber_outputs
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
raise TranscriptionError(f"Failed to transcribe lyrics: {str(e)}") from e
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the transcriber.
|
||||
"""
|
||||
self.logger.info("Cleaning up transcriber resources")
|
||||
# No resources to clean up currently
|
||||
pass
|
||||
@@ -0,0 +1,152 @@
|
||||
import os
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.services.audio.service import AudioService
|
||||
from karaoke_gen.services.lyrics.service import LyricsService
|
||||
from karaoke_gen.services.video.service import VideoService
|
||||
|
||||
|
||||
class MainService:
|
||||
"""
|
||||
Main service for orchestrating the entire karaoke preparation process.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the karaoke service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Initialize component services
|
||||
self.audio_service = AudioService(config)
|
||||
self.lyrics_service = LyricsService(config)
|
||||
self.video_service = VideoService(config)
|
||||
|
||||
async def process_track(self, track: Track) -> Track:
|
||||
"""
|
||||
Process a single track through the entire karaoke preparation pipeline.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The processed track
|
||||
"""
|
||||
self.logger.info(f"Processing track: {track.base_name}")
|
||||
|
||||
try:
|
||||
# Create output directory if it doesn't exist
|
||||
if not os.path.exists(track.track_output_dir):
|
||||
os.makedirs(track.track_output_dir)
|
||||
|
||||
# Process audio
|
||||
track = await self.audio_service.process_audio(track)
|
||||
|
||||
# Process lyrics
|
||||
track = await self.lyrics_service.process_lyrics(track)
|
||||
|
||||
# Process video
|
||||
track = await self.video_service.process_video(track)
|
||||
|
||||
self.logger.info(f"Successfully processed track: {track.base_name}")
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to process track {track.base_name}: {str(e)}")
|
||||
return track
|
||||
|
||||
async def process_tracks(self, tracks: List[Track]) -> List[Track]:
|
||||
"""
|
||||
Process multiple tracks through the entire karaoke preparation pipeline.
|
||||
|
||||
Args:
|
||||
tracks: The list of tracks to process
|
||||
|
||||
Returns:
|
||||
The list of processed tracks
|
||||
"""
|
||||
self.logger.info(f"Processing {len(tracks)} tracks")
|
||||
|
||||
processed_tracks = []
|
||||
|
||||
# Process tracks sequentially or in parallel based on configuration
|
||||
if self.config.parallel_processing:
|
||||
# Process tracks in parallel with a limit on concurrency
|
||||
semaphore = asyncio.Semaphore(self.config.max_concurrent_tracks)
|
||||
|
||||
async def process_with_semaphore(track):
|
||||
async with semaphore:
|
||||
return await self.process_track(track)
|
||||
|
||||
tasks = [process_with_semaphore(track) for track in tracks]
|
||||
processed_tracks = await asyncio.gather(*tasks)
|
||||
else:
|
||||
# Process tracks sequentially
|
||||
for track in tracks:
|
||||
processed_track = await self.process_track(track)
|
||||
processed_tracks.append(processed_track)
|
||||
|
||||
self.logger.info(f"Finished processing {len(processed_tracks)} tracks")
|
||||
return processed_tracks
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations after processing is complete.
|
||||
"""
|
||||
self.logger.info("Performing cleanup operations")
|
||||
|
||||
# Cleanup temporary files if configured
|
||||
if self.config.cleanup_temp_files:
|
||||
self.logger.info("Cleaning up temporary files")
|
||||
# Implement cleanup logic here
|
||||
|
||||
# Close any open resources
|
||||
await self.audio_service.cleanup()
|
||||
await self.lyrics_service.cleanup()
|
||||
await self.video_service.cleanup()
|
||||
|
||||
self.logger.info("Cleanup complete")
|
||||
|
||||
def get_summary(self, tracks: List[Track]) -> str:
|
||||
"""
|
||||
Generate a summary of the processed tracks.
|
||||
|
||||
Args:
|
||||
tracks: The list of processed tracks
|
||||
|
||||
Returns:
|
||||
A summary string
|
||||
"""
|
||||
summary = []
|
||||
summary.append(f"Processed {len(tracks)} tracks:")
|
||||
|
||||
for track in tracks:
|
||||
track_summary = f"- {track.base_name}:"
|
||||
|
||||
# Add audio processing summary
|
||||
if track.instrumental:
|
||||
track_summary += " [Audio: ✓]"
|
||||
else:
|
||||
track_summary += " [Audio: ✗]"
|
||||
|
||||
# Add lyrics processing summary
|
||||
if track.processed_lyrics:
|
||||
track_summary += " [Lyrics: ✓]"
|
||||
else:
|
||||
track_summary += " [Lyrics: ✗]"
|
||||
|
||||
# Add video processing summary
|
||||
if track.final_video:
|
||||
track_summary += " [Video: ✓]"
|
||||
else:
|
||||
track_summary += " [Video: ✗]"
|
||||
|
||||
summary.append(track_summary)
|
||||
|
||||
return "\n".join(summary)
|
||||
@@ -0,0 +1,3 @@
|
||||
from karaoke_gen.services.media.service import MediaService
|
||||
from karaoke_gen.services.media.downloader import MediaDownloader
|
||||
from karaoke_gen.services.media.extractor import MediaExtractor
|
||||
@@ -0,0 +1,167 @@
|
||||
import os
|
||||
import asyncio
|
||||
import mimetypes
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import MediaError
|
||||
|
||||
|
||||
class MediaDetector:
|
||||
"""
|
||||
Handles detecting media types.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the media detector.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Initialize mimetypes
|
||||
mimetypes.init()
|
||||
|
||||
async def detect_media_type(self, file_path):
|
||||
"""
|
||||
Detect the type of a media file.
|
||||
|
||||
Args:
|
||||
file_path: The path to the media file
|
||||
|
||||
Returns:
|
||||
The media type (audio, video, image, or unknown)
|
||||
"""
|
||||
self.logger.debug(f"Detecting media type for {file_path}")
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
raise MediaError(f"File not found: {file_path}")
|
||||
|
||||
# Get file extension
|
||||
_, ext = os.path.splitext(file_path)
|
||||
ext = ext.lower()
|
||||
|
||||
# Check file extension
|
||||
if ext in ['.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac']:
|
||||
self.logger.debug(f"Detected audio file by extension: {ext}")
|
||||
return "audio"
|
||||
elif ext in ['.mp4', '.avi', '.mov', '.mkv', '.webm', '.flv', '.wmv', '.m4v']:
|
||||
self.logger.debug(f"Detected video file by extension: {ext}")
|
||||
return "video"
|
||||
elif ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff']:
|
||||
self.logger.debug(f"Detected image file by extension: {ext}")
|
||||
return "image"
|
||||
|
||||
# Check mimetype
|
||||
mime_type, _ = mimetypes.guess_type(file_path)
|
||||
if mime_type:
|
||||
if mime_type.startswith('audio/'):
|
||||
self.logger.debug(f"Detected audio file by mimetype: {mime_type}")
|
||||
return "audio"
|
||||
elif mime_type.startswith('video/'):
|
||||
self.logger.debug(f"Detected video file by mimetype: {mime_type}")
|
||||
return "video"
|
||||
elif mime_type.startswith('image/'):
|
||||
self.logger.debug(f"Detected image file by mimetype: {mime_type}")
|
||||
return "image"
|
||||
|
||||
# Use ffprobe as a fallback
|
||||
media_type = await self._detect_media_type_with_ffprobe(file_path)
|
||||
if media_type:
|
||||
self.logger.debug(f"Detected {media_type} file with ffprobe")
|
||||
return media_type
|
||||
|
||||
self.logger.warning(f"Could not detect media type for {file_path}")
|
||||
return "unknown"
|
||||
|
||||
async def _detect_media_type_with_ffprobe(self, file_path):
|
||||
"""
|
||||
Detect the type of a media file using ffprobe.
|
||||
|
||||
Args:
|
||||
file_path: The path to the media file
|
||||
|
||||
Returns:
|
||||
The media type (audio, video, image, or None if detection failed)
|
||||
"""
|
||||
# Build ffprobe command
|
||||
command = f'ffprobe -v error -show_entries stream=codec_type -of default=noprint_wrappers=1 "{file_path}"'
|
||||
|
||||
try:
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
self.logger.debug(f"ffprobe failed: {stderr.decode()}")
|
||||
return None
|
||||
|
||||
output = stdout.decode()
|
||||
|
||||
if "codec_type=video" in output and "codec_type=audio" in output:
|
||||
return "video"
|
||||
elif "codec_type=audio" in output:
|
||||
return "audio"
|
||||
elif "codec_type=video" in output:
|
||||
# Check if it's a single frame (image) or a video
|
||||
duration_command = f'ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "{file_path}"'
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
duration_command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode == 0:
|
||||
try:
|
||||
duration = float(stdout.decode().strip())
|
||||
if duration < 0.1: # Very short duration, likely an image
|
||||
return "image"
|
||||
else:
|
||||
return "video"
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
|
||||
return "video" # Default to video if duration check fails
|
||||
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.logger.debug(f"Error detecting media type with ffprobe: {str(e)}")
|
||||
return None
|
||||
|
||||
async def detect_media_info(self, track: Track) -> Track:
|
||||
"""
|
||||
Detect media information for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Detecting media info for {track.base_name}")
|
||||
|
||||
# Detect media type for input media
|
||||
if track.input_media and os.path.isfile(track.input_media):
|
||||
media_type = await self.detect_media_type(track.input_media)
|
||||
track.input_media_type = media_type
|
||||
self.logger.info(f"Detected input media type: {media_type}")
|
||||
|
||||
# Detect media type for input audio
|
||||
if track.input_audio_wav and os.path.isfile(track.input_audio_wav):
|
||||
media_type = await self.detect_media_type(track.input_audio_wav)
|
||||
track.input_audio_type = media_type
|
||||
self.logger.info(f"Detected input audio type: {media_type}")
|
||||
|
||||
# Detect media type for input still image
|
||||
if track.input_still_image and os.path.isfile(track.input_still_image):
|
||||
media_type = await self.detect_media_type(track.input_still_image)
|
||||
track.input_image_type = media_type
|
||||
self.logger.info(f"Detected input image type: {media_type}")
|
||||
|
||||
return track
|
||||
@@ -0,0 +1,231 @@
|
||||
import os
|
||||
import asyncio
|
||||
import re
|
||||
import yt_dlp
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import DownloadError
|
||||
|
||||
|
||||
class MediaDownloader:
|
||||
"""
|
||||
Handles downloading media from URLs.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the media downloader.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
async def download_media(self, track):
|
||||
"""
|
||||
Download media from a URL.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Downloading media from {track.input_media}")
|
||||
|
||||
if not track.is_url:
|
||||
self.logger.warning(f"Input media is not a URL: {track.input_media}")
|
||||
return track
|
||||
|
||||
try:
|
||||
# Extract info for online media
|
||||
track = await self._extract_info_for_online_media(track)
|
||||
|
||||
# Download the video with extractor and media_id in the filename
|
||||
output_filename = f"{self._sanitize_filename(track.base_name)} ({track.extractor}"
|
||||
|
||||
# Add media_id if available
|
||||
if track.media_id:
|
||||
output_filename += f" {track.media_id}"
|
||||
|
||||
output_filename += ")"
|
||||
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
output_filename
|
||||
)
|
||||
|
||||
downloaded_file = await self._download_video(track.input_media, output_filename_no_extension)
|
||||
|
||||
# Update track information
|
||||
track.input_media = downloaded_file
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
raise DownloadError(f"Failed to download media: {str(e)}") from e
|
||||
|
||||
async def _extract_info_for_online_media(self, track):
|
||||
"""
|
||||
Extract information for online media.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated information
|
||||
"""
|
||||
self.logger.info(f"Extracting info for online media: {track.input_media}")
|
||||
|
||||
# Skip artist and title extraction if already provided
|
||||
extract_metadata = not (track.artist and track.title)
|
||||
|
||||
# Extract info from URL
|
||||
try:
|
||||
ydl_opts = {
|
||||
"quiet": True,
|
||||
"no_warnings": True,
|
||||
"extract_flat": "in_playlist",
|
||||
"skip_download": True,
|
||||
}
|
||||
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl_instance:
|
||||
info = ydl_instance.extract_info(track.input_media, download=False)
|
||||
|
||||
# Handle playlists
|
||||
if "entries" in info:
|
||||
# Get the first video in the playlist
|
||||
if not info["entries"]:
|
||||
raise DownloadError("Playlist is empty")
|
||||
|
||||
info = info["entries"][0]
|
||||
|
||||
# Extract extractor and media_id (always do this)
|
||||
if "extractor_key" in info:
|
||||
track.extractor = info["extractor_key"]
|
||||
elif "ie_key" in info:
|
||||
track.extractor = info["ie_key"]
|
||||
else:
|
||||
self.logger.warning("Could not extract extractor from media info")
|
||||
|
||||
if "id" in info:
|
||||
track.media_id = info["id"]
|
||||
|
||||
# Extract artist and title if needed
|
||||
if extract_metadata:
|
||||
artist, title = self._parse_video_title(info.get("title", ""))
|
||||
|
||||
if not track.artist:
|
||||
track.artist = artist
|
||||
|
||||
if not track.title:
|
||||
track.title = title
|
||||
|
||||
self.logger.info(f"Extracted info - artist: {track.artist}, title: {track.title}, extractor: {track.extractor}, id: {track.media_id}")
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
raise DownloadError(f"Failed to extract info for online media: {str(e)}") from e
|
||||
|
||||
async def _download_video(self, url, output_filename_no_extension):
|
||||
"""
|
||||
Download a video from a URL.
|
||||
|
||||
Args:
|
||||
url: The URL to download from
|
||||
output_filename_no_extension: The output filename without extension
|
||||
|
||||
Returns:
|
||||
The path to the downloaded file
|
||||
"""
|
||||
self.logger.info(f"Downloading video from {url}")
|
||||
|
||||
# Define output template
|
||||
output_template = f"{output_filename_no_extension}.%(ext)s"
|
||||
|
||||
# Set up yt-dlp options
|
||||
ydl_opts = {
|
||||
"format": "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best",
|
||||
"outtmpl": output_template,
|
||||
"quiet": self.config.log_level > 10, # Only show output if log level is DEBUG
|
||||
"no_warnings": self.config.log_level > 10,
|
||||
"ignoreerrors": False,
|
||||
"noplaylist": True,
|
||||
}
|
||||
|
||||
if self.config.dry_run:
|
||||
self.logger.info(f"[DRY RUN] Would download video from {url} to {output_template}")
|
||||
return f"{output_filename_no_extension}.mp4"
|
||||
|
||||
try:
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl_instance:
|
||||
info = ydl_instance.extract_info(url, download=True)
|
||||
|
||||
# Get the downloaded file path
|
||||
if info and "requested_downloads" in info:
|
||||
for download in info["requested_downloads"]:
|
||||
if "filepath" in download:
|
||||
downloaded_file = download["filepath"]
|
||||
self.logger.info(f"Successfully downloaded video: {downloaded_file}")
|
||||
return downloaded_file
|
||||
|
||||
# Fallback: try to guess the file path
|
||||
extensions = ["mp4", "webm", "mkv", "m4a", "mp3"]
|
||||
for ext in extensions:
|
||||
possible_path = f"{output_filename_no_extension}.{ext}"
|
||||
if os.path.isfile(possible_path):
|
||||
self.logger.info(f"Found downloaded file: {possible_path}")
|
||||
return possible_path
|
||||
|
||||
raise DownloadError("Failed to determine downloaded file path")
|
||||
|
||||
except Exception as e:
|
||||
raise DownloadError(f"Failed to download video: {str(e)}") from e
|
||||
|
||||
def _parse_video_title(self, video_title):
|
||||
"""
|
||||
Parse artist and title from a video title.
|
||||
|
||||
Args:
|
||||
video_title: The video title
|
||||
|
||||
Returns:
|
||||
Tuple of (artist, title)
|
||||
"""
|
||||
self.logger.debug(f"Parsing video title: {video_title}")
|
||||
|
||||
# Try to match "Artist - Title" pattern
|
||||
match = re.search(r"(.+?)\s*[-–—]\s*(.+)", video_title)
|
||||
if match:
|
||||
artist = match.group(1).strip()
|
||||
title = match.group(2).strip()
|
||||
|
||||
# Clean up title (remove things like "Official Video", etc.)
|
||||
title = re.sub(r"\(Official\s+Video\)", "", title, flags=re.IGNORECASE).strip()
|
||||
title = re.sub(r"\(Official\s+Music\s+Video\)", "", title, flags=re.IGNORECASE).strip()
|
||||
title = re.sub(r"\(Official\s+Lyric\s+Video\)", "", title, flags=re.IGNORECASE).strip()
|
||||
title = re.sub(r"\(Lyric\s+Video\)", "", title, flags=re.IGNORECASE).strip()
|
||||
title = re.sub(r"\(Audio\)", "", title, flags=re.IGNORECASE).strip()
|
||||
title = re.sub(r"\(Official\s+Audio\)", "", title, flags=re.IGNORECASE).strip()
|
||||
|
||||
return artist, title
|
||||
|
||||
# If no match, use the whole title as both artist and title
|
||||
return video_title, video_title
|
||||
|
||||
def _sanitize_filename(self, filename):
|
||||
"""
|
||||
Sanitize a filename by removing invalid characters.
|
||||
|
||||
Args:
|
||||
filename: The filename to sanitize
|
||||
|
||||
Returns:
|
||||
The sanitized filename
|
||||
"""
|
||||
# Replace characters that are invalid in filenames
|
||||
invalid_chars = ['<', '>', ':', '"', '/', '\\', '|', '?', '*']
|
||||
for char in invalid_chars:
|
||||
filename = filename.replace(char, '_')
|
||||
return filename
|
||||
@@ -0,0 +1,322 @@
|
||||
import os
|
||||
import asyncio
|
||||
import shutil
|
||||
from PIL import Image
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import MediaError
|
||||
|
||||
|
||||
class MediaExtractor:
|
||||
"""
|
||||
Handles extracting content from media files.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the media extractor.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
async def extract_still_image(self, track):
|
||||
"""
|
||||
Extract a still image from a video file.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Extracting still image for {track.base_name}")
|
||||
|
||||
# Skip if input is not a video file
|
||||
if not self._is_video_file(track.input_media):
|
||||
self.logger.info(f"Input is not a video file, skipping still image extraction")
|
||||
return track
|
||||
|
||||
# Define output path with (Original) label
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Original)"
|
||||
)
|
||||
output_image = f"{output_filename_no_extension}.jpg"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_image):
|
||||
self.logger.info(f"Still image already exists: {output_image}")
|
||||
track.input_still_image = output_image
|
||||
return track
|
||||
|
||||
# Build ffmpeg command
|
||||
command = f'{self.ffmpeg_base_command} -i "{track.input_media}" -vf "select=eq(n\\,0)" -q:v 1 "{output_image}"'
|
||||
|
||||
# Execute command
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
self.logger.debug(f"Executing command: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise MediaError(f"Failed to extract still image: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully extracted still image: {output_image}")
|
||||
track.input_still_image = output_image
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to extract still image: {str(e)}")
|
||||
# Continue without still image
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would extract still image: {output_image}")
|
||||
track.input_still_image = output_image
|
||||
|
||||
return track
|
||||
|
||||
async def extract_audio_from_video(self, track):
|
||||
"""
|
||||
Extract audio from a video file.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Extracting audio from video for {track.base_name}")
|
||||
|
||||
# Skip if input is not a video file
|
||||
if not self._is_video_file(track.input_media):
|
||||
self.logger.info(f"Input is not a video file, skipping audio extraction")
|
||||
return track
|
||||
|
||||
# Define output path with (Original) label
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Original)"
|
||||
)
|
||||
output_wav = f"{output_filename_no_extension}.wav"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_wav):
|
||||
self.logger.info(f"Audio file already exists: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
return track
|
||||
|
||||
# Build ffmpeg command
|
||||
command = f'{self.ffmpeg_base_command} -i "{track.input_media}" -vn -acodec pcm_s16le -ar 44100 -ac 2 "{output_wav}"'
|
||||
|
||||
# Execute command
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
self.logger.debug(f"Executing command: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise MediaError(f"Failed to extract audio: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully extracted audio: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
except Exception as e:
|
||||
raise MediaError(f"Failed to extract audio: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would extract audio: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
return track
|
||||
|
||||
async def copy_audio_file(self, track):
|
||||
"""
|
||||
Copy an audio file to the output directory.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Copying audio file for {track.base_name}")
|
||||
|
||||
# Define output path with (Original) label
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Original)"
|
||||
)
|
||||
|
||||
# Determine output extension
|
||||
input_ext = os.path.splitext(track.input_media)[1].lower()
|
||||
output_file = f"{output_filename_no_extension}{input_ext}"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file) and os.path.abspath(output_file) != os.path.abspath(track.input_media):
|
||||
self.logger.info(f"Audio file already exists: {output_file}")
|
||||
elif not self.config.dry_run:
|
||||
try:
|
||||
# Copy file
|
||||
shutil.copy2(track.input_media, output_file)
|
||||
self.logger.info(f"Successfully copied audio file: {output_file}")
|
||||
except Exception as e:
|
||||
raise MediaError(f"Failed to copy audio file: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would copy audio file: {output_file}")
|
||||
|
||||
# Convert to WAV if needed
|
||||
output_wav = f"{output_filename_no_extension}.wav"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_wav):
|
||||
self.logger.info(f"WAV file already exists: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
return track
|
||||
|
||||
# Build ffmpeg command
|
||||
command = f'{self.ffmpeg_base_command} -i "{output_file}" -vn -acodec pcm_s16le -ar 44100 -ac 2 "{output_wav}"'
|
||||
|
||||
# Execute command
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
self.logger.debug(f"Executing command: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise MediaError(f"Failed to convert audio to WAV: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully converted audio to WAV: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
except Exception as e:
|
||||
raise MediaError(f"Failed to convert audio to WAV: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would convert audio to WAV: {output_wav}")
|
||||
track.input_audio_wav = output_wav
|
||||
|
||||
return track
|
||||
|
||||
async def copy_image_file(self, track):
|
||||
"""
|
||||
Copy an image file to the output directory.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Copying image file for {track.base_name}")
|
||||
|
||||
# Define output path with (Original) label
|
||||
output_filename_no_extension = os.path.join(
|
||||
track.track_output_dir,
|
||||
f"{track.base_name} (Original)"
|
||||
)
|
||||
|
||||
# Determine output extension
|
||||
input_ext = os.path.splitext(track.input_media)[1].lower()
|
||||
output_file = f"{output_filename_no_extension}{input_ext}"
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file) and os.path.abspath(output_file) != os.path.abspath(track.input_media):
|
||||
self.logger.info(f"Image file already exists: {output_file}")
|
||||
elif not self.config.dry_run:
|
||||
try:
|
||||
# Copy file
|
||||
shutil.copy2(track.input_media, output_file)
|
||||
self.logger.info(f"Successfully copied image file: {output_file}")
|
||||
except Exception as e:
|
||||
raise MediaError(f"Failed to copy image file: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would copy image file: {output_file}")
|
||||
|
||||
# Set still image
|
||||
track.input_still_image = output_file
|
||||
|
||||
return track
|
||||
|
||||
def _is_video_file(self, file_path):
|
||||
"""
|
||||
Check if a file is a video file.
|
||||
|
||||
Args:
|
||||
file_path: The path to the file
|
||||
|
||||
Returns:
|
||||
True if the file is a video file, False otherwise
|
||||
"""
|
||||
if not file_path or not os.path.isfile(file_path):
|
||||
return False
|
||||
|
||||
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.webm', '.flv', '.wmv', '.m4v']
|
||||
_, ext = os.path.splitext(file_path)
|
||||
return ext.lower() in video_extensions
|
||||
|
||||
async def extract_media(self, track: Track) -> Track:
|
||||
"""
|
||||
Extract media from the input file based on its type.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Extracting media for {track.base_name}")
|
||||
|
||||
# Check if the input is a video file
|
||||
if self._is_video_file(track.input_media):
|
||||
# Extract still image and audio from video
|
||||
track = await self.extract_still_image(track)
|
||||
track = await self.extract_audio_from_video(track)
|
||||
elif self._is_image_file(track.input_media):
|
||||
# Copy image file
|
||||
track = await self.copy_image_file(track)
|
||||
else:
|
||||
# Assume it's an audio file
|
||||
track = await self.copy_audio_file(track)
|
||||
|
||||
return track
|
||||
|
||||
def _is_image_file(self, file_path):
|
||||
"""
|
||||
Check if a file is an image file.
|
||||
|
||||
Args:
|
||||
file_path: The path to the file
|
||||
|
||||
Returns:
|
||||
True if the file is an image file, False otherwise
|
||||
"""
|
||||
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp']
|
||||
ext = os.path.splitext(file_path)[1].lower()
|
||||
return ext in image_extensions
|
||||
@@ -0,0 +1,115 @@
|
||||
import logging
|
||||
import os
|
||||
import asyncio
|
||||
import shutil
|
||||
import glob
|
||||
from typing import Dict, Any, Optional, Tuple
|
||||
from karaoke_gen.core.project import ProjectConfig
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import MediaError, DownloadError, ConversionError
|
||||
from karaoke_gen.services.media.downloader import MediaDownloader
|
||||
from karaoke_gen.services.media.extractor import MediaExtractor
|
||||
from karaoke_gen.services.media.detector import MediaDetector
|
||||
|
||||
|
||||
class MediaService:
|
||||
"""
|
||||
Service for media handling operations including downloading, extraction, and detection.
|
||||
"""
|
||||
|
||||
def __init__(self, config: ProjectConfig):
|
||||
"""
|
||||
Initialize the media service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Initialize components
|
||||
self.downloader = MediaDownloader(config)
|
||||
self.extractor = MediaExtractor(config)
|
||||
self.detector = MediaDetector(config)
|
||||
|
||||
async def download_media(self, track: Track) -> Track:
|
||||
"""
|
||||
Download media for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
if self.config.skip_download:
|
||||
self.logger.info("Skipping media download")
|
||||
return track
|
||||
|
||||
self.logger.info(f"Downloading media for {track.base_name}")
|
||||
|
||||
# Download media
|
||||
track = await self.downloader.download_media(track)
|
||||
|
||||
return track
|
||||
|
||||
async def extract_media(self, track: Track) -> Track:
|
||||
"""
|
||||
Extract audio and other components from media.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated extracted media information
|
||||
"""
|
||||
if self.config.skip_separation:
|
||||
self.logger.info("Skipping media extraction")
|
||||
return track
|
||||
|
||||
self.logger.info(f"Extracting media for {track.base_name}")
|
||||
|
||||
# Extract media
|
||||
track = await self.extractor.extract_media(track)
|
||||
|
||||
return track
|
||||
|
||||
async def detect_media_info(self, track: Track) -> Track:
|
||||
"""
|
||||
Detect media information.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Detecting media info for {track.base_name}")
|
||||
|
||||
# Detect media info
|
||||
track = await self.detector.detect_media_info(track)
|
||||
|
||||
return track
|
||||
|
||||
async def process_media(self, track: Track) -> Track:
|
||||
"""
|
||||
Process media for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated media information
|
||||
"""
|
||||
self.logger.info(f"Processing media for {track.base_name}")
|
||||
|
||||
# Download media
|
||||
track = await self.download_media(track)
|
||||
|
||||
# Extract media
|
||||
track = await self.extract_media(track)
|
||||
|
||||
# Detect media info
|
||||
track = await self.detect_media_info(track)
|
||||
|
||||
return track
|
||||
@@ -0,0 +1,5 @@
|
||||
from karaoke_gen.services.video.service import VideoService
|
||||
from karaoke_gen.services.video.renderer import VideoRenderer
|
||||
from karaoke_gen.services.video.text import TextRenderer
|
||||
from karaoke_gen.services.video.screens import ScreenGenerator
|
||||
from karaoke_gen.services.video.compositor import VideoCompositor
|
||||
@@ -0,0 +1,626 @@
|
||||
import os
|
||||
import asyncio
|
||||
import tempfile
|
||||
from karaoke_gen.core.exceptions import VideoError
|
||||
|
||||
|
||||
class VideoCompositor:
|
||||
"""
|
||||
Handles video composition operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the video compositor.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
# Initialize temporary files list
|
||||
self._temp_files = []
|
||||
|
||||
async def compose_final_video(self, track):
|
||||
"""
|
||||
Compose the final video by combining title, content, and end videos.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Composing final video for {track.base_name}")
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Final video already exists: {output_path}")
|
||||
track.final_video = output_path
|
||||
return track
|
||||
|
||||
# Check for required videos
|
||||
title_video = track.title_video
|
||||
content_video = track.video_with_lyrics or track.video_with_instrumental
|
||||
end_video = track.end_video
|
||||
|
||||
if not title_video or not os.path.isfile(title_video):
|
||||
self.logger.warning("Title video not found, skipping final video composition")
|
||||
return track
|
||||
|
||||
if not content_video or not os.path.isfile(content_video):
|
||||
self.logger.warning("Content video not found, skipping final video composition")
|
||||
return track
|
||||
|
||||
# Compose video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Build ffmpeg command
|
||||
command = f'{self.ffmpeg_base_command} -i "{title_video}" -i "{content_video}" '
|
||||
|
||||
# Add end video if available
|
||||
if end_video and os.path.isfile(end_video):
|
||||
command += f'-i "{end_video}" '
|
||||
filter_complex = '[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]'
|
||||
else:
|
||||
filter_complex = '[0:v][0:a][1:v][1:a]concat=n=2:v=1:a=1[outv][outa]'
|
||||
|
||||
# Add filter complex and output options
|
||||
command += (
|
||||
f'-filter_complex "{filter_complex}" '
|
||||
f'-map "[outv]" -map "[outa]" '
|
||||
f'-c:v libx264 -preset medium -crf 22 -c:a aac -b:a 192k '
|
||||
f'-pix_fmt yuv420p "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Composing final video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to compose final video: {error_message}")
|
||||
|
||||
track.final_video = output_path
|
||||
self.logger.info(f"Successfully composed final video: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to compose final video: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would compose final video: {output_path}")
|
||||
track.final_video = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def create_lossless_version(self, track):
|
||||
"""
|
||||
Create a lossless version of the final video.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Creating lossless version for {track.base_name}")
|
||||
|
||||
# Skip if no final video
|
||||
if not track.final_video or not os.path.isfile(track.final_video):
|
||||
self.logger.info("No final video available, skipping lossless version creation")
|
||||
return track
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke).mkv")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Lossless version already exists: {output_path}")
|
||||
track.final_video_mkv = output_path
|
||||
return track
|
||||
|
||||
# Create lossless version
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{track.final_video}" '
|
||||
f'-c:v copy -c:a flac "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Creating lossless version: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create lossless version: {error_message}")
|
||||
|
||||
track.final_video_mkv = output_path
|
||||
self.logger.info(f"Successfully created lossless version: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create lossless version: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would create lossless version: {output_path}")
|
||||
track.final_video_mkv = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def create_720p_version(self, track):
|
||||
"""
|
||||
Create a 720p version of the final video.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Creating 720p version for {track.base_name}")
|
||||
|
||||
# Skip if no final video
|
||||
if not track.final_video or not os.path.isfile(track.final_video):
|
||||
self.logger.info("No final video available, skipping 720p version creation")
|
||||
return track
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke 720p).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"720p version already exists: {output_path}")
|
||||
track.final_video_720p = output_path
|
||||
return track
|
||||
|
||||
# Create 720p version
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{track.final_video}" '
|
||||
f'-c:v libx264 -vf "scale=1280:720" -b:v 2000k -preset medium -tune animation '
|
||||
f'-c:a aac -b:a 128k -pix_fmt yuv420p "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Creating 720p version: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create 720p version: {error_message}")
|
||||
|
||||
track.final_video_720p = output_path
|
||||
self.logger.info(f"Successfully created 720p version: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create 720p version: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would create 720p version: {output_path}")
|
||||
track.final_video_720p = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def create_lossy_version(self, track):
|
||||
"""
|
||||
Create a lossy version of the final video.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Creating lossy version for {track.base_name}")
|
||||
|
||||
# Skip if no final video
|
||||
if not track.final_video or not os.path.isfile(track.final_video):
|
||||
self.logger.warning(f"No final video found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Final Karaoke Lossy).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path) and not self.config.force_regenerate:
|
||||
self.logger.info(f"Lossy version already exists: {output_path}")
|
||||
track.final_video_lossy = output_path
|
||||
return track
|
||||
|
||||
# Create lossy version
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{track.final_video}" '
|
||||
f'-c:v libx264 -preset slow -crf 23 -c:a aac -b:a 128k '
|
||||
f'-pix_fmt yuv420p "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Creating lossy version: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create lossy version: {error_message}")
|
||||
|
||||
track.final_video_lossy = output_path
|
||||
self.logger.info(f"Successfully created lossy version: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create lossy version: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would create lossy version: {output_path}")
|
||||
track.final_video_lossy = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def add_subtitles_to_video(self, track, subtitles_file, output_file=None):
|
||||
"""
|
||||
Add subtitles to a video.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
subtitles_file: The subtitles file
|
||||
output_file: The output file path
|
||||
|
||||
Returns:
|
||||
The track with updated subtitled video information
|
||||
"""
|
||||
self.logger.info(f"Adding subtitles to video for {track.base_name}")
|
||||
|
||||
# Set default output file
|
||||
if output_file is None:
|
||||
output_file = os.path.join(track.track_output_dir, f"{track.base_name} (Subtitled).mov")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Subtitled video already exists: {output_file}")
|
||||
track.subtitled_video = output_file
|
||||
return track
|
||||
|
||||
# Check if required files exist
|
||||
if not track.video or not os.path.isfile(track.video):
|
||||
self.logger.error(f"Video not found: {track.video}")
|
||||
raise VideoError(f"Video not found: {track.video}")
|
||||
|
||||
if not os.path.isfile(subtitles_file):
|
||||
self.logger.error(f"Subtitles file not found: {subtitles_file}")
|
||||
raise VideoError(f"Subtitles file not found: {subtitles_file}")
|
||||
|
||||
# Add subtitles to video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
await self._add_subtitles_to_video(track.video, subtitles_file, output_file)
|
||||
|
||||
track.subtitled_video = output_file
|
||||
self.logger.info(f"Successfully added subtitles to video: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to add subtitles to video: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would add subtitles to video: {output_file}")
|
||||
track.subtitled_video = output_file
|
||||
|
||||
return track
|
||||
|
||||
async def overlay_videos(self, background_video, overlay_video, output_file, position=None,
|
||||
start_time=None, end_time=None, opacity=None):
|
||||
"""
|
||||
Overlay one video on top of another.
|
||||
|
||||
Args:
|
||||
background_video: The background video file
|
||||
overlay_video: The overlay video file
|
||||
output_file: The output file path
|
||||
position: The position (x:y)
|
||||
start_time: The start time in seconds
|
||||
end_time: The end time in seconds
|
||||
opacity: The opacity (0.0-1.0)
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Overlaying video on {background_video}")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Overlaid video already exists: {output_file}")
|
||||
return output_file
|
||||
|
||||
# Check if required files exist
|
||||
if not os.path.isfile(background_video):
|
||||
self.logger.error(f"Background video not found: {background_video}")
|
||||
raise VideoError(f"Background video not found: {background_video}")
|
||||
|
||||
if not os.path.isfile(overlay_video):
|
||||
self.logger.error(f"Overlay video not found: {overlay_video}")
|
||||
raise VideoError(f"Overlay video not found: {overlay_video}")
|
||||
|
||||
# Set default values
|
||||
position = position or self.config.overlay_position or "10:10"
|
||||
opacity = opacity or self.config.overlay_opacity or 1.0
|
||||
|
||||
# Overlay video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create filter complex
|
||||
filter_complex = (
|
||||
f"[0:v][1:v]overlay={position}"
|
||||
)
|
||||
|
||||
# Add start time if specified
|
||||
if start_time is not None:
|
||||
filter_complex += f":enable='between(t,{start_time},{end_time or 999999})'"
|
||||
|
||||
# Add opacity if less than 1.0
|
||||
if opacity < 1.0:
|
||||
filter_complex += f":alpha={opacity}"
|
||||
|
||||
# Overlay video
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{background_video}" -i "{overlay_video}" '
|
||||
f'-filter_complex "{filter_complex}" -c:v prores_ks -profile:v 3 '
|
||||
f'-vendor ap10 -bits_per_mb 8000 -pix_fmt yuv422p10le -c:a copy "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Overlaying video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to overlay video: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully overlaid video: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to overlay video: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would overlay video: {output_file}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def create_picture_in_picture(self, main_video, pip_video, output_file, position=None,
|
||||
size=None, start_time=None, end_time=None, border=None,
|
||||
border_color=None):
|
||||
"""
|
||||
Create a picture-in-picture video.
|
||||
|
||||
Args:
|
||||
main_video: The main video file
|
||||
pip_video: The picture-in-picture video file
|
||||
output_file: The output file path
|
||||
position: The position (x:y)
|
||||
size: The size (width:height)
|
||||
start_time: The start time in seconds
|
||||
end_time: The end time in seconds
|
||||
border: The border width
|
||||
border_color: The border color
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Creating picture-in-picture video with {main_video} and {pip_video}")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Picture-in-picture video already exists: {output_file}")
|
||||
return output_file
|
||||
|
||||
# Check if required files exist
|
||||
if not os.path.isfile(main_video):
|
||||
self.logger.error(f"Main video not found: {main_video}")
|
||||
raise VideoError(f"Main video not found: {main_video}")
|
||||
|
||||
if not os.path.isfile(pip_video):
|
||||
self.logger.error(f"Picture-in-picture video not found: {pip_video}")
|
||||
raise VideoError(f"Picture-in-picture video not found: {pip_video}")
|
||||
|
||||
# Set default values
|
||||
position = position or self.config.pip_position or "main_w-overlay_w-10:main_h-overlay_h-10"
|
||||
size = size or self.config.pip_size or "iw/4:ih/4"
|
||||
border = border or self.config.pip_border or 0
|
||||
border_color = border_color or self.config.pip_border_color or "black"
|
||||
|
||||
# Create picture-in-picture video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create filter complex
|
||||
filter_complex = (
|
||||
f"[1:v]scale={size}"
|
||||
)
|
||||
|
||||
# Add border if specified
|
||||
if border > 0:
|
||||
filter_complex += f",pad=iw+{border*2}:ih+{border*2}:{border}:{border}:{border_color}"
|
||||
|
||||
filter_complex += f"[pip]; [0:v][pip]overlay={position}"
|
||||
|
||||
# Add start time if specified
|
||||
if start_time is not None:
|
||||
filter_complex += f":enable='between(t,{start_time},{end_time or 999999})'"
|
||||
|
||||
# Create picture-in-picture video
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{main_video}" -i "{pip_video}" '
|
||||
f'-filter_complex "{filter_complex}" -c:v prores_ks -profile:v 3 '
|
||||
f'-vendor ap10 -bits_per_mb 8000 -pix_fmt yuv422p10le -c:a copy "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Creating picture-in-picture video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create picture-in-picture video: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully created picture-in-picture video: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to create picture-in-picture video: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would create picture-in-picture video: {output_file}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _combine_videos(self, videos, output_file):
|
||||
"""
|
||||
Combine multiple videos into one.
|
||||
|
||||
Args:
|
||||
videos: The list of video files
|
||||
output_file: The output file path
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
# Create a temporary file for the concat list
|
||||
with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as temp_file:
|
||||
concat_list = temp_file.name
|
||||
self._temp_files.append(concat_list) # Track temporary file
|
||||
|
||||
# Write concat list
|
||||
with open(concat_list, "w") as f:
|
||||
for video in videos:
|
||||
f.write(f"file '{video}'\n")
|
||||
|
||||
# Combine videos
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -f concat -safe 0 -i "{concat_list}" '
|
||||
f'-c:v prores_ks -profile:v 3 -vendor ap10 -bits_per_mb 8000 '
|
||||
f'-pix_fmt yuv422p10le -c:a pcm_s24le "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Combining videos: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to combine videos: {error_message}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _add_subtitles_to_video(self, video_file, subtitles_file, output_file):
|
||||
"""
|
||||
Add subtitles to a video.
|
||||
|
||||
Args:
|
||||
video_file: The video file
|
||||
subtitles_file: The subtitles file
|
||||
output_file: The output file path
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
# Determine subtitles format
|
||||
subtitles_format = os.path.splitext(subtitles_file)[1].lower()
|
||||
|
||||
# Add subtitles to video
|
||||
if subtitles_format == ".srt":
|
||||
# Use subtitles filter for SRT
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{video_file}" '
|
||||
f'-vf "subtitles={subtitles_file}" -c:v prores_ks -profile:v 3 '
|
||||
f'-vendor ap10 -bits_per_mb 8000 -pix_fmt yuv422p10le -c:a copy "{output_file}"'
|
||||
)
|
||||
elif subtitles_format == ".ass":
|
||||
# Use ASS filter for ASS/SSA
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{video_file}" '
|
||||
f'-vf "ass={subtitles_file}" -c:v prores_ks -profile:v 3 '
|
||||
f'-vendor ap10 -bits_per_mb 8000 -pix_fmt yuv422p10le -c:a copy "{output_file}"'
|
||||
)
|
||||
else:
|
||||
# Use subtitles filter for other formats
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{video_file}" -i "{subtitles_file}" '
|
||||
f'-c:v prores_ks -profile:v 3 -vendor ap10 -bits_per_mb 8000 '
|
||||
f'-pix_fmt yuv422p10le -c:a copy -c:s mov_text "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Adding subtitles to video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to add subtitles to video: {error_message}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the video compositor.
|
||||
"""
|
||||
self.logger.info("Cleaning up video compositor resources")
|
||||
|
||||
# Clean up any temporary files
|
||||
if hasattr(self, '_temp_files') and self._temp_files:
|
||||
for temp_file in self._temp_files:
|
||||
if os.path.exists(temp_file):
|
||||
try:
|
||||
os.remove(temp_file)
|
||||
self.logger.debug(f"Removed temporary file: {temp_file}")
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to remove temporary file {temp_file}: {str(e)}")
|
||||
|
||||
self.logger.info("Video compositor cleanup complete")
|
||||
@@ -0,0 +1,803 @@
|
||||
import os
|
||||
import asyncio
|
||||
import tempfile
|
||||
import subprocess
|
||||
import shutil
|
||||
from karaoke_gen.core.exceptions import VideoError
|
||||
|
||||
|
||||
class VideoRenderer:
|
||||
"""
|
||||
Handles video rendering operations.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the video renderer.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
# Initialize temporary files list
|
||||
self._temp_files = []
|
||||
|
||||
async def render_video(self, track, output_file=None, resolution=None, fps=None,
|
||||
codec=None, bitrate=None, background_color=None):
|
||||
"""
|
||||
Render a video for a track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
output_file: The output file path
|
||||
resolution: The resolution
|
||||
fps: The frames per second
|
||||
codec: The codec
|
||||
bitrate: The bitrate
|
||||
background_color: The background color
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Rendering video for {track.base_name}")
|
||||
|
||||
# Set default output file
|
||||
if output_file is None:
|
||||
output_file = os.path.join(track.track_output_dir, f"{track.base_name} (Video).mov")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Video already exists: {output_file}")
|
||||
track.video = output_file
|
||||
return track
|
||||
|
||||
# Set default values
|
||||
resolution = resolution or self.config.video_resolution or "1920x1080"
|
||||
fps = fps or self.config.video_fps or 30
|
||||
codec = codec or self.config.video_codec or "prores_ks"
|
||||
bitrate = bitrate or self.config.video_bitrate or "8000k"
|
||||
background_color = background_color or self.config.video_background_color or "black"
|
||||
|
||||
# Check if audio file exists
|
||||
if not track.audio_file or not os.path.isfile(track.audio_file):
|
||||
self.logger.error(f"Audio file not found: {track.audio_file}")
|
||||
raise VideoError(f"Audio file not found: {track.audio_file}")
|
||||
|
||||
# Create video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create a video from audio
|
||||
await self._create_video_from_audio(
|
||||
track.audio_file,
|
||||
output_file,
|
||||
track.duration,
|
||||
resolution,
|
||||
fps,
|
||||
codec,
|
||||
bitrate,
|
||||
background_color
|
||||
)
|
||||
|
||||
track.video = output_file
|
||||
self.logger.info(f"Successfully rendered video: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to render video: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render video: {output_file}")
|
||||
track.video = output_file
|
||||
|
||||
return track
|
||||
|
||||
async def combine_videos(self, videos, output_file, transition_duration=None):
|
||||
"""
|
||||
Combine multiple videos into one.
|
||||
|
||||
Args:
|
||||
videos: The list of video files to combine
|
||||
output_file: The output file path
|
||||
transition_duration: The transition duration in seconds
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Combining {len(videos)} videos")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Combined video already exists: {output_file}")
|
||||
return output_file
|
||||
|
||||
# Check if videos exist
|
||||
for video in videos:
|
||||
if not os.path.isfile(video):
|
||||
self.logger.error(f"Video file not found: {video}")
|
||||
raise VideoError(f"Video file not found: {video}")
|
||||
|
||||
# Set default transition duration
|
||||
transition_duration = transition_duration or self.config.transition_duration or 0.5
|
||||
|
||||
# Create video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create a temporary file for the concat list
|
||||
with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as temp_file:
|
||||
concat_list = temp_file.name
|
||||
self._temp_files.append(concat_list) # Track temporary file
|
||||
|
||||
# Write concat list
|
||||
with open(concat_list, "w") as f:
|
||||
for video in videos:
|
||||
f.write(f"file '{video}'\n")
|
||||
|
||||
# Combine videos
|
||||
if transition_duration > 0:
|
||||
await self._combine_videos_with_transitions(videos, output_file, transition_duration)
|
||||
else:
|
||||
await self._combine_videos_simple(concat_list, output_file)
|
||||
|
||||
self.logger.info(f"Successfully combined videos: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to combine videos: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would combine videos: {output_file}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def add_audio_to_video(self, video_file, audio_file, output_file):
|
||||
"""
|
||||
Add audio to a video.
|
||||
|
||||
Args:
|
||||
video_file: The video file
|
||||
audio_file: The audio file
|
||||
output_file: The output file path
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Adding audio to video: {video_file}")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Video with audio already exists: {output_file}")
|
||||
return output_file
|
||||
|
||||
# Check if files exist
|
||||
if not os.path.isfile(video_file):
|
||||
self.logger.error(f"Video file not found: {video_file}")
|
||||
raise VideoError(f"Video file not found: {video_file}")
|
||||
|
||||
if not os.path.isfile(audio_file):
|
||||
self.logger.error(f"Audio file not found: {audio_file}")
|
||||
raise VideoError(f"Audio file not found: {audio_file}")
|
||||
|
||||
# Add audio to video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{video_file}" -i "{audio_file}" '
|
||||
f'-c:v copy -c:a pcm_s24le -shortest "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Adding audio to video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to add audio to video: {error_message}")
|
||||
|
||||
self.logger.info(f"Successfully added audio to video: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to add audio to video: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would add audio to video: {output_file}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _create_video_from_audio(self, audio_file, output_file, duration, resolution,
|
||||
fps, codec, bitrate, background_color):
|
||||
"""
|
||||
Create a video from an audio file.
|
||||
|
||||
Args:
|
||||
audio_file: The audio file
|
||||
output_file: The output file path
|
||||
duration: The duration in seconds
|
||||
resolution: The resolution
|
||||
fps: The frames per second
|
||||
codec: The codec
|
||||
bitrate: The bitrate
|
||||
background_color: The background color
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
# Create a video from audio
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -f lavfi -i color=c={background_color}:s={resolution}:r={fps} '
|
||||
f'-i "{audio_file}" -t {duration} -c:v {codec} -profile:v 3 -vendor ap10 '
|
||||
f'-b:v {bitrate} -pix_fmt yuv422p10le -c:a pcm_s24le "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Creating video from audio: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create video from audio: {error_message}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _combine_videos_simple(self, concat_list, output_file):
|
||||
"""
|
||||
Combine videos using the concat demuxer.
|
||||
|
||||
Args:
|
||||
concat_list: The concat list file
|
||||
output_file: The output file path
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
# Combine videos
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -f concat -safe 0 -i "{concat_list}" '
|
||||
f'-c:v prores_ks -profile:v 3 -vendor ap10 -bits_per_mb 8000 '
|
||||
f'-pix_fmt yuv422p10le -c:a pcm_s24le "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Combining videos: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to combine videos: {error_message}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _combine_videos_with_transitions(self, videos, output_file, transition_duration):
|
||||
"""
|
||||
Combine videos with crossfade transitions.
|
||||
|
||||
Args:
|
||||
videos: The list of video files
|
||||
output_file: The output file path
|
||||
transition_duration: The transition duration in seconds
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
# Create a complex filter for crossfade transitions
|
||||
filter_complex = ""
|
||||
inputs = ""
|
||||
|
||||
# Add input files
|
||||
for i, video in enumerate(videos):
|
||||
inputs += f' -i "{video}"'
|
||||
|
||||
# Create filter complex
|
||||
for i in range(len(videos)):
|
||||
filter_complex += f"[{i}:v]setpts=PTS-STARTPTS[v{i}];"
|
||||
|
||||
# Add crossfade transitions
|
||||
for i in range(len(videos) - 1):
|
||||
filter_complex += (
|
||||
f"[v{i}][v{i+1}]xfade=transition=fade:duration={transition_duration}:offset="
|
||||
f"{self._get_video_duration(videos[i]) - transition_duration}[v{i}out];"
|
||||
)
|
||||
|
||||
# Finalize filter complex
|
||||
if len(videos) > 2:
|
||||
for i in range(len(videos) - 2):
|
||||
filter_complex += f"[v{i}out][v{i+2}]concat=n=2:v=1:a=0[v{i+1}out];"
|
||||
filter_complex = filter_complex[:-1] # Remove last semicolon
|
||||
output_label = f"[v{len(videos)-2}out]"
|
||||
else:
|
||||
output_label = "[v0out]"
|
||||
|
||||
# Combine videos with transitions
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command}{inputs} -filter_complex "{filter_complex}" '
|
||||
f'-map "{output_label}" -c:v prores_ks -profile:v 3 -vendor ap10 '
|
||||
f'-bits_per_mb 8000 -pix_fmt yuv422p10le "{output_file}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Combining videos with transitions: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to combine videos with transitions: {error_message}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def _get_video_duration(self, video_file):
|
||||
"""
|
||||
Get the duration of a video file.
|
||||
|
||||
Args:
|
||||
video_file: The video file
|
||||
|
||||
Returns:
|
||||
The duration in seconds
|
||||
"""
|
||||
# Get video duration
|
||||
command = (
|
||||
f'{self.ffmpeg_path} -i "{video_file}" -hide_banner 2>&1 | '
|
||||
f'grep "Duration" | cut -d " " -f 4 | sed s/,//'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Getting video duration: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE,
|
||||
shell=True
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to get video duration: {error_message}")
|
||||
|
||||
# Parse duration
|
||||
duration_str = stdout.decode().strip()
|
||||
if not duration_str:
|
||||
raise VideoError(f"Failed to get video duration: {video_file}")
|
||||
|
||||
# Convert HH:MM:SS.ms to seconds
|
||||
hours, minutes, seconds = duration_str.split(":")
|
||||
seconds, milliseconds = seconds.split(".")
|
||||
|
||||
duration = (
|
||||
int(hours) * 3600 +
|
||||
int(minutes) * 60 +
|
||||
int(seconds) +
|
||||
int(milliseconds) / 100
|
||||
)
|
||||
|
||||
return duration
|
||||
|
||||
async def render_lyrics_video(self, track):
|
||||
"""
|
||||
Render a video with lyrics.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Rendering lyrics video for {track.base_name}")
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (With Vocals).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Lyrics video already exists: {output_path}")
|
||||
track.video_with_lyrics = output_path
|
||||
return track
|
||||
|
||||
# Debug logging
|
||||
self.logger.debug(f"processed_lyrics: {track.processed_lyrics}, type: {type(track.processed_lyrics)}")
|
||||
self.logger.debug(f"title_video: {track.title_video}, type: {type(track.title_video)}")
|
||||
self.logger.debug(f"instrumental: {track.instrumental}, type: {type(track.instrumental)}")
|
||||
|
||||
# Handle case where processed_lyrics is a dictionary
|
||||
lyrics_file = None
|
||||
if isinstance(track.processed_lyrics, dict):
|
||||
# Try to get the formatted lyrics file
|
||||
if 'formatted_lyrics_file' in track.processed_lyrics:
|
||||
lyrics_file = track.processed_lyrics['formatted_lyrics_file']
|
||||
elif 'formatted_lyrics' in track.processed_lyrics:
|
||||
lyrics_file = track.processed_lyrics['formatted_lyrics']
|
||||
elif 'ass_filepath' in track.processed_lyrics:
|
||||
lyrics_file = track.processed_lyrics['ass_filepath']
|
||||
else:
|
||||
lyrics_file = track.processed_lyrics
|
||||
|
||||
# Check for processed lyrics
|
||||
if not lyrics_file or not os.path.isfile(lyrics_file):
|
||||
self.logger.warning(f"No processed lyrics found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Check for audio file
|
||||
audio_file = track.audio_file
|
||||
if not audio_file or not os.path.isfile(audio_file):
|
||||
self.logger.warning(f"No audio file found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Render video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Determine if we have a valid title video
|
||||
has_title_video = track.title_video and os.path.isfile(track.title_video)
|
||||
|
||||
# Create temporary subtitle file in ASS format if needed
|
||||
if lyrics_file.endswith('.lrc'):
|
||||
subtitle_file = await self._convert_lrc_to_ass(lyrics_file, track.track_output_dir)
|
||||
else:
|
||||
subtitle_file = lyrics_file
|
||||
|
||||
# Build ffmpeg command
|
||||
if has_title_video:
|
||||
# Use title video if available
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{track.title_video}" -i "{audio_file}" '
|
||||
f'-vf "ass={subtitle_file}" '
|
||||
f'-c:v libx264 -preset medium -crf 22 -c:a aac -b:a 192k '
|
||||
f'-pix_fmt yuv420p -shortest "{output_path}"'
|
||||
)
|
||||
else:
|
||||
# Create video from audio with black background
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -f lavfi -i color=c=black:s=1920x1080:r=30 '
|
||||
f'-i "{audio_file}" -vf "ass={subtitle_file}" '
|
||||
f'-c:v libx264 -preset medium -crf 22 -c:a aac -b:a 192k '
|
||||
f'-pix_fmt yuv420p -shortest -t {track.duration} "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Rendering lyrics video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to render lyrics video: {error_message}")
|
||||
|
||||
track.video_with_lyrics = output_path
|
||||
self.logger.info(f"Successfully rendered lyrics video: {output_path}")
|
||||
|
||||
# Clean up temporary files
|
||||
if lyrics_file.endswith('.lrc') and os.path.isfile(subtitle_file) and subtitle_file != lyrics_file:
|
||||
os.remove(subtitle_file)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to render lyrics video: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render lyrics video: {output_path}")
|
||||
track.video_with_lyrics = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def render_instrumental_video(self, track):
|
||||
"""
|
||||
Render a video with instrumental audio.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Rendering instrumental video for {track.base_name}")
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Instrumental).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Instrumental video already exists: {output_path}")
|
||||
track.video_with_instrumental = output_path
|
||||
return track
|
||||
|
||||
# Check for title video
|
||||
if not track.title_video or not os.path.isfile(track.title_video):
|
||||
self.logger.warning(f"No title video found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Check for instrumental audio
|
||||
if not track.instrumental or not os.path.isfile(track.instrumental):
|
||||
self.logger.warning(f"No instrumental audio found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Render video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{track.title_video}" -i "{track.instrumental}" '
|
||||
f'-map 0:v -map 1:a -c:v libx264 -preset medium -crf 22 -c:a aac -b:a 192k '
|
||||
f'-pix_fmt yuv420p -shortest "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Rendering instrumental video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to render instrumental video: {error_message}")
|
||||
|
||||
track.video_with_instrumental = output_path
|
||||
self.logger.info(f"Successfully rendered instrumental video: {output_path}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to render instrumental video: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render instrumental video: {output_path}")
|
||||
track.video_with_instrumental = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def render_karaoke_video(self, track):
|
||||
"""
|
||||
Render a karaoke video with lyrics and instrumental audio.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Rendering karaoke video for {track.base_name}")
|
||||
|
||||
# Skip if no processed lyrics
|
||||
if not track.processed_lyrics or not track.processed_lyrics.get("lrc_filepath"):
|
||||
self.logger.info("No processed lyrics available, skipping karaoke video rendering")
|
||||
return track
|
||||
|
||||
# Skip if no instrumental audio
|
||||
if not track.separated_audio["clean_instrumental"].get("instrumental"):
|
||||
self.logger.info("No instrumental audio available, skipping karaoke video rendering")
|
||||
return track
|
||||
|
||||
# Define output path
|
||||
output_path = os.path.join(track.track_output_dir, f"{track.base_name} (Karaoke).mp4")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_path):
|
||||
self.logger.info(f"Karaoke video already exists: {output_path}")
|
||||
track.final_video = output_path
|
||||
return track
|
||||
|
||||
# Get input paths
|
||||
title_video = track.title_video
|
||||
end_video = track.end_video
|
||||
instrumental_audio = track.separated_audio["clean_instrumental"]["instrumental"]
|
||||
lyrics_file = track.processed_lyrics.get("lrc_filepath")
|
||||
|
||||
# Check if all required files exist
|
||||
if not all(os.path.isfile(f) for f in [title_video, instrumental_audio, lyrics_file]):
|
||||
self.logger.warning("Missing required files for karaoke video rendering")
|
||||
return track
|
||||
|
||||
# Render video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create temporary subtitle file in ASS format
|
||||
ass_file = await self._convert_lrc_to_ass(lyrics_file, track.track_output_dir)
|
||||
|
||||
# Build ffmpeg command
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{title_video}" -i "{instrumental_audio}" '
|
||||
)
|
||||
|
||||
# Add end video if available
|
||||
if end_video and os.path.isfile(end_video):
|
||||
command += f'-i "{end_video}" '
|
||||
filter_complex = (
|
||||
f'-filter_complex "[0:v][1:a][2:v][1:a]concat=n=2:v=1:a=1[outv][outa]" '
|
||||
f'-map "[outv]" -map "[outa]" '
|
||||
)
|
||||
else:
|
||||
filter_complex = ""
|
||||
command += f'-map 0:v -map 1:a '
|
||||
|
||||
# Add subtitle filter
|
||||
if filter_complex:
|
||||
command = command.replace("-filter_complex", f'-filter_complex "ass={ass_file}:')
|
||||
else:
|
||||
command += f'-vf "ass={ass_file}" '
|
||||
|
||||
# Add output options
|
||||
command += (
|
||||
f'-c:v libx264 -preset medium -crf 22 -c:a aac -b:a 192k '
|
||||
f'-pix_fmt yuv420p -shortest "{output_path}"'
|
||||
)
|
||||
|
||||
# Execute command
|
||||
self.logger.debug(f"Rendering karaoke video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to render karaoke video: {error_message}")
|
||||
|
||||
track.final_video = output_path
|
||||
self.logger.info(f"Successfully rendered karaoke video: {output_path}")
|
||||
|
||||
# Clean up temporary files
|
||||
if os.path.isfile(ass_file):
|
||||
os.remove(ass_file)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to render karaoke video: {str(e)}")
|
||||
# Continue with other processing
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render karaoke video: {output_path}")
|
||||
track.final_video = output_path
|
||||
|
||||
return track
|
||||
|
||||
async def _convert_lrc_to_ass(self, lrc_file, output_dir):
|
||||
"""
|
||||
Convert LRC file to ASS subtitle format.
|
||||
|
||||
Args:
|
||||
lrc_file: The LRC file path
|
||||
output_dir: The output directory
|
||||
|
||||
Returns:
|
||||
The path to the ASS file
|
||||
"""
|
||||
self.logger.info(f"Converting LRC file to ASS: {lrc_file}")
|
||||
|
||||
# Define output path
|
||||
ass_file = os.path.join(output_dir, os.path.basename(lrc_file).replace(".lrc", ".ass"))
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(ass_file):
|
||||
self.logger.info(f"ASS file already exists: {ass_file}")
|
||||
return ass_file
|
||||
|
||||
# Create a temporary file for the ASS file
|
||||
with tempfile.NamedTemporaryFile(suffix=".ass", delete=False) as temp_file:
|
||||
temp_ass_file = temp_file.name
|
||||
self._temp_files.append(temp_ass_file) # Track temporary file
|
||||
|
||||
# Read LRC file
|
||||
with open(lrc_file, "r", encoding="utf-8") as f:
|
||||
lrc_content = f.readlines()
|
||||
|
||||
# Parse LRC content
|
||||
lyrics = []
|
||||
for line in lrc_content:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("[ti:") or line.startswith("[ar:") or line.startswith("[al:"):
|
||||
continue
|
||||
|
||||
# Extract timestamp and text
|
||||
if line.startswith("[") and "]" in line:
|
||||
timestamp = line[1:line.find("]")]
|
||||
text = line[line.find("]") + 1:].strip()
|
||||
|
||||
# Parse timestamp
|
||||
if ":" in timestamp and "." in timestamp:
|
||||
minutes, seconds = timestamp.split(":")
|
||||
seconds, milliseconds = seconds.split(".")
|
||||
|
||||
start_time = int(minutes) * 60 + int(seconds) + int(milliseconds) / 100
|
||||
lyrics.append((start_time, text))
|
||||
|
||||
# Sort lyrics by timestamp
|
||||
lyrics.sort(key=lambda x: x[0])
|
||||
|
||||
# Calculate end times
|
||||
for i in range(len(lyrics) - 1):
|
||||
lyrics[i] = (lyrics[i][0], lyrics[i + 1][0], lyrics[i][1])
|
||||
|
||||
# Add end time for last lyric
|
||||
if lyrics:
|
||||
lyrics[-1] = (lyrics[-1][0], lyrics[-1][0] + 5, lyrics[-1][1])
|
||||
|
||||
# Create ASS file
|
||||
with open(temp_ass_file, "w", encoding="utf-8") as f:
|
||||
# Write header
|
||||
f.write("[Script Info]\n")
|
||||
f.write("Title: Karaoke Lyrics\n")
|
||||
f.write("ScriptType: v4.00+\n")
|
||||
f.write("PlayResX: 3840\n")
|
||||
f.write("PlayResY: 2160\n")
|
||||
f.write("Collisions: Normal\n\n")
|
||||
|
||||
# Write styles
|
||||
f.write("[V4+ Styles]\n")
|
||||
f.write("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n")
|
||||
f.write("Style: Default,Arial,72,&H00FFFFFF,&H00FFFFFF,&H00000000,&H80000000,-1,0,0,0,100,100,0,0,1,3,0,2,20,20,20,1\n\n")
|
||||
|
||||
# Write events
|
||||
f.write("[Events]\n")
|
||||
f.write("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n")
|
||||
|
||||
# Write lyrics
|
||||
for start_time, end_time, text in lyrics:
|
||||
start_str = self._format_time(start_time)
|
||||
end_str = self._format_time(end_time)
|
||||
f.write(f"Dialogue: 0,{start_str},{end_str},Default,,0,0,0,,{text}\n")
|
||||
|
||||
# Copy to output path
|
||||
shutil.copy2(temp_ass_file, ass_file)
|
||||
|
||||
self.logger.info(f"Successfully converted LRC to ASS: {ass_file}")
|
||||
return ass_file
|
||||
|
||||
def _format_time(self, seconds):
|
||||
"""
|
||||
Format time in seconds to ASS format (h:mm:ss.cc).
|
||||
|
||||
Args:
|
||||
seconds: The time in seconds
|
||||
|
||||
Returns:
|
||||
The formatted time string
|
||||
"""
|
||||
hours = int(seconds // 3600)
|
||||
minutes = int((seconds % 3600) // 60)
|
||||
seconds = seconds % 60
|
||||
centiseconds = int((seconds - int(seconds)) * 100)
|
||||
seconds = int(seconds)
|
||||
|
||||
return f"{hours}:{minutes:02d}:{seconds:02d}.{centiseconds:02d}"
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the video renderer.
|
||||
"""
|
||||
self.logger.info("Cleaning up video renderer resources")
|
||||
|
||||
# Clean up any temporary files
|
||||
if hasattr(self, '_temp_files') and self._temp_files:
|
||||
for temp_file in self._temp_files:
|
||||
if os.path.exists(temp_file):
|
||||
try:
|
||||
os.remove(temp_file)
|
||||
self.logger.debug(f"Removed temporary file: {temp_file}")
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to remove temporary file {temp_file}: {str(e)}")
|
||||
|
||||
self.logger.info("Video renderer cleanup complete")
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,236 @@
|
||||
import os
|
||||
import asyncio
|
||||
import logging
|
||||
from typing import List, Optional
|
||||
from karaoke_gen.core.track import Track
|
||||
from karaoke_gen.core.exceptions import VideoError
|
||||
from karaoke_gen.services.video.screens import ScreenGenerator
|
||||
from karaoke_gen.services.video.renderer import VideoRenderer
|
||||
from karaoke_gen.services.video.compositor import VideoCompositor
|
||||
|
||||
|
||||
class VideoService:
|
||||
"""
|
||||
Service for orchestrating the video generation process.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the video service.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger or logging.getLogger(__name__)
|
||||
|
||||
# Initialize components
|
||||
self.screen_generator = ScreenGenerator(config)
|
||||
self.renderer = VideoRenderer(config)
|
||||
self.compositor = VideoCompositor(config)
|
||||
|
||||
async def process_video(self, track: Track) -> Track:
|
||||
"""
|
||||
Process video for a track, including screen generation, rendering, and composition.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Processing video for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Skip if final video already exists and we're not forcing regeneration
|
||||
if track.final_video and os.path.isfile(track.final_video) and not self.config.force_regenerate:
|
||||
self.logger.info(f"Final video already exists for {track.base_name}, skipping video processing")
|
||||
return track
|
||||
|
||||
# Generate screens
|
||||
track = await self.generate_screens(track)
|
||||
|
||||
# Render videos
|
||||
track = await self.render_videos(track)
|
||||
|
||||
# Compose final video
|
||||
track = await self.compose_final_video(track)
|
||||
|
||||
# Create additional versions
|
||||
track = await self.create_additional_versions(track)
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to process video for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def generate_screens(self, track: Track) -> Track:
|
||||
"""
|
||||
Generate title and end screens for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated screen information
|
||||
"""
|
||||
self.logger.info(f"Generating screens for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Generate title screen
|
||||
if not track.title_video or not os.path.isfile(track.title_video) or self.config.force_regenerate:
|
||||
track = await self.screen_generator.generate_title_screen(track)
|
||||
else:
|
||||
self.logger.info(f"Title screen already exists: {track.title_video}")
|
||||
|
||||
# Generate end screen
|
||||
if not track.end_video or not os.path.isfile(track.end_video) or self.config.force_regenerate:
|
||||
track = await self.screen_generator.generate_end_screen(track)
|
||||
else:
|
||||
self.logger.info(f"End screen already exists: {track.end_video}")
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to generate screens for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def render_videos(self, track: Track) -> Track:
|
||||
"""
|
||||
Render videos for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video information
|
||||
"""
|
||||
self.logger.info(f"Rendering videos for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Render lyrics video
|
||||
if (not track.video_with_lyrics or not os.path.isfile(track.video_with_lyrics) or
|
||||
self.config.force_regenerate):
|
||||
track = await self.renderer.render_lyrics_video(track)
|
||||
else:
|
||||
self.logger.info(f"Lyrics video already exists: {track.video_with_lyrics}")
|
||||
|
||||
# Render instrumental video
|
||||
if (not track.video_with_instrumental or not os.path.isfile(track.video_with_instrumental) or
|
||||
self.config.force_regenerate):
|
||||
track = await self.renderer.render_instrumental_video(track)
|
||||
else:
|
||||
self.logger.info(f"Instrumental video already exists: {track.video_with_instrumental}")
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to render videos for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def compose_final_video(self, track: Track) -> Track:
|
||||
"""
|
||||
Compose the final video for the track.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated final video information
|
||||
"""
|
||||
self.logger.info(f"Composing final video for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Skip if final video already exists
|
||||
if track.final_video and os.path.isfile(track.final_video) and not self.config.force_regenerate:
|
||||
self.logger.info(f"Final video already exists: {track.final_video}")
|
||||
return track
|
||||
|
||||
# Check for required videos
|
||||
if not track.title_video or not os.path.isfile(track.title_video):
|
||||
self.logger.warning(f"Title video not found for {track.base_name}")
|
||||
return track
|
||||
|
||||
if not track.video_with_lyrics and not track.video_with_instrumental:
|
||||
self.logger.warning(f"No content videos found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Compose final video
|
||||
track = await self.compositor.compose_final_video(track)
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to compose final video for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def create_additional_versions(self, track: Track) -> Track:
|
||||
"""
|
||||
Create additional versions of the final video.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
|
||||
Returns:
|
||||
The track with updated video version information
|
||||
"""
|
||||
self.logger.info(f"Creating additional video versions for {track.base_name}")
|
||||
|
||||
try:
|
||||
# Skip if no final video
|
||||
if not track.final_video or not os.path.isfile(track.final_video):
|
||||
self.logger.warning(f"No final video found for {track.base_name}")
|
||||
return track
|
||||
|
||||
# Create lossless version
|
||||
if not track.final_video_mkv or not os.path.isfile(track.final_video_mkv) or self.config.force_regenerate:
|
||||
track = await self.compositor.create_lossless_version(track)
|
||||
else:
|
||||
self.logger.info(f"Lossless version already exists: {track.final_video_mkv}")
|
||||
|
||||
# Create 720p version
|
||||
if not track.final_video_720p or not os.path.isfile(track.final_video_720p) or self.config.force_regenerate:
|
||||
track = await self.compositor.create_720p_version(track)
|
||||
else:
|
||||
self.logger.info(f"720p version already exists: {track.final_video_720p}")
|
||||
|
||||
# Create lossy version
|
||||
if not track.final_video_lossy or not os.path.isfile(track.final_video_lossy) or self.config.force_regenerate:
|
||||
track = await self.compositor.create_lossy_version(track)
|
||||
else:
|
||||
self.logger.info(f"Lossy version already exists: {track.final_video_lossy}")
|
||||
|
||||
return track
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create additional versions for {track.base_name}: {str(e)}")
|
||||
# Continue with other processing
|
||||
return track
|
||||
|
||||
async def cleanup(self):
|
||||
"""
|
||||
Perform cleanup operations for the video service.
|
||||
"""
|
||||
self.logger.info("Cleaning up video service resources")
|
||||
|
||||
# Clean up temporary files
|
||||
if self.config.cleanup_temp_files:
|
||||
self.logger.info("Cleaning up temporary video files")
|
||||
# Implementation would depend on what temporary files are created
|
||||
|
||||
# Close any open resources
|
||||
if hasattr(self, 'screen_generator'):
|
||||
await self.screen_generator.cleanup()
|
||||
|
||||
if hasattr(self, 'renderer'):
|
||||
await self.renderer.cleanup()
|
||||
|
||||
if hasattr(self, 'compositor'):
|
||||
await self.compositor.cleanup()
|
||||
|
||||
self.logger.info("Video service cleanup complete")
|
||||
@@ -0,0 +1,545 @@
|
||||
import os
|
||||
import asyncio
|
||||
import tempfile
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import pkg_resources
|
||||
from karaoke_gen.core.exceptions import VideoError
|
||||
|
||||
|
||||
class TextRenderer:
|
||||
"""
|
||||
Handles text rendering for videos.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialize the text renderer.
|
||||
|
||||
Args:
|
||||
config: The project configuration
|
||||
"""
|
||||
self.config = config
|
||||
self.logger = config.logger
|
||||
|
||||
# Path to ffmpeg
|
||||
self.ffmpeg_path = "ffmpeg"
|
||||
|
||||
# Set up ffmpeg base command
|
||||
self.ffmpeg_base_command = f"{self.ffmpeg_path} -hide_banner -nostats"
|
||||
|
||||
if self.config.log_level <= 10: # DEBUG
|
||||
self.ffmpeg_base_command += " -loglevel verbose"
|
||||
else:
|
||||
self.ffmpeg_base_command += " -loglevel fatal"
|
||||
|
||||
async def render_lyrics(self, track, lyrics_file, output_file, font_name=None, font_size=None,
|
||||
font_color=None, outline_color=None, outline_width=None,
|
||||
position=None, alignment=None, background_color=None):
|
||||
"""
|
||||
Render lyrics to a video file.
|
||||
|
||||
Args:
|
||||
track: The track to process
|
||||
lyrics_file: The lyrics file to render
|
||||
output_file: The output file path
|
||||
font_name: The font name
|
||||
font_size: The font size
|
||||
font_color: The font color
|
||||
outline_color: The outline color
|
||||
outline_width: The outline width
|
||||
position: The position
|
||||
alignment: The alignment
|
||||
background_color: The background color
|
||||
|
||||
Returns:
|
||||
The output file path
|
||||
"""
|
||||
self.logger.info(f"Rendering lyrics for {track.base_name}")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_file):
|
||||
self.logger.info(f"Lyrics video already exists: {output_file}")
|
||||
return output_file
|
||||
|
||||
# Check if lyrics file exists
|
||||
if not os.path.isfile(lyrics_file):
|
||||
self.logger.error(f"Lyrics file not found: {lyrics_file}")
|
||||
raise VideoError(f"Lyrics file not found: {lyrics_file}")
|
||||
|
||||
# Set default values
|
||||
font_name = font_name or self.config.lyrics_font or "Arial"
|
||||
font_size = font_size or self.config.lyrics_font_size or 48
|
||||
font_color = font_color or self.config.lyrics_font_color or "white"
|
||||
outline_color = outline_color or self.config.lyrics_outline_color or "black"
|
||||
outline_width = outline_width or self.config.lyrics_outline_width or 2
|
||||
position = position or self.config.lyrics_position or "bottom"
|
||||
alignment = alignment or self.config.lyrics_alignment or "center"
|
||||
background_color = background_color or self.config.lyrics_background_color or "transparent"
|
||||
|
||||
# Get font path
|
||||
font_path = self._get_font_path(font_name)
|
||||
|
||||
# Create subtitles file
|
||||
subtitles_file = await self._create_subtitles_file(
|
||||
lyrics_file,
|
||||
font_path,
|
||||
font_size,
|
||||
font_color,
|
||||
outline_color,
|
||||
outline_width,
|
||||
position,
|
||||
alignment,
|
||||
background_color
|
||||
)
|
||||
|
||||
# Create video with subtitles
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
# Create a black video if no input video is provided
|
||||
temp_video = await self._create_temp_black_video(track.duration)
|
||||
|
||||
# Add subtitles to video
|
||||
await self._add_subtitles_to_video(temp_video, subtitles_file, output_file)
|
||||
|
||||
# Clean up temporary files
|
||||
os.remove(temp_video)
|
||||
os.remove(subtitles_file)
|
||||
|
||||
self.logger.info(f"Successfully rendered lyrics: {output_file}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to render lyrics: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render lyrics: {output_file}")
|
||||
|
||||
return output_file
|
||||
|
||||
async def render_text_overlay(self, input_video, output_video, text, font_name=None, font_size=None,
|
||||
font_color=None, outline_color=None, outline_width=None,
|
||||
position=None, alignment=None, background_color=None,
|
||||
start_time=None, end_time=None):
|
||||
"""
|
||||
Render text overlay on a video.
|
||||
|
||||
Args:
|
||||
input_video: The input video file
|
||||
output_video: The output video file
|
||||
text: The text to render
|
||||
font_name: The font name
|
||||
font_size: The font size
|
||||
font_color: The font color
|
||||
outline_color: The outline color
|
||||
outline_width: The outline width
|
||||
position: The position
|
||||
alignment: The alignment
|
||||
background_color: The background color
|
||||
start_time: The start time
|
||||
end_time: The end time
|
||||
|
||||
Returns:
|
||||
The output video file
|
||||
"""
|
||||
self.logger.info(f"Rendering text overlay on {input_video}")
|
||||
|
||||
# Skip if output already exists
|
||||
if os.path.isfile(output_video):
|
||||
self.logger.info(f"Text overlay video already exists: {output_video}")
|
||||
return output_video
|
||||
|
||||
# Check if input video exists
|
||||
if not os.path.isfile(input_video):
|
||||
self.logger.error(f"Input video not found: {input_video}")
|
||||
raise VideoError(f"Input video not found: {input_video}")
|
||||
|
||||
# Set default values
|
||||
font_name = font_name or self.config.overlay_font or "Arial"
|
||||
font_size = font_size or self.config.overlay_font_size or 48
|
||||
font_color = font_color or self.config.overlay_font_color or "white"
|
||||
outline_color = outline_color or self.config.overlay_outline_color or "black"
|
||||
outline_width = outline_width or self.config.overlay_outline_width or 2
|
||||
position = position or self.config.overlay_position or "bottom"
|
||||
alignment = alignment or self.config.overlay_alignment or "center"
|
||||
background_color = background_color or self.config.overlay_background_color or "transparent"
|
||||
|
||||
# Get font path
|
||||
font_path = self._get_font_path(font_name)
|
||||
|
||||
# Create subtitles file with single entry
|
||||
subtitles_file = await self._create_simple_subtitles_file(
|
||||
text,
|
||||
start_time or 0,
|
||||
end_time or 999999,
|
||||
font_path,
|
||||
font_size,
|
||||
font_color,
|
||||
outline_color,
|
||||
outline_width,
|
||||
position,
|
||||
alignment,
|
||||
background_color
|
||||
)
|
||||
|
||||
# Add subtitles to video
|
||||
if not self.config.dry_run:
|
||||
try:
|
||||
await self._add_subtitles_to_video(input_video, subtitles_file, output_video)
|
||||
|
||||
# Clean up temporary files
|
||||
os.remove(subtitles_file)
|
||||
|
||||
self.logger.info(f"Successfully rendered text overlay: {output_video}")
|
||||
|
||||
except Exception as e:
|
||||
raise VideoError(f"Failed to render text overlay: {str(e)}") from e
|
||||
else:
|
||||
self.logger.info(f"[DRY RUN] Would render text overlay: {output_video}")
|
||||
|
||||
return output_video
|
||||
|
||||
def _get_font_path(self, font_name):
|
||||
"""
|
||||
Get the path to a font file.
|
||||
|
||||
Args:
|
||||
font_name: The font name
|
||||
|
||||
Returns:
|
||||
The font path
|
||||
"""
|
||||
# Check if font is a path
|
||||
if os.path.isfile(font_name):
|
||||
return font_name
|
||||
|
||||
# Check in resources directory
|
||||
resources_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "resources")
|
||||
font_path = os.path.join(resources_dir, font_name)
|
||||
if os.path.isfile(font_path):
|
||||
return font_path
|
||||
|
||||
# Try to find font in package resources
|
||||
try:
|
||||
font_path = pkg_resources.resource_filename("karaoke_gen", f"resources/{font_name}")
|
||||
if os.path.isfile(font_path):
|
||||
return font_path
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Default to a system font
|
||||
self.logger.warning(f"Font not found: {font_name}, using default font")
|
||||
return font_name
|
||||
|
||||
async def _create_subtitles_file(self, lyrics_file, font_path, font_size, font_color,
|
||||
outline_color, outline_width, position, alignment, background_color):
|
||||
"""
|
||||
Create a subtitles file from a lyrics file.
|
||||
|
||||
Args:
|
||||
lyrics_file: The lyrics file
|
||||
font_path: The font path
|
||||
font_size: The font size
|
||||
font_color: The font color
|
||||
outline_color: The outline color
|
||||
outline_width: The outline width
|
||||
position: The position
|
||||
alignment: The alignment
|
||||
background_color: The background color
|
||||
|
||||
Returns:
|
||||
The subtitles file path
|
||||
"""
|
||||
# Create a temporary file for subtitles
|
||||
with tempfile.NamedTemporaryFile(suffix=".ass", delete=False) as temp_file:
|
||||
subtitles_file = temp_file.name
|
||||
|
||||
# Parse LRC file and convert to ASS format
|
||||
with open(lyrics_file, "r", encoding="utf-8") as f:
|
||||
lrc_lines = f.readlines()
|
||||
|
||||
# Write ASS header
|
||||
with open(subtitles_file, "w", encoding="utf-8") as f:
|
||||
f.write("[Script Info]\n")
|
||||
f.write("Title: Lyrics\n")
|
||||
f.write("ScriptType: v4.00+\n")
|
||||
f.write("WrapStyle: 0\n")
|
||||
f.write("ScaledBorderAndShadow: yes\n")
|
||||
f.write("YCbCr Matrix: None\n\n")
|
||||
|
||||
f.write("[V4+ Styles]\n")
|
||||
f.write("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n")
|
||||
|
||||
# Convert colors to ASS format
|
||||
primary_color = self._color_to_ass(font_color)
|
||||
outline_color_ass = self._color_to_ass(outline_color)
|
||||
background_color_ass = self._color_to_ass(background_color)
|
||||
|
||||
# Set alignment based on position and alignment
|
||||
ass_alignment = self._get_ass_alignment(position, alignment)
|
||||
|
||||
# Set margin based on position
|
||||
margin_v = 20 if position == "bottom" else (20 if position == "top" else 10)
|
||||
|
||||
f.write(f"Style: Default,{os.path.basename(font_path)},{font_size},{primary_color},{primary_color},{outline_color_ass},{background_color_ass},0,0,0,0,100,100,0,0,1,{outline_width},0,{ass_alignment},10,10,{margin_v},1\n\n")
|
||||
|
||||
f.write("[Events]\n")
|
||||
f.write("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n")
|
||||
|
||||
# Parse LRC lines
|
||||
events = []
|
||||
for line in lrc_lines:
|
||||
line = line.strip()
|
||||
if line and "[" in line and "]" in line:
|
||||
try:
|
||||
time_tag = line[line.find("[") + 1:line.find("]")]
|
||||
if ":" in time_tag and "." in time_tag:
|
||||
minutes, rest = time_tag.split(":")
|
||||
seconds, milliseconds = rest.split(".")
|
||||
|
||||
start_time_seconds = int(minutes) * 60 + int(seconds) + int(milliseconds) / 100
|
||||
text = line[line.find("]") + 1:].strip()
|
||||
|
||||
if text: # Only add non-empty lines
|
||||
events.append((start_time_seconds, text))
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to parse LRC line: {line}, error: {str(e)}")
|
||||
|
||||
# Sort events by start time
|
||||
events.sort(key=lambda x: x[0])
|
||||
|
||||
# Write events with end times
|
||||
for i, (start_time, text) in enumerate(events):
|
||||
# Set end time to the start time of the next event, or 5 seconds after if it's the last event
|
||||
end_time = events[i + 1][0] if i < len(events) - 1 else start_time + 5
|
||||
|
||||
# Format times as h:mm:ss.cc
|
||||
start_time_formatted = self._format_ass_time(start_time)
|
||||
end_time_formatted = self._format_ass_time(end_time)
|
||||
|
||||
# Escape special characters
|
||||
text = text.replace("\\", "\\\\").replace("{", "\\{").replace("}", "\\}")
|
||||
|
||||
f.write(f"Dialogue: 0,{start_time_formatted},{end_time_formatted},Default,,0,0,0,,{text}\n")
|
||||
|
||||
return subtitles_file
|
||||
|
||||
async def _create_simple_subtitles_file(self, text, start_time, end_time, font_path, font_size,
|
||||
font_color, outline_color, outline_width, position,
|
||||
alignment, background_color):
|
||||
"""
|
||||
Create a simple subtitles file with a single entry.
|
||||
|
||||
Args:
|
||||
text: The text
|
||||
start_time: The start time in seconds
|
||||
end_time: The end time in seconds
|
||||
font_path: The font path
|
||||
font_size: The font size
|
||||
font_color: The font color
|
||||
outline_color: The outline color
|
||||
outline_width: The outline width
|
||||
position: The position
|
||||
alignment: The alignment
|
||||
background_color: The background color
|
||||
|
||||
Returns:
|
||||
The subtitles file path
|
||||
"""
|
||||
# Create a temporary file for subtitles
|
||||
with tempfile.NamedTemporaryFile(suffix=".ass", delete=False) as temp_file:
|
||||
subtitles_file = temp_file.name
|
||||
|
||||
# Write ASS header
|
||||
with open(subtitles_file, "w", encoding="utf-8") as f:
|
||||
f.write("[Script Info]\n")
|
||||
f.write("Title: Text Overlay\n")
|
||||
f.write("ScriptType: v4.00+\n")
|
||||
f.write("WrapStyle: 0\n")
|
||||
f.write("ScaledBorderAndShadow: yes\n")
|
||||
f.write("YCbCr Matrix: None\n\n")
|
||||
|
||||
f.write("[V4+ Styles]\n")
|
||||
f.write("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding\n")
|
||||
|
||||
# Convert colors to ASS format
|
||||
primary_color = self._color_to_ass(font_color)
|
||||
outline_color_ass = self._color_to_ass(outline_color)
|
||||
background_color_ass = self._color_to_ass(background_color)
|
||||
|
||||
# Set alignment based on position and alignment
|
||||
ass_alignment = self._get_ass_alignment(position, alignment)
|
||||
|
||||
# Set margin based on position
|
||||
margin_v = 20 if position == "bottom" else (20 if position == "top" else 10)
|
||||
|
||||
f.write(f"Style: Default,{os.path.basename(font_path)},{font_size},{primary_color},{primary_color},{outline_color_ass},{background_color_ass},0,0,0,0,100,100,0,0,1,{outline_width},0,{ass_alignment},10,10,{margin_v},1\n\n")
|
||||
|
||||
f.write("[Events]\n")
|
||||
f.write("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n")
|
||||
|
||||
# Format times as h:mm:ss.cc
|
||||
start_time_formatted = self._format_ass_time(start_time)
|
||||
end_time_formatted = self._format_ass_time(end_time)
|
||||
|
||||
# Escape special characters
|
||||
text = text.replace("\\", "\\\\").replace("{", "\\{").replace("}", "\\}")
|
||||
|
||||
f.write(f"Dialogue: 0,{start_time_formatted},{end_time_formatted},Default,,0,0,0,,{text}\n")
|
||||
|
||||
return subtitles_file
|
||||
|
||||
def _color_to_ass(self, color):
|
||||
"""
|
||||
Convert a color to ASS format.
|
||||
|
||||
Args:
|
||||
color: The color
|
||||
|
||||
Returns:
|
||||
The ASS color
|
||||
"""
|
||||
if color == "transparent":
|
||||
return "&H00FFFFFF" # Transparent
|
||||
|
||||
# Handle hex colors
|
||||
if color.startswith("#"):
|
||||
r = int(color[1:3], 16)
|
||||
g = int(color[3:5], 16)
|
||||
b = int(color[5:7], 16)
|
||||
return f"&H00{b:02X}{g:02X}{r:02X}"
|
||||
|
||||
# Handle named colors
|
||||
color_map = {
|
||||
"white": "&H00FFFFFF",
|
||||
"black": "&H00000000",
|
||||
"red": "&H000000FF",
|
||||
"green": "&H0000FF00",
|
||||
"blue": "&H00FF0000",
|
||||
"yellow": "&H0000FFFF",
|
||||
"cyan": "&H00FFFF00",
|
||||
"magenta": "&H00FF00FF",
|
||||
}
|
||||
|
||||
return color_map.get(color.lower(), "&H00FFFFFF") # Default to white
|
||||
|
||||
def _get_ass_alignment(self, position, alignment):
|
||||
"""
|
||||
Get the ASS alignment value.
|
||||
|
||||
Args:
|
||||
position: The position
|
||||
alignment: The alignment
|
||||
|
||||
Returns:
|
||||
The ASS alignment value
|
||||
"""
|
||||
# ASS alignment values:
|
||||
# 1: bottom left, 2: bottom center, 3: bottom right
|
||||
# 4: middle left, 5: middle center, 6: middle right
|
||||
# 7: top left, 8: top center, 9: top right
|
||||
|
||||
if position == "bottom":
|
||||
if alignment == "left":
|
||||
return 1
|
||||
elif alignment == "right":
|
||||
return 3
|
||||
else: # center
|
||||
return 2
|
||||
elif position == "middle":
|
||||
if alignment == "left":
|
||||
return 4
|
||||
elif alignment == "right":
|
||||
return 6
|
||||
else: # center
|
||||
return 5
|
||||
elif position == "top":
|
||||
if alignment == "left":
|
||||
return 7
|
||||
elif alignment == "right":
|
||||
return 9
|
||||
else: # center
|
||||
return 8
|
||||
else:
|
||||
return 2 # Default to bottom center
|
||||
|
||||
def _format_ass_time(self, seconds):
|
||||
"""
|
||||
Format seconds as h:mm:ss.cc for ASS format.
|
||||
|
||||
Args:
|
||||
seconds: The time in seconds
|
||||
|
||||
Returns:
|
||||
The formatted time
|
||||
"""
|
||||
hours = int(seconds // 3600)
|
||||
minutes = int((seconds % 3600) // 60)
|
||||
seconds_remainder = seconds % 60
|
||||
centiseconds = int((seconds_remainder - int(seconds_remainder)) * 100)
|
||||
|
||||
return f"{hours}:{minutes:02d}:{int(seconds_remainder):02d}.{centiseconds:02d}"
|
||||
|
||||
async def _create_temp_black_video(self, duration):
|
||||
"""
|
||||
Create a temporary black video.
|
||||
|
||||
Args:
|
||||
duration: The duration in seconds
|
||||
|
||||
Returns:
|
||||
The temporary video file path
|
||||
"""
|
||||
# Create a temporary file for the video
|
||||
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as temp_file:
|
||||
temp_video = temp_file.name
|
||||
|
||||
# Create a black video
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -f lavfi -i color=c=black:s=1920x1080:r=30 '
|
||||
f'-t {duration} -c:v libx264 -pix_fmt yuv420p "{temp_video}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Creating temporary black video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to create temporary black video: {error_message}")
|
||||
|
||||
return temp_video
|
||||
|
||||
async def _add_subtitles_to_video(self, input_video, subtitles_file, output_video):
|
||||
"""
|
||||
Add subtitles to a video.
|
||||
|
||||
Args:
|
||||
input_video: The input video file
|
||||
subtitles_file: The subtitles file
|
||||
output_video: The output video file
|
||||
|
||||
Returns:
|
||||
The output video file
|
||||
"""
|
||||
# Add subtitles to video
|
||||
command = (
|
||||
f'{self.ffmpeg_base_command} -i "{input_video}" -vf '
|
||||
f'ass="{subtitles_file}" -c:v prores_ks -profile:v 3 -vendor ap10 '
|
||||
f'-bits_per_mb 8000 -pix_fmt yuv422p10le "{output_video}"'
|
||||
)
|
||||
|
||||
self.logger.debug(f"Adding subtitles to video: {command}")
|
||||
process = await asyncio.create_subprocess_shell(
|
||||
command,
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
stderr=asyncio.subprocess.PIPE
|
||||
)
|
||||
stdout, stderr = await process.communicate()
|
||||
|
||||
if process.returncode != 0:
|
||||
error_message = stderr.decode() if stderr else "Unknown error"
|
||||
raise VideoError(f"Failed to add subtitles to video: {error_message}")
|
||||
|
||||
return output_video
|
||||
@@ -0,0 +1,108 @@
|
||||
"""
|
||||
Utility functions for the karaoke_gen package.
|
||||
"""
|
||||
|
||||
# Import utility modules
|
||||
from karaoke_gen.utils import config
|
||||
from karaoke_gen.utils import date
|
||||
from karaoke_gen.utils import file
|
||||
from karaoke_gen.utils import logging
|
||||
from karaoke_gen.utils import path
|
||||
from karaoke_gen.utils import string
|
||||
from karaoke_gen.utils import validation
|
||||
|
||||
# Re-export functions from config module
|
||||
from karaoke_gen.utils.config import (
|
||||
load_config_file,
|
||||
save_config_file,
|
||||
get_config_value,
|
||||
set_config_value,
|
||||
merge_configs,
|
||||
validate_required_config_keys,
|
||||
get_nested_config_value,
|
||||
set_nested_config_value,
|
||||
)
|
||||
|
||||
# Re-export functions from date module
|
||||
from karaoke_gen.utils.date import (
|
||||
get_current_timestamp,
|
||||
get_current_date,
|
||||
get_current_time,
|
||||
format_date,
|
||||
parse_date,
|
||||
get_date_components,
|
||||
add_days,
|
||||
days_between,
|
||||
is_date_in_range,
|
||||
get_month_name,
|
||||
get_day_of_week,
|
||||
)
|
||||
|
||||
# Re-export functions from file module
|
||||
from karaoke_gen.utils.file import (
|
||||
sanitize_filename,
|
||||
ensure_directory_exists,
|
||||
backup_existing_files,
|
||||
file_exists,
|
||||
copy_file,
|
||||
move_file,
|
||||
delete_file,
|
||||
create_zip_file,
|
||||
execute_command,
|
||||
)
|
||||
|
||||
# Re-export functions from logging module
|
||||
from karaoke_gen.utils.logging import (
|
||||
setup_logger,
|
||||
get_log_level_from_string,
|
||||
configure_logger_from_config,
|
||||
log_section,
|
||||
log_subsection,
|
||||
log_dict,
|
||||
log_exception,
|
||||
)
|
||||
|
||||
# Re-export functions from path module
|
||||
from karaoke_gen.utils.path import (
|
||||
normalize_path,
|
||||
join_paths,
|
||||
get_absolute_path,
|
||||
get_relative_path,
|
||||
get_parent_directory,
|
||||
get_filename,
|
||||
get_filename_without_extension,
|
||||
get_file_extension,
|
||||
create_directory,
|
||||
delete_directory,
|
||||
list_files,
|
||||
list_directories,
|
||||
get_file_info,
|
||||
find_files_by_extension,
|
||||
copy_directory,
|
||||
move_directory,
|
||||
get_directory_size,
|
||||
)
|
||||
|
||||
# Re-export functions from string module
|
||||
from karaoke_gen.utils.string import (
|
||||
slugify,
|
||||
truncate_string,
|
||||
extract_artist_and_title,
|
||||
format_duration,
|
||||
format_filesize,
|
||||
strip_html_tags,
|
||||
normalize_whitespace,
|
||||
extract_urls,
|
||||
replace_placeholders,
|
||||
generate_random_string,
|
||||
)
|
||||
|
||||
# Re-export functions from validation module
|
||||
from karaoke_gen.utils.validation import (
|
||||
is_url,
|
||||
is_file,
|
||||
is_directory,
|
||||
prompt_user_confirmation_or_raise_exception,
|
||||
prompt_user_bool,
|
||||
validate_input_parameters_for_features,
|
||||
)
|
||||
@@ -0,0 +1,204 @@
|
||||
"""
|
||||
Configuration utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from typing import Dict, Any, Optional, List, Union
|
||||
|
||||
|
||||
def load_config_file(config_file: str, logger: Optional[logging.Logger] = None) -> Dict[str, Any]:
|
||||
"""
|
||||
Load a configuration file.
|
||||
|
||||
Args:
|
||||
config_file: The configuration file to load
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
The loaded configuration
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If the configuration file does not exist
|
||||
json.JSONDecodeError: If the configuration file is not valid JSON
|
||||
"""
|
||||
if logger:
|
||||
logger.info(f"Loading configuration from {config_file}")
|
||||
|
||||
if not os.path.isfile(config_file):
|
||||
error_msg = f"Configuration file not found: {config_file}"
|
||||
if logger:
|
||||
logger.error(error_msg)
|
||||
raise FileNotFoundError(error_msg)
|
||||
|
||||
try:
|
||||
with open(config_file, "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
if logger:
|
||||
logger.info(f"Successfully loaded configuration from {config_file}")
|
||||
return config
|
||||
except json.JSONDecodeError as e:
|
||||
error_msg = f"Invalid JSON in configuration file {config_file}: {str(e)}"
|
||||
if logger:
|
||||
logger.error(error_msg)
|
||||
raise
|
||||
|
||||
|
||||
def save_config_file(config_file: str, config: Dict[str, Any], logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Save a configuration file.
|
||||
|
||||
Args:
|
||||
config_file: The configuration file to save
|
||||
config: The configuration to save
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the configuration was saved successfully, False otherwise
|
||||
"""
|
||||
if logger:
|
||||
logger.info(f"Saving configuration to {config_file}")
|
||||
|
||||
try:
|
||||
# Create directory if it doesn't exist
|
||||
os.makedirs(os.path.dirname(config_file), exist_ok=True)
|
||||
|
||||
with open(config_file, "w") as f:
|
||||
json.dump(config, f, indent=4)
|
||||
|
||||
if logger:
|
||||
logger.info(f"Successfully saved configuration to {config_file}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to save configuration to {config_file}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def get_config_value(config: Dict[str, Any], key: str, default: Any = None) -> Any:
|
||||
"""
|
||||
Get a value from a configuration dictionary.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
key: The key to get
|
||||
default: The default value to return if the key is not found
|
||||
|
||||
Returns:
|
||||
The value for the key, or the default value if the key is not found
|
||||
"""
|
||||
return config.get(key, default)
|
||||
|
||||
|
||||
def set_config_value(config: Dict[str, Any], key: str, value: Any) -> Dict[str, Any]:
|
||||
"""
|
||||
Set a value in a configuration dictionary.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
key: The key to set
|
||||
value: The value to set
|
||||
|
||||
Returns:
|
||||
The updated configuration dictionary
|
||||
"""
|
||||
config[key] = value
|
||||
return config
|
||||
|
||||
|
||||
def merge_configs(base_config: Dict[str, Any], override_config: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Merge two configuration dictionaries.
|
||||
|
||||
Args:
|
||||
base_config: The base configuration dictionary
|
||||
override_config: The override configuration dictionary
|
||||
|
||||
Returns:
|
||||
The merged configuration dictionary
|
||||
"""
|
||||
result = base_config.copy()
|
||||
|
||||
for key, value in override_config.items():
|
||||
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
|
||||
result[key] = merge_configs(result[key], value)
|
||||
else:
|
||||
result[key] = value
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_required_config_keys(config: Dict[str, Any], required_keys: List[str], logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Validate that a configuration dictionary contains all required keys.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
required_keys: The required keys
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if all required keys are present, False otherwise
|
||||
"""
|
||||
missing_keys = [key for key in required_keys if key not in config]
|
||||
|
||||
if missing_keys:
|
||||
if logger:
|
||||
logger.error(f"Missing required configuration keys: {', '.join(missing_keys)}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def get_nested_config_value(config: Dict[str, Any], key_path: str, default: Any = None) -> Any:
|
||||
"""
|
||||
Get a nested value from a configuration dictionary using a dot-separated path.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
key_path: The dot-separated path to the key
|
||||
default: The default value to return if the key is not found
|
||||
|
||||
Returns:
|
||||
The value for the key, or the default value if the key is not found
|
||||
"""
|
||||
keys = key_path.split(".")
|
||||
current = config
|
||||
|
||||
for key in keys:
|
||||
if not isinstance(current, dict) or key not in current:
|
||||
return default
|
||||
current = current[key]
|
||||
|
||||
return current
|
||||
|
||||
|
||||
def set_nested_config_value(config: Dict[str, Any], key_path: str, value: Any) -> Dict[str, Any]:
|
||||
"""
|
||||
Set a nested value in a configuration dictionary using a dot-separated path.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
key_path: The dot-separated path to the key
|
||||
value: The value to set
|
||||
|
||||
Returns:
|
||||
The updated configuration dictionary
|
||||
"""
|
||||
keys = key_path.split(".")
|
||||
current = config
|
||||
|
||||
# Navigate to the parent of the final key
|
||||
for key in keys[:-1]:
|
||||
if key not in current:
|
||||
current[key] = {}
|
||||
elif not isinstance(current[key], dict):
|
||||
current[key] = {}
|
||||
current = current[key]
|
||||
|
||||
# Set the value at the final key
|
||||
current[keys[-1]] = value
|
||||
|
||||
return config
|
||||
@@ -0,0 +1,223 @@
|
||||
"""
|
||||
Date utility functions.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from typing import Optional, Union, Dict, Any
|
||||
|
||||
|
||||
def get_current_timestamp() -> str:
|
||||
"""
|
||||
Get the current timestamp in ISO 8601 format.
|
||||
|
||||
Returns:
|
||||
The current timestamp in ISO 8601 format
|
||||
"""
|
||||
return datetime.datetime.now().isoformat()
|
||||
|
||||
|
||||
def get_current_date() -> str:
|
||||
"""
|
||||
Get the current date in YYYY-MM-DD format.
|
||||
|
||||
Returns:
|
||||
The current date in YYYY-MM-DD format
|
||||
"""
|
||||
return datetime.date.today().isoformat()
|
||||
|
||||
|
||||
def get_current_time() -> str:
|
||||
"""
|
||||
Get the current time in HH:MM:SS format.
|
||||
|
||||
Returns:
|
||||
The current time in HH:MM:SS format
|
||||
"""
|
||||
return datetime.datetime.now().strftime("%H:%M:%S")
|
||||
|
||||
|
||||
def format_date(date: Union[datetime.date, datetime.datetime, str], format_string: str = "%Y-%m-%d") -> str:
|
||||
"""
|
||||
Format a date object or string as a string.
|
||||
|
||||
Args:
|
||||
date: The date to format
|
||||
format_string: The format string to use
|
||||
|
||||
Returns:
|
||||
The formatted date string
|
||||
|
||||
Raises:
|
||||
ValueError: If the date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(date, str):
|
||||
try:
|
||||
date = datetime.datetime.fromisoformat(date)
|
||||
except ValueError:
|
||||
try:
|
||||
date = datetime.datetime.strptime(date, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid date string: {date}")
|
||||
|
||||
return date.strftime(format_string)
|
||||
|
||||
|
||||
def parse_date(date_string: str, format_string: Optional[str] = None) -> datetime.date:
|
||||
"""
|
||||
Parse a date string into a date object.
|
||||
|
||||
Args:
|
||||
date_string: The date string to parse
|
||||
format_string: The format string to use (optional)
|
||||
|
||||
Returns:
|
||||
The parsed date object
|
||||
|
||||
Raises:
|
||||
ValueError: If the date string is not valid
|
||||
"""
|
||||
if format_string:
|
||||
return datetime.datetime.strptime(date_string, format_string).date()
|
||||
|
||||
try:
|
||||
return datetime.date.fromisoformat(date_string)
|
||||
except ValueError:
|
||||
try:
|
||||
return datetime.datetime.fromisoformat(date_string).date()
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid date string: {date_string}")
|
||||
|
||||
|
||||
def get_date_components(date: Union[datetime.date, datetime.datetime, str]) -> Dict[str, int]:
|
||||
"""
|
||||
Get the components of a date.
|
||||
|
||||
Args:
|
||||
date: The date to get components from
|
||||
|
||||
Returns:
|
||||
A dictionary with "year", "month", and "day" keys
|
||||
|
||||
Raises:
|
||||
ValueError: If the date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(date, str):
|
||||
date = parse_date(date)
|
||||
|
||||
return {
|
||||
"year": date.year,
|
||||
"month": date.month,
|
||||
"day": date.day,
|
||||
}
|
||||
|
||||
|
||||
def add_days(date: Union[datetime.date, datetime.datetime, str], days: int) -> datetime.date:
|
||||
"""
|
||||
Add days to a date.
|
||||
|
||||
Args:
|
||||
date: The date to add days to
|
||||
days: The number of days to add
|
||||
|
||||
Returns:
|
||||
The new date
|
||||
|
||||
Raises:
|
||||
ValueError: If the date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(date, str):
|
||||
date = parse_date(date)
|
||||
|
||||
return date + datetime.timedelta(days=days)
|
||||
|
||||
|
||||
def days_between(start_date: Union[datetime.date, datetime.datetime, str],
|
||||
end_date: Union[datetime.date, datetime.datetime, str]) -> int:
|
||||
"""
|
||||
Calculate the number of days between two dates.
|
||||
|
||||
Args:
|
||||
start_date: The start date
|
||||
end_date: The end date
|
||||
|
||||
Returns:
|
||||
The number of days between the dates
|
||||
|
||||
Raises:
|
||||
ValueError: If either date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(start_date, str):
|
||||
start_date = parse_date(start_date)
|
||||
|
||||
if isinstance(end_date, str):
|
||||
end_date = parse_date(end_date)
|
||||
|
||||
delta = end_date - start_date
|
||||
return delta.days
|
||||
|
||||
|
||||
def is_date_in_range(date: Union[datetime.date, datetime.datetime, str],
|
||||
start_date: Union[datetime.date, datetime.datetime, str],
|
||||
end_date: Union[datetime.date, datetime.datetime, str]) -> bool:
|
||||
"""
|
||||
Check if a date is within a range.
|
||||
|
||||
Args:
|
||||
date: The date to check
|
||||
start_date: The start date of the range
|
||||
end_date: The end date of the range
|
||||
|
||||
Returns:
|
||||
True if the date is within the range, False otherwise
|
||||
|
||||
Raises:
|
||||
ValueError: If any date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(date, str):
|
||||
date = parse_date(date)
|
||||
|
||||
if isinstance(start_date, str):
|
||||
start_date = parse_date(start_date)
|
||||
|
||||
if isinstance(end_date, str):
|
||||
end_date = parse_date(end_date)
|
||||
|
||||
return start_date <= date <= end_date
|
||||
|
||||
|
||||
def get_month_name(month: int) -> str:
|
||||
"""
|
||||
Get the name of a month.
|
||||
|
||||
Args:
|
||||
month: The month number (1-12)
|
||||
|
||||
Returns:
|
||||
The month name
|
||||
|
||||
Raises:
|
||||
ValueError: If the month is not valid
|
||||
"""
|
||||
if not 1 <= month <= 12:
|
||||
raise ValueError(f"Invalid month: {month}")
|
||||
|
||||
return datetime.date(2000, month, 1).strftime("%B")
|
||||
|
||||
|
||||
def get_day_of_week(date: Union[datetime.date, datetime.datetime, str]) -> str:
|
||||
"""
|
||||
Get the day of the week for a date.
|
||||
|
||||
Args:
|
||||
date: The date to get the day of the week for
|
||||
|
||||
Returns:
|
||||
The day of the week
|
||||
|
||||
Raises:
|
||||
ValueError: If the date is not a valid date object or string
|
||||
"""
|
||||
if isinstance(date, str):
|
||||
date = parse_date(date)
|
||||
|
||||
return date.strftime("%A")
|
||||
@@ -0,0 +1,233 @@
|
||||
"""
|
||||
File utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import logging
|
||||
import zipfile
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
|
||||
def sanitize_filename(filename: str) -> str:
|
||||
"""
|
||||
Sanitize a filename to be safe for all operating systems.
|
||||
|
||||
Args:
|
||||
filename: The filename to sanitize
|
||||
|
||||
Returns:
|
||||
The sanitized filename
|
||||
"""
|
||||
# Replace invalid characters with underscores
|
||||
sanitized = re.sub(r'[\\/*?:"<>|]', "_", filename)
|
||||
# Remove leading/trailing whitespace and dots
|
||||
sanitized = sanitized.strip(". ")
|
||||
# Ensure the filename is not empty
|
||||
if not sanitized:
|
||||
sanitized = "unnamed"
|
||||
return sanitized
|
||||
|
||||
|
||||
def ensure_directory_exists(directory: str) -> None:
|
||||
"""
|
||||
Ensure a directory exists, creating it if necessary.
|
||||
|
||||
Args:
|
||||
directory: The directory to ensure exists
|
||||
"""
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
|
||||
|
||||
def backup_existing_files(file_path: str, max_backups: int = 5) -> None:
|
||||
"""
|
||||
Backup existing files to prevent overwriting.
|
||||
|
||||
Args:
|
||||
file_path: The file to backup
|
||||
max_backups: The maximum number of backups to keep
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
return
|
||||
|
||||
# Create backup directory
|
||||
backup_dir = os.path.join(os.path.dirname(file_path), "backups")
|
||||
ensure_directory_exists(backup_dir)
|
||||
|
||||
# Get base filename
|
||||
base_name = os.path.basename(file_path)
|
||||
|
||||
# Create backup filename with timestamp
|
||||
from datetime import datetime
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
backup_file = os.path.join(backup_dir, f"{base_name}.{timestamp}")
|
||||
|
||||
# Copy the file to the backup location
|
||||
shutil.copy2(file_path, backup_file)
|
||||
|
||||
# Remove old backups if there are too many
|
||||
backup_files = [
|
||||
os.path.join(backup_dir, f) for f in os.listdir(backup_dir)
|
||||
if f.startswith(base_name + ".")
|
||||
]
|
||||
backup_files.sort(key=os.path.getmtime)
|
||||
|
||||
if len(backup_files) > max_backups:
|
||||
for old_backup in backup_files[:-max_backups]:
|
||||
os.remove(old_backup)
|
||||
|
||||
|
||||
def file_exists(file_path: str) -> bool:
|
||||
"""
|
||||
Check if a file exists with proper error handling.
|
||||
|
||||
Args:
|
||||
file_path: The file to check
|
||||
|
||||
Returns:
|
||||
True if the file exists, False otherwise
|
||||
"""
|
||||
try:
|
||||
return os.path.isfile(file_path)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def copy_file(source: str, destination: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Copy a file with proper error handling.
|
||||
|
||||
Args:
|
||||
source: The source file
|
||||
destination: The destination file
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the copy was successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
shutil.copy2(source, destination)
|
||||
if logger:
|
||||
logger.info(f"Copied {source} to {destination}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to copy {source} to {destination}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def move_file(source: str, destination: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Move a file with proper error handling.
|
||||
|
||||
Args:
|
||||
source: The source file
|
||||
destination: The destination file
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the move was successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
shutil.move(source, destination)
|
||||
if logger:
|
||||
logger.info(f"Moved {source} to {destination}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to move {source} to {destination}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def delete_file(file_path: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Delete a file with proper error handling.
|
||||
|
||||
Args:
|
||||
file_path: The file to delete
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the deletion was successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
os.remove(file_path)
|
||||
if logger:
|
||||
logger.info(f"Deleted {file_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to delete {file_path}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def create_zip_file(zip_file: str, files: List[str], logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Create a zip file from a list of files.
|
||||
|
||||
Args:
|
||||
zip_file: The zip file to create
|
||||
files: The files to include in the zip file
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the zip file was created successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
with zipfile.ZipFile(zip_file, "w") as zipf:
|
||||
for file in files:
|
||||
if os.path.isfile(file):
|
||||
zipf.write(file, os.path.basename(file))
|
||||
if logger:
|
||||
logger.info(f"Added {file} to {zip_file}")
|
||||
|
||||
if logger:
|
||||
logger.info(f"Created zip file: {zip_file}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to create zip file {zip_file}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def execute_command(command: str, description: str, logger: Optional[logging.Logger] = None, dry_run: bool = False) -> bool:
|
||||
"""
|
||||
Execute a shell command with proper error handling.
|
||||
|
||||
Args:
|
||||
command: The command to execute
|
||||
description: A description of the command
|
||||
logger: The logger to use
|
||||
dry_run: Whether to perform a dry run
|
||||
|
||||
Returns:
|
||||
True if the command was executed successfully, False otherwise
|
||||
"""
|
||||
if logger:
|
||||
logger.info(description)
|
||||
|
||||
if dry_run:
|
||||
if logger:
|
||||
logger.info(f"DRY RUN: Would run command: {command}")
|
||||
return True
|
||||
|
||||
if logger:
|
||||
logger.info(f"Running command: {command}")
|
||||
|
||||
try:
|
||||
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
|
||||
if logger and result.stdout:
|
||||
logger.debug(f"Command output: {result.stdout}")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
if logger:
|
||||
logger.error(f"Command failed with exit code {e.returncode}")
|
||||
logger.error(f"Command output (stdout): {e.stdout}")
|
||||
logger.error(f"Command output (stderr): {e.stderr}")
|
||||
return False
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to execute command: {str(e)}")
|
||||
return False
|
||||
@@ -0,0 +1,220 @@
|
||||
"""
|
||||
Logging utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import logging
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
|
||||
def setup_logger(
|
||||
name: str,
|
||||
log_file: Optional[str] = None,
|
||||
level: int = logging.INFO,
|
||||
format_string: Optional[str] = None,
|
||||
file_level: Optional[int] = None,
|
||||
console_level: Optional[int] = None,
|
||||
) -> logging.Logger:
|
||||
"""
|
||||
Set up a logger with console and file handlers.
|
||||
|
||||
Args:
|
||||
name: The name of the logger
|
||||
log_file: The log file to write to (optional)
|
||||
level: The default logging level
|
||||
format_string: The format string to use for log messages
|
||||
file_level: The logging level for the file handler (defaults to level)
|
||||
console_level: The logging level for the console handler (defaults to level)
|
||||
|
||||
Returns:
|
||||
The configured logger
|
||||
"""
|
||||
if format_string is None:
|
||||
format_string = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
|
||||
if file_level is None:
|
||||
file_level = level
|
||||
|
||||
if console_level is None:
|
||||
console_level = level
|
||||
|
||||
# Create logger
|
||||
logger = logging.getLogger(name)
|
||||
logger.setLevel(level)
|
||||
|
||||
# Remove existing handlers to avoid duplicates
|
||||
for handler in logger.handlers[:]:
|
||||
logger.removeHandler(handler)
|
||||
|
||||
# Create formatter
|
||||
formatter = logging.Formatter(format_string)
|
||||
|
||||
# Create console handler
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setLevel(console_level)
|
||||
console_handler.setFormatter(formatter)
|
||||
logger.addHandler(console_handler)
|
||||
|
||||
# Create file handler if log_file is provided
|
||||
if log_file:
|
||||
# Create directory if it doesn't exist
|
||||
os.makedirs(os.path.dirname(log_file), exist_ok=True)
|
||||
|
||||
file_handler = logging.FileHandler(log_file)
|
||||
file_handler.setLevel(file_level)
|
||||
file_handler.setFormatter(formatter)
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
return logger
|
||||
|
||||
|
||||
def get_log_level_from_string(level_str: str) -> int:
|
||||
"""
|
||||
Convert a string log level to a logging level constant.
|
||||
|
||||
Args:
|
||||
level_str: The string log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
||||
|
||||
Returns:
|
||||
The corresponding logging level constant
|
||||
|
||||
Raises:
|
||||
ValueError: If the string log level is invalid
|
||||
"""
|
||||
level_map = {
|
||||
"DEBUG": logging.DEBUG,
|
||||
"INFO": logging.INFO,
|
||||
"WARNING": logging.WARNING,
|
||||
"ERROR": logging.ERROR,
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
}
|
||||
|
||||
level_str = level_str.upper()
|
||||
if level_str not in level_map:
|
||||
valid_levels = ", ".join(level_map.keys())
|
||||
raise ValueError(f"Invalid log level: {level_str}. Valid levels are: {valid_levels}")
|
||||
|
||||
return level_map[level_str]
|
||||
|
||||
|
||||
def configure_logger_from_config(
|
||||
name: str,
|
||||
config: Dict[str, Any],
|
||||
default_level: int = logging.INFO,
|
||||
default_format: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
||||
) -> logging.Logger:
|
||||
"""
|
||||
Configure a logger from a configuration dictionary.
|
||||
|
||||
Args:
|
||||
name: The name of the logger
|
||||
config: The configuration dictionary
|
||||
default_level: The default logging level
|
||||
default_format: The default format string
|
||||
|
||||
Returns:
|
||||
The configured logger
|
||||
"""
|
||||
log_config = config.get("logging", {})
|
||||
|
||||
# Get log level
|
||||
level_str = log_config.get("level", "INFO")
|
||||
try:
|
||||
level = get_log_level_from_string(level_str)
|
||||
except ValueError:
|
||||
level = default_level
|
||||
|
||||
# Get log format
|
||||
format_string = log_config.get("format", default_format)
|
||||
|
||||
# Get log file
|
||||
log_file = log_config.get("file")
|
||||
|
||||
# Get file and console levels
|
||||
file_level_str = log_config.get("file_level")
|
||||
console_level_str = log_config.get("console_level")
|
||||
|
||||
file_level = None
|
||||
if file_level_str:
|
||||
try:
|
||||
file_level = get_log_level_from_string(file_level_str)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
console_level = None
|
||||
if console_level_str:
|
||||
try:
|
||||
console_level = get_log_level_from_string(console_level_str)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return setup_logger(
|
||||
name=name,
|
||||
log_file=log_file,
|
||||
level=level,
|
||||
format_string=format_string,
|
||||
file_level=file_level,
|
||||
console_level=console_level,
|
||||
)
|
||||
|
||||
|
||||
def log_section(logger: logging.Logger, section_name: str, level: int = logging.INFO) -> None:
|
||||
"""
|
||||
Log a section header.
|
||||
|
||||
Args:
|
||||
logger: The logger to use
|
||||
section_name: The name of the section
|
||||
level: The logging level
|
||||
"""
|
||||
separator = "=" * 80
|
||||
logger.log(level, separator)
|
||||
logger.log(level, f" {section_name} ".center(80, "="))
|
||||
logger.log(level, separator)
|
||||
|
||||
|
||||
def log_subsection(logger: logging.Logger, subsection_name: str, level: int = logging.INFO) -> None:
|
||||
"""
|
||||
Log a subsection header.
|
||||
|
||||
Args:
|
||||
logger: The logger to use
|
||||
subsection_name: The name of the subsection
|
||||
level: The logging level
|
||||
"""
|
||||
separator = "-" * 60
|
||||
logger.log(level, separator)
|
||||
logger.log(level, f" {subsection_name} ".center(60, "-"))
|
||||
logger.log(level, separator)
|
||||
|
||||
|
||||
def log_dict(logger: logging.Logger, data: Dict[str, Any], title: Optional[str] = None, level: int = logging.INFO) -> None:
|
||||
"""
|
||||
Log a dictionary.
|
||||
|
||||
Args:
|
||||
logger: The logger to use
|
||||
data: The dictionary to log
|
||||
title: The title to use (optional)
|
||||
level: The logging level
|
||||
"""
|
||||
import json
|
||||
|
||||
if title:
|
||||
logger.log(level, f"{title}:")
|
||||
|
||||
formatted_json = json.dumps(data, indent=2)
|
||||
for line in formatted_json.splitlines():
|
||||
logger.log(level, line)
|
||||
|
||||
|
||||
def log_exception(logger: logging.Logger, exception: Exception, message: str = "An error occurred") -> None:
|
||||
"""
|
||||
Log an exception.
|
||||
|
||||
Args:
|
||||
logger: The logger to use
|
||||
exception: The exception to log
|
||||
message: The message to log
|
||||
"""
|
||||
logger.error(f"{message}: {str(exception)}", exc_info=True)
|
||||
@@ -0,0 +1,311 @@
|
||||
"""
|
||||
Path utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import glob
|
||||
import shutil
|
||||
from typing import List, Optional, Dict, Any, Union
|
||||
import logging
|
||||
|
||||
|
||||
def normalize_path(path: str) -> str:
|
||||
"""
|
||||
Normalize a path to use the correct path separator for the current OS.
|
||||
|
||||
Args:
|
||||
path: The path to normalize
|
||||
|
||||
Returns:
|
||||
The normalized path
|
||||
"""
|
||||
return os.path.normpath(path)
|
||||
|
||||
|
||||
def join_paths(*paths: str) -> str:
|
||||
"""
|
||||
Join paths using the correct path separator for the current OS.
|
||||
|
||||
Args:
|
||||
*paths: The paths to join
|
||||
|
||||
Returns:
|
||||
The joined path
|
||||
"""
|
||||
return os.path.join(*paths)
|
||||
|
||||
|
||||
def get_absolute_path(path: str) -> str:
|
||||
"""
|
||||
Get the absolute path of a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the absolute path of
|
||||
|
||||
Returns:
|
||||
The absolute path
|
||||
"""
|
||||
return os.path.abspath(path)
|
||||
|
||||
|
||||
def get_relative_path(path: str, start: Optional[str] = None) -> str:
|
||||
"""
|
||||
Get the relative path of a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the relative path of
|
||||
start: The start path (defaults to the current working directory)
|
||||
|
||||
Returns:
|
||||
The relative path
|
||||
"""
|
||||
if start is None:
|
||||
start = os.getcwd()
|
||||
|
||||
return os.path.relpath(path, start)
|
||||
|
||||
|
||||
def get_parent_directory(path: str) -> str:
|
||||
"""
|
||||
Get the parent directory of a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the parent directory of
|
||||
|
||||
Returns:
|
||||
The parent directory
|
||||
"""
|
||||
return os.path.dirname(path)
|
||||
|
||||
|
||||
def get_filename(path: str) -> str:
|
||||
"""
|
||||
Get the filename from a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the filename from
|
||||
|
||||
Returns:
|
||||
The filename
|
||||
"""
|
||||
return os.path.basename(path)
|
||||
|
||||
|
||||
def get_filename_without_extension(path: str) -> str:
|
||||
"""
|
||||
Get the filename without extension from a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the filename without extension from
|
||||
|
||||
Returns:
|
||||
The filename without extension
|
||||
"""
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
||||
|
||||
def get_file_extension(path: str) -> str:
|
||||
"""
|
||||
Get the file extension from a path.
|
||||
|
||||
Args:
|
||||
path: The path to get the file extension from
|
||||
|
||||
Returns:
|
||||
The file extension (including the dot)
|
||||
"""
|
||||
return os.path.splitext(path)[1]
|
||||
|
||||
|
||||
def create_directory(directory: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Create a directory if it doesn't exist.
|
||||
|
||||
Args:
|
||||
directory: The directory to create
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the directory was created or already exists, False otherwise
|
||||
"""
|
||||
try:
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
if logger:
|
||||
logger.info(f"Created directory: {directory}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to create directory {directory}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def delete_directory(directory: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Delete a directory if it exists.
|
||||
|
||||
Args:
|
||||
directory: The directory to delete
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the directory was deleted or doesn't exist, False otherwise
|
||||
"""
|
||||
if not os.path.exists(directory):
|
||||
return True
|
||||
|
||||
try:
|
||||
shutil.rmtree(directory)
|
||||
if logger:
|
||||
logger.info(f"Deleted directory: {directory}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to delete directory {directory}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def list_files(directory: str, pattern: str = "*") -> List[str]:
|
||||
"""
|
||||
List files in a directory matching a pattern.
|
||||
|
||||
Args:
|
||||
directory: The directory to list files in
|
||||
pattern: The glob pattern to match files against
|
||||
|
||||
Returns:
|
||||
A list of file paths
|
||||
"""
|
||||
return glob.glob(os.path.join(directory, pattern))
|
||||
|
||||
|
||||
def list_directories(directory: str) -> List[str]:
|
||||
"""
|
||||
List subdirectories in a directory.
|
||||
|
||||
Args:
|
||||
directory: The directory to list subdirectories in
|
||||
|
||||
Returns:
|
||||
A list of directory paths
|
||||
"""
|
||||
return [
|
||||
os.path.join(directory, d) for d in os.listdir(directory)
|
||||
if os.path.isdir(os.path.join(directory, d))
|
||||
]
|
||||
|
||||
|
||||
def get_file_info(file_path: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Get information about a file.
|
||||
|
||||
Args:
|
||||
file_path: The path to the file
|
||||
|
||||
Returns:
|
||||
A dictionary with file information
|
||||
"""
|
||||
if not os.path.isfile(file_path):
|
||||
return {}
|
||||
|
||||
stat = os.stat(file_path)
|
||||
|
||||
return {
|
||||
"path": file_path,
|
||||
"size": stat.st_size,
|
||||
"created": stat.st_ctime,
|
||||
"modified": stat.st_mtime,
|
||||
"accessed": stat.st_atime,
|
||||
"filename": os.path.basename(file_path),
|
||||
"extension": os.path.splitext(file_path)[1],
|
||||
"directory": os.path.dirname(file_path),
|
||||
}
|
||||
|
||||
|
||||
def find_files_by_extension(directory: str, extension: str, recursive: bool = True) -> List[str]:
|
||||
"""
|
||||
Find files with a specific extension in a directory.
|
||||
|
||||
Args:
|
||||
directory: The directory to search in
|
||||
extension: The file extension to search for (with or without the dot)
|
||||
recursive: Whether to search recursively
|
||||
|
||||
Returns:
|
||||
A list of file paths
|
||||
"""
|
||||
if not extension.startswith("."):
|
||||
extension = f".{extension}"
|
||||
|
||||
if recursive:
|
||||
pattern = os.path.join(directory, f"**/*{extension}")
|
||||
return glob.glob(pattern, recursive=True)
|
||||
else:
|
||||
pattern = os.path.join(directory, f"*{extension}")
|
||||
return glob.glob(pattern)
|
||||
|
||||
|
||||
def copy_directory(source: str, destination: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Copy a directory.
|
||||
|
||||
Args:
|
||||
source: The source directory
|
||||
destination: The destination directory
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the directory was copied successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
shutil.copytree(source, destination)
|
||||
if logger:
|
||||
logger.info(f"Copied directory from {source} to {destination}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to copy directory from {source} to {destination}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def move_directory(source: str, destination: str, logger: Optional[logging.Logger] = None) -> bool:
|
||||
"""
|
||||
Move a directory.
|
||||
|
||||
Args:
|
||||
source: The source directory
|
||||
destination: The destination directory
|
||||
logger: The logger to use
|
||||
|
||||
Returns:
|
||||
True if the directory was moved successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
shutil.move(source, destination)
|
||||
if logger:
|
||||
logger.info(f"Moved directory from {source} to {destination}")
|
||||
return True
|
||||
except Exception as e:
|
||||
if logger:
|
||||
logger.error(f"Failed to move directory from {source} to {destination}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
def get_directory_size(directory: str) -> int:
|
||||
"""
|
||||
Get the total size of a directory in bytes.
|
||||
|
||||
Args:
|
||||
directory: The directory to get the size of
|
||||
|
||||
Returns:
|
||||
The total size in bytes
|
||||
"""
|
||||
total_size = 0
|
||||
|
||||
for dirpath, dirnames, filenames in os.walk(directory):
|
||||
for filename in filenames:
|
||||
file_path = os.path.join(dirpath, filename)
|
||||
if os.path.isfile(file_path):
|
||||
total_size += os.path.getsize(file_path)
|
||||
|
||||
return total_size
|
||||
@@ -0,0 +1,187 @@
|
||||
"""
|
||||
String utility functions.
|
||||
"""
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
|
||||
def slugify(value: str, allow_unicode: bool = False) -> str:
|
||||
"""
|
||||
Convert a string to a URL-friendly slug.
|
||||
|
||||
Args:
|
||||
value: The string to convert
|
||||
allow_unicode: Whether to allow Unicode characters
|
||||
|
||||
Returns:
|
||||
The slugified string
|
||||
"""
|
||||
if allow_unicode:
|
||||
value = unicodedata.normalize("NFKC", value)
|
||||
else:
|
||||
value = (
|
||||
unicodedata.normalize("NFKD", value)
|
||||
.encode("ascii", "ignore")
|
||||
.decode("ascii")
|
||||
)
|
||||
value = re.sub(r"[^\w\s-]", "", value.lower())
|
||||
value = re.sub(r"[-\s]+", "-", value).strip("-_")
|
||||
return value
|
||||
|
||||
|
||||
def truncate_string(value: str, max_length: int, suffix: str = "...") -> str:
|
||||
"""
|
||||
Truncate a string to a maximum length.
|
||||
|
||||
Args:
|
||||
value: The string to truncate
|
||||
max_length: The maximum length
|
||||
suffix: The suffix to append if truncated
|
||||
|
||||
Returns:
|
||||
The truncated string
|
||||
"""
|
||||
if len(value) <= max_length:
|
||||
return value
|
||||
|
||||
return value[:max_length - len(suffix)] + suffix
|
||||
|
||||
|
||||
def extract_artist_and_title(filename: str) -> Dict[str, str]:
|
||||
"""
|
||||
Extract artist and title from a filename.
|
||||
|
||||
Args:
|
||||
filename: The filename to extract from
|
||||
|
||||
Returns:
|
||||
A dictionary with "artist" and "title" keys
|
||||
"""
|
||||
# Remove file extension
|
||||
name_without_ext = re.sub(r"\.[^.]+$", "", filename)
|
||||
|
||||
# Try to split by " - " first
|
||||
parts = name_without_ext.split(" - ", 1)
|
||||
if len(parts) == 2:
|
||||
return {"artist": parts[0].strip(), "title": parts[1].strip()}
|
||||
|
||||
# Try to split by "-" if " - " didn't work
|
||||
parts = name_without_ext.split("-", 1)
|
||||
if len(parts) == 2:
|
||||
return {"artist": parts[0].strip(), "title": parts[1].strip()}
|
||||
|
||||
# If no separator found, use the whole name as the title
|
||||
return {"artist": "", "title": name_without_ext.strip()}
|
||||
|
||||
|
||||
def format_duration(seconds: int) -> str:
|
||||
"""
|
||||
Format a duration in seconds to a human-readable string.
|
||||
|
||||
Args:
|
||||
seconds: The duration in seconds
|
||||
|
||||
Returns:
|
||||
The formatted duration string (MM:SS)
|
||||
"""
|
||||
minutes, seconds = divmod(seconds, 60)
|
||||
return f"{minutes:02d}:{seconds:02d}"
|
||||
|
||||
|
||||
def format_filesize(size_bytes: int) -> str:
|
||||
"""
|
||||
Format a file size in bytes to a human-readable string.
|
||||
|
||||
Args:
|
||||
size_bytes: The file size in bytes
|
||||
|
||||
Returns:
|
||||
The formatted file size string
|
||||
"""
|
||||
if size_bytes < 1024:
|
||||
return f"{size_bytes} B"
|
||||
|
||||
size_kb = size_bytes / 1024
|
||||
if size_kb < 1024:
|
||||
return f"{size_kb:.1f} KB"
|
||||
|
||||
size_mb = size_kb / 1024
|
||||
if size_mb < 1024:
|
||||
return f"{size_mb:.1f} MB"
|
||||
|
||||
size_gb = size_mb / 1024
|
||||
return f"{size_gb:.1f} GB"
|
||||
|
||||
|
||||
def strip_html_tags(html: str) -> str:
|
||||
"""
|
||||
Strip HTML tags from a string.
|
||||
|
||||
Args:
|
||||
html: The HTML string
|
||||
|
||||
Returns:
|
||||
The string with HTML tags removed
|
||||
"""
|
||||
return re.sub(r"<[^>]+>", "", html)
|
||||
|
||||
|
||||
def normalize_whitespace(text: str) -> str:
|
||||
"""
|
||||
Normalize whitespace in a string.
|
||||
|
||||
Args:
|
||||
text: The string to normalize
|
||||
|
||||
Returns:
|
||||
The string with normalized whitespace
|
||||
"""
|
||||
# Replace multiple whitespace characters with a single space
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
|
||||
def extract_urls(text: str) -> List[str]:
|
||||
"""
|
||||
Extract URLs from a string.
|
||||
|
||||
Args:
|
||||
text: The string to extract URLs from
|
||||
|
||||
Returns:
|
||||
A list of URLs
|
||||
"""
|
||||
url_pattern = r"https?://[^\s]+"
|
||||
return re.findall(url_pattern, text)
|
||||
|
||||
|
||||
def replace_placeholders(template: str, data: Dict[str, Any]) -> str:
|
||||
"""
|
||||
Replace placeholders in a template string with values from a dictionary.
|
||||
|
||||
Args:
|
||||
template: The template string with {placeholder} syntax
|
||||
data: The dictionary with placeholder values
|
||||
|
||||
Returns:
|
||||
The template with placeholders replaced
|
||||
"""
|
||||
return template.format(**data)
|
||||
|
||||
|
||||
def generate_random_string(length: int = 8) -> str:
|
||||
"""
|
||||
Generate a random string of a specified length.
|
||||
|
||||
Args:
|
||||
length: The length of the random string
|
||||
|
||||
Returns:
|
||||
The random string
|
||||
"""
|
||||
import random
|
||||
import string
|
||||
|
||||
characters = string.ascii_letters + string.digits
|
||||
return "".join(random.choice(characters) for _ in range(length))
|
||||
@@ -0,0 +1,230 @@
|
||||
"""
|
||||
Validation utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import logging
|
||||
from typing import Optional, Dict, Any, List, Callable
|
||||
|
||||
|
||||
def is_url(string: str) -> bool:
|
||||
"""
|
||||
Check if a string is a URL.
|
||||
|
||||
Args:
|
||||
string: The string to check
|
||||
|
||||
Returns:
|
||||
True if the string is a URL, False otherwise
|
||||
"""
|
||||
return string.startswith("http://") or string.startswith("https://")
|
||||
|
||||
|
||||
def is_file(string: str) -> bool:
|
||||
"""
|
||||
Check if a string is a valid file.
|
||||
|
||||
Args:
|
||||
string: The string to check
|
||||
|
||||
Returns:
|
||||
True if the string is a valid file, False otherwise
|
||||
"""
|
||||
return os.path.isfile(string)
|
||||
|
||||
|
||||
def is_directory(string: str) -> bool:
|
||||
"""
|
||||
Check if a string is a valid directory.
|
||||
|
||||
Args:
|
||||
string: The string to check
|
||||
|
||||
Returns:
|
||||
True if the string is a valid directory, False otherwise
|
||||
"""
|
||||
return os.path.isdir(string)
|
||||
|
||||
|
||||
def prompt_user_confirmation_or_raise_exception(
|
||||
prompt_message: str,
|
||||
exit_message: str,
|
||||
allow_empty: bool = False,
|
||||
non_interactive: bool = False,
|
||||
logger: Optional[logging.Logger] = None
|
||||
) -> None:
|
||||
"""
|
||||
Prompt the user for confirmation or raise an exception.
|
||||
|
||||
Args:
|
||||
prompt_message: The message to display to the user
|
||||
exit_message: The message to display if the user does not confirm
|
||||
allow_empty: Whether to allow an empty response
|
||||
non_interactive: Whether to automatically confirm in non-interactive mode
|
||||
logger: The logger to use
|
||||
|
||||
Raises:
|
||||
Exception: If the user does not confirm
|
||||
"""
|
||||
if non_interactive:
|
||||
if logger:
|
||||
logger.info(f"Non-interactive mode, automatically confirming: {prompt_message}")
|
||||
return
|
||||
|
||||
if not prompt_user_bool(prompt_message, allow_empty=allow_empty):
|
||||
if logger:
|
||||
logger.error(exit_message)
|
||||
raise Exception(exit_message)
|
||||
|
||||
|
||||
def prompt_user_bool(prompt_message: str, allow_empty: bool = False) -> bool:
|
||||
"""
|
||||
Prompt the user for a boolean value.
|
||||
|
||||
Args:
|
||||
prompt_message: The message to display to the user
|
||||
allow_empty: Whether to allow an empty response
|
||||
|
||||
Returns:
|
||||
True if the user confirms, False otherwise
|
||||
"""
|
||||
options_string = "[y]/n" if allow_empty else "y/[n]"
|
||||
accept_responses = ["y", "yes"]
|
||||
if allow_empty:
|
||||
accept_responses.append("")
|
||||
|
||||
print()
|
||||
response = input(f"{prompt_message} {options_string} ").strip().lower()
|
||||
return response in accept_responses
|
||||
|
||||
|
||||
def validate_input_parameters_for_features(
|
||||
config: Dict[str, Any],
|
||||
logger: Optional[logging.Logger] = None,
|
||||
prompt_confirmation: Optional[Callable] = None
|
||||
) -> Dict[str, bool]:
|
||||
"""
|
||||
Validate input parameters for enabled features.
|
||||
|
||||
Args:
|
||||
config: The configuration dictionary
|
||||
logger: The logger to use
|
||||
prompt_confirmation: A function to prompt the user for confirmation
|
||||
|
||||
Returns:
|
||||
A dictionary of enabled features
|
||||
|
||||
Raises:
|
||||
Exception: If validation fails
|
||||
"""
|
||||
if logger:
|
||||
logger.info(f"Validating input parameters for enabled features...")
|
||||
|
||||
current_directory = os.getcwd()
|
||||
if logger:
|
||||
logger.info(f"Current directory to process: {current_directory}")
|
||||
|
||||
enabled_features = {
|
||||
"youtube_upload": False,
|
||||
"discord_notification": False,
|
||||
"folder_organisation": False,
|
||||
"public_share_copy": False,
|
||||
"public_share_rclone": False,
|
||||
"cdg_zip_creation": config.get("enable_cdg", False),
|
||||
"txt_zip_creation": config.get("enable_txt", False)
|
||||
}
|
||||
|
||||
# Enable youtube upload if client secrets file is provided and is valid JSON
|
||||
youtube_client_secrets_file = config.get("youtube_client_secrets_file")
|
||||
youtube_description_file = config.get("youtube_description_file")
|
||||
|
||||
if youtube_client_secrets_file is not None and youtube_description_file is not None:
|
||||
if not os.path.isfile(youtube_client_secrets_file):
|
||||
raise Exception(f"YouTube client secrets file does not exist: {youtube_client_secrets_file}")
|
||||
|
||||
if not os.path.isfile(youtube_description_file):
|
||||
raise Exception(f"YouTube description file does not exist: {youtube_description_file}")
|
||||
|
||||
# Test parsing the file as JSON to check it's valid
|
||||
try:
|
||||
import json
|
||||
with open(youtube_client_secrets_file, "r") as f:
|
||||
json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
raise Exception(f"YouTube client secrets file is not valid JSON: {youtube_client_secrets_file}") from e
|
||||
|
||||
if logger:
|
||||
logger.debug(f"YouTube upload checks passed, enabling YouTube upload")
|
||||
enabled_features["youtube_upload"] = True
|
||||
|
||||
# Enable discord notifications if webhook URL is provided and is valid URL
|
||||
discord_webhook_url = config.get("discord_webhook_url")
|
||||
if discord_webhook_url is not None:
|
||||
if not discord_webhook_url.startswith("https://discord.com/api/webhooks/"):
|
||||
raise Exception(f"Discord webhook URL is not valid: {discord_webhook_url}")
|
||||
|
||||
if logger:
|
||||
logger.debug(f"Discord webhook URL checks passed, enabling Discord notifications")
|
||||
enabled_features["discord_notification"] = True
|
||||
|
||||
# Enable folder organisation if brand prefix and target directory are provided and target directory is valid
|
||||
brand_prefix = config.get("brand_prefix")
|
||||
organised_dir = config.get("organised_dir")
|
||||
|
||||
if brand_prefix is not None and organised_dir is not None:
|
||||
if not os.path.isdir(organised_dir):
|
||||
raise Exception(f"Target directory does not exist: {organised_dir}")
|
||||
|
||||
if logger:
|
||||
logger.debug(f"Brand prefix and target directory provided, enabling folder organisation")
|
||||
enabled_features["folder_organisation"] = True
|
||||
|
||||
# Enable public share copy if public share directory is provided and is valid directory with MP4 and CDG subdirectories
|
||||
public_share_dir = config.get("public_share_dir")
|
||||
if public_share_dir is not None:
|
||||
if not os.path.isdir(public_share_dir):
|
||||
raise Exception(f"Public share directory does not exist: {public_share_dir}")
|
||||
|
||||
mp4_dir = os.path.join(public_share_dir, "MP4")
|
||||
cdg_dir = os.path.join(public_share_dir, "CDG")
|
||||
|
||||
if not os.path.isdir(mp4_dir):
|
||||
os.makedirs(mp4_dir, exist_ok=True)
|
||||
if logger:
|
||||
logger.info(f"Created MP4 subdirectory: {mp4_dir}")
|
||||
|
||||
if not os.path.isdir(cdg_dir):
|
||||
os.makedirs(cdg_dir, exist_ok=True)
|
||||
if logger:
|
||||
logger.info(f"Created CDG subdirectory: {cdg_dir}")
|
||||
|
||||
if logger:
|
||||
logger.debug(f"Public share directory checks passed, enabling public share copy")
|
||||
enabled_features["public_share_copy"] = True
|
||||
|
||||
# Enable public share rclone if rclone destination is provided
|
||||
rclone_destination = config.get("rclone_destination")
|
||||
if rclone_destination is not None:
|
||||
if logger:
|
||||
logger.debug(f"Rclone destination provided, enabling rclone sync")
|
||||
enabled_features["public_share_rclone"] = True
|
||||
|
||||
# Tell user which features are enabled, prompt them to confirm before proceeding
|
||||
if logger:
|
||||
logger.info(f"Enabled features:")
|
||||
logger.info(f" CDG ZIP creation: {enabled_features['cdg_zip_creation']}")
|
||||
logger.info(f" TXT ZIP creation: {enabled_features['txt_zip_creation']}")
|
||||
logger.info(f" YouTube upload: {enabled_features['youtube_upload']}")
|
||||
logger.info(f" Discord notifications: {enabled_features['discord_notification']}")
|
||||
logger.info(f" Folder organisation: {enabled_features['folder_organisation']}")
|
||||
logger.info(f" Public share copy: {enabled_features['public_share_copy']}")
|
||||
logger.info(f" Public share rclone: {enabled_features['public_share_rclone']}")
|
||||
|
||||
if prompt_confirmation:
|
||||
prompt_confirmation(
|
||||
f"Confirm features enabled log messages above match your expectations for finalisation?",
|
||||
"Refusing to proceed without user confirmation they're happy with enabled features.",
|
||||
allow_empty=True,
|
||||
)
|
||||
|
||||
return enabled_features
|
||||
@@ -1 +0,0 @@
|
||||
from .karaoke_prep import KaraokePrep
|
||||
@@ -1 +0,0 @@
|
||||
from .karaoke_finalise import KaraokeFinalise
|
||||
Whitespace-only changes.
@@ -1,810 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import argparse
|
||||
import logging
|
||||
import pkg_resources
|
||||
import tempfile
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import asyncio
|
||||
import time
|
||||
import pyperclip
|
||||
from karaoke_prep import KaraokePrep
|
||||
from karaoke_prep.karaoke_finalise import KaraokeFinalise
|
||||
|
||||
|
||||
def is_url(string):
|
||||
"""Simple check to determine if a string is a URL."""
|
||||
return string.startswith("http://") or string.startswith("https://")
|
||||
|
||||
|
||||
def is_file(string):
|
||||
"""Check if a string is a valid file."""
|
||||
return os.path.isfile(string)
|
||||
|
||||
|
||||
async def async_main():
|
||||
logger = logging.getLogger(__name__)
|
||||
log_handler = logging.StreamHandler()
|
||||
log_formatter = logging.Formatter(fmt="%(asctime)s.%(msecs)03d - %(levelname)s - %(module)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
|
||||
log_handler.setFormatter(log_formatter)
|
||||
logger.addHandler(log_handler)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video.",
|
||||
formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=54),
|
||||
)
|
||||
|
||||
# Basic information
|
||||
parser.add_argument(
|
||||
"args",
|
||||
nargs="*",
|
||||
help="[Media or playlist URL] [Artist] [Title] of song to process. If URL is provided, Artist and Title are optional but increase chance of fetching the correct lyrics. If Artist and Title are provided with no URL, the top YouTube search result will be fetched.",
|
||||
)
|
||||
|
||||
package_version = pkg_resources.get_distribution("karaoke-gen").version
|
||||
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {package_version}")
|
||||
|
||||
# Workflow control
|
||||
workflow_group = parser.add_argument_group("Workflow Control")
|
||||
workflow_group.add_argument(
|
||||
"--prep-only",
|
||||
action="store_true",
|
||||
help="Only run the preparation phase (download audio, lyrics, separate stems, create title screens). Example: --prep-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--finalise-only",
|
||||
action="store_true",
|
||||
help="Only run the finalisation phase (remux, encode, organize). Must be run in a directory prepared by the prep phase. Example: --finalise-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-transcription",
|
||||
action="store_true",
|
||||
help="Skip automatic lyrics transcription/synchronization. Use this to fall back to manual syncing. Example: --skip-transcription",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-separation",
|
||||
action="store_true",
|
||||
help="Skip audio separation process. Example: --skip-separation",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--skip-lyrics",
|
||||
action="store_true",
|
||||
help="Skip fetching and processing lyrics. Example: --skip-lyrics",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--lyrics-only",
|
||||
action="store_true",
|
||||
help="Only process lyrics, skipping audio separation and title/end screen generation. Example: --lyrics-only",
|
||||
)
|
||||
workflow_group.add_argument(
|
||||
"--edit-lyrics",
|
||||
action="store_true",
|
||||
help="Edit lyrics of an existing track. This will backup existing outputs, re-run the lyrics transcription process, and update all outputs. Example: --edit-lyrics",
|
||||
)
|
||||
|
||||
# Logging & Debugging
|
||||
debug_group = parser.add_argument_group("Logging & Debugging")
|
||||
debug_group.add_argument(
|
||||
"--log_level",
|
||||
default="info",
|
||||
help="Optional: logging level, e.g. info, debug, warning (default: %(default)s). Example: --log_level=debug",
|
||||
)
|
||||
debug_group.add_argument(
|
||||
"--dry_run",
|
||||
action="store_true",
|
||||
help="Optional: perform a dry run without making any changes. Example: --dry_run",
|
||||
)
|
||||
debug_group.add_argument(
|
||||
"--render_bounding_boxes",
|
||||
action="store_true",
|
||||
help="Optional: render bounding boxes around text regions for debugging. Example: --render_bounding_boxes",
|
||||
)
|
||||
|
||||
# Input/Output Configuration
|
||||
io_group = parser.add_argument_group("Input/Output Configuration")
|
||||
io_group.add_argument(
|
||||
"--filename_pattern",
|
||||
help="Required if processing a folder: Python regex pattern to extract track names from filenames. Must contain a named group 'title'. Example: --filename_pattern='(?P<index>\\d+) - (?P<title>.+).mp3'",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_dir",
|
||||
default=".",
|
||||
help="Optional: directory to write output files (default: <current dir>). Example: --output_dir=/app/karaoke",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--no_track_subfolders",
|
||||
action="store_false",
|
||||
dest="no_track_subfolders",
|
||||
help="Optional: do NOT create a named subfolder for each track. Example: --no_track_subfolders",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--lossless_output_format",
|
||||
default="FLAC",
|
||||
help="Optional: lossless output format for separated audio (default: FLAC). Example: --lossless_output_format=WAV",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_png",
|
||||
type=lambda x: (str(x).lower() == "true"),
|
||||
default=True,
|
||||
help="Optional: output PNG format for title and end images (default: %(default)s). Example: --output_png=False",
|
||||
)
|
||||
io_group.add_argument(
|
||||
"--output_jpg",
|
||||
type=lambda x: (str(x).lower() == "true"),
|
||||
default=True,
|
||||
help="Optional: output JPG format for title and end images (default: %(default)s). Example: --output_jpg=False",
|
||||
)
|
||||
|
||||
# Audio Processing Configuration
|
||||
audio_group = parser.add_argument_group("Audio Processing Configuration")
|
||||
audio_group.add_argument(
|
||||
"--clean_instrumental_model",
|
||||
default="model_bs_roformer_ep_317_sdr_12.9755.ckpt",
|
||||
help="Optional: Model for clean instrumental separation (default: %(default)s).",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--backing_vocals_models",
|
||||
nargs="+",
|
||||
default=["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"],
|
||||
help="Optional: List of models for backing vocals separation (default: %(default)s).",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--other_stems_models",
|
||||
nargs="+",
|
||||
default=["htdemucs_6s.yaml"],
|
||||
help="Optional: List of models for other stems separation (default: %(default)s).",
|
||||
)
|
||||
|
||||
default_model_dir_unix = "/tmp/audio-separator-models/"
|
||||
if os.name == "posix" and os.path.exists(default_model_dir_unix):
|
||||
default_model_dir = default_model_dir_unix
|
||||
else:
|
||||
# Use tempfile to get the platform-independent temp directory
|
||||
default_model_dir = os.path.join(tempfile.gettempdir(), "audio-separator-models")
|
||||
|
||||
audio_group.add_argument(
|
||||
"--model_file_dir",
|
||||
default=default_model_dir,
|
||||
help="Optional: model files directory (default: %(default)s). Example: --model_file_dir=/app/models",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--existing_instrumental",
|
||||
help="Optional: Path to an existing instrumental audio file. If provided, audio separation will be skipped.",
|
||||
)
|
||||
audio_group.add_argument(
|
||||
"--instrumental_format",
|
||||
default="flac",
|
||||
help="Optional: format / file extension for instrumental track to use for remux (default: %(default)s). Example: --instrumental_format=mp3",
|
||||
)
|
||||
|
||||
# Lyrics Configuration
|
||||
lyrics_group = parser.add_argument_group("Lyrics Configuration")
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_artist",
|
||||
help="Optional: Override the artist name used for lyrics search. Example: --lyrics_artist='The Beatles'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_title",
|
||||
help="Optional: Override the song title used for lyrics search. Example: --lyrics_title='Hey Jude'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--lyrics_file",
|
||||
help="Optional: Path to a file containing lyrics to use instead of fetching from online. Example: --lyrics_file='/path/to/lyrics.txt'",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--subtitle_offset_ms",
|
||||
type=int,
|
||||
default=0,
|
||||
help="Optional: Adjust subtitle timing by N milliseconds (+ve delays, -ve advances). Example: --subtitle_offset_ms=500",
|
||||
)
|
||||
lyrics_group.add_argument(
|
||||
"--skip_transcription_review",
|
||||
action="store_true",
|
||||
help="Optional: Skip the review step after transcription. Example: --skip_transcription_review",
|
||||
)
|
||||
|
||||
# Style Configuration
|
||||
style_group = parser.add_argument_group("Style Configuration")
|
||||
style_group.add_argument(
|
||||
"--style_params_json",
|
||||
help="Optional: Path to JSON file containing style configuration. Example: --style_params_json='/path/to/style_params.json'",
|
||||
)
|
||||
|
||||
# Finalisation Configuration
|
||||
finalise_group = parser.add_argument_group("Finalisation Configuration")
|
||||
finalise_group.add_argument(
|
||||
"--enable_cdg",
|
||||
action="store_true",
|
||||
help="Optional: Enable CDG ZIP generation during finalisation. Example: --enable_cdg",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--enable_txt",
|
||||
action="store_true",
|
||||
help="Optional: Enable TXT ZIP generation during finalisation. Example: --enable_txt",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--brand_prefix",
|
||||
help="Optional: Your brand prefix to calculate the next sequential number. Example: --brand_prefix=BRAND",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--organised_dir",
|
||||
help="Optional: Target directory where the processed folder will be moved. Example: --organised_dir='/path/to/Tracks-Organized'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--organised_dir_rclone_root",
|
||||
help="Optional: Rclone path which maps to your organised_dir. Example: --organised_dir_rclone_root='dropbox:Media/Karaoke/Tracks-Organized'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--public_share_dir",
|
||||
help="Optional: Public share directory for final files. Example: --public_share_dir='/path/to/Tracks-PublicShare'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--youtube_client_secrets_file",
|
||||
help="Optional: Path to youtube client secrets file. Example: --youtube_client_secrets_file='/path/to/client_secret.json'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--youtube_description_file",
|
||||
help="Optional: Path to youtube description template. Example: --youtube_description_file='/path/to/description.txt'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--rclone_destination",
|
||||
help="Optional: Rclone destination for public_share_dir sync. Example: --rclone_destination='googledrive:KaraokeFolder'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--discord_webhook_url",
|
||||
help="Optional: Discord webhook URL for notifications. Example: --discord_webhook_url='https://discord.com/api/webhooks/...'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--email_template_file",
|
||||
help="Optional: Path to email template file. Example: --email_template_file='/path/to/template.txt'",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--keep-brand-code",
|
||||
action="store_true",
|
||||
help="Optional: Use existing brand code from current directory instead of generating new one. Example: --keep-brand-code",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"-y",
|
||||
"--yes",
|
||||
action="store_true",
|
||||
help="Optional: Run in non-interactive mode, assuming yes to all prompts. Example: -y",
|
||||
)
|
||||
finalise_group.add_argument(
|
||||
"--test_email_template",
|
||||
action="store_true",
|
||||
help="Optional: Test the email template functionality with fake data. Example: --test_email_template",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Handle test email template case first
|
||||
if args.test_email_template:
|
||||
log_level = getattr(logging, args.log_level.upper())
|
||||
logger.setLevel(log_level)
|
||||
logger.info("Testing email template functionality...")
|
||||
kfinalise = KaraokeFinalise(
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
email_template_file=args.email_template_file,
|
||||
)
|
||||
kfinalise.test_email_template()
|
||||
return
|
||||
|
||||
# Handle edit-lyrics mode
|
||||
if args.edit_lyrics:
|
||||
log_level = getattr(logging, args.log_level.upper())
|
||||
logger.setLevel(log_level)
|
||||
logger.info("Running in edit-lyrics mode...")
|
||||
|
||||
# Get the current directory name to extract artist and title
|
||||
current_dir = os.path.basename(os.getcwd())
|
||||
logger.info(f"Current directory: {current_dir}")
|
||||
|
||||
# Extract artist and title from directory name
|
||||
# Format could be either "Artist - Title" or "BRAND-XXXX - Artist - Title"
|
||||
if " - " not in current_dir:
|
||||
logger.error("Current directory name does not contain ' - ' separator. Cannot extract artist and title.")
|
||||
exit(1)
|
||||
|
||||
parts = current_dir.split(" - ")
|
||||
if len(parts) == 2:
|
||||
artist, title = parts
|
||||
elif len(parts) >= 3:
|
||||
# Handle brand code format: "BRAND-XXXX - Artist - Title"
|
||||
artist = parts[1]
|
||||
title = " - ".join(parts[2:])
|
||||
else:
|
||||
logger.error(f"Could not parse artist and title from directory name: {current_dir}")
|
||||
exit(1)
|
||||
|
||||
logger.info(f"Extracted artist: {artist}, title: {title}")
|
||||
|
||||
# Initialize KaraokePrep
|
||||
kprep = KaraokePrep(
|
||||
artist=artist,
|
||||
title=title,
|
||||
input_media=None, # Will be set by backup_existing_outputs
|
||||
dry_run=args.dry_run,
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
render_bounding_boxes=args.render_bounding_boxes,
|
||||
output_dir=".", # We're already in the track directory
|
||||
create_track_subfolders=False, # Don't create subfolders, we're already in one
|
||||
lossless_output_format=args.lossless_output_format,
|
||||
output_png=args.output_png,
|
||||
output_jpg=args.output_jpg,
|
||||
clean_instrumental_model=args.clean_instrumental_model,
|
||||
backing_vocals_models=args.backing_vocals_models,
|
||||
other_stems_models=args.other_stems_models,
|
||||
model_file_dir=args.model_file_dir,
|
||||
skip_separation=True, # Skip separation as we already have the audio files
|
||||
lyrics_artist=args.lyrics_artist or artist,
|
||||
lyrics_title=args.lyrics_title or title,
|
||||
lyrics_file=args.lyrics_file,
|
||||
skip_lyrics=False, # We want to process lyrics
|
||||
skip_transcription=False, # We want to transcribe
|
||||
skip_transcription_review=args.skip_transcription_review,
|
||||
subtitle_offset_ms=args.subtitle_offset_ms,
|
||||
style_params_json=args.style_params_json,
|
||||
)
|
||||
|
||||
# Backup existing outputs and get the input audio file
|
||||
track_output_dir = os.getcwd()
|
||||
input_audio_wav = kprep.backup_existing_outputs(track_output_dir, artist, title)
|
||||
kprep.input_media = input_audio_wav
|
||||
|
||||
# Run KaraokePrep
|
||||
tracks = await kprep.process()
|
||||
|
||||
# Load CDG styles if CDG generation is enabled
|
||||
cdg_styles = None
|
||||
if args.enable_cdg:
|
||||
if not args.style_params_json:
|
||||
logger.error("CDG styles JSON file path (--style_params_json) is required when --enable_cdg is used")
|
||||
exit(1)
|
||||
try:
|
||||
with open(args.style_params_json, "r") as f:
|
||||
style_params = json.loads(f.read())
|
||||
cdg_styles = style_params["cdg"]
|
||||
except FileNotFoundError:
|
||||
logger.error(f"CDG styles configuration file not found: {args.style_params_json}")
|
||||
exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in CDG styles configuration file: {e}")
|
||||
exit(1)
|
||||
|
||||
# Run KaraokeFinalise with keep_brand_code=True and replace_existing=True
|
||||
kfinalise = KaraokeFinalise(
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
dry_run=args.dry_run,
|
||||
instrumental_format=args.instrumental_format,
|
||||
enable_cdg=args.enable_cdg,
|
||||
enable_txt=args.enable_txt,
|
||||
brand_prefix=args.brand_prefix,
|
||||
organised_dir=args.organised_dir,
|
||||
organised_dir_rclone_root=args.organised_dir_rclone_root,
|
||||
public_share_dir=args.public_share_dir,
|
||||
youtube_client_secrets_file=args.youtube_client_secrets_file,
|
||||
youtube_description_file=args.youtube_description_file,
|
||||
rclone_destination=args.rclone_destination,
|
||||
discord_webhook_url=args.discord_webhook_url,
|
||||
email_template_file=args.email_template_file,
|
||||
cdg_styles=cdg_styles,
|
||||
keep_brand_code=True, # Always keep brand code in edit mode
|
||||
non_interactive=args.yes,
|
||||
)
|
||||
|
||||
try:
|
||||
final_track = kfinalise.process(replace_existing=True) # Replace existing YouTube video
|
||||
logger.info(f"Successfully completed editing lyrics for: {artist} - {title}")
|
||||
|
||||
# Display summary of outputs
|
||||
logger.info(f"Karaoke lyrics edit complete! Output files:")
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {final_track['artist']} - {final_track['title']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Working Files:")
|
||||
logger.info(f" Video With Vocals: {final_track['video_with_vocals']}")
|
||||
logger.info(f" Video With Instrumental: {final_track['video_with_instrumental']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Final Videos:")
|
||||
logger.info(f" Lossless 4K MP4 (PCM): {final_track['final_video']}")
|
||||
logger.info(f" Lossless 4K MKV (FLAC): {final_track['final_video_mkv']}")
|
||||
logger.info(f" Lossy 4K MP4 (AAC): {final_track['final_video_lossy']}")
|
||||
logger.info(f" Lossy 720p MP4 (AAC): {final_track['final_video_720p']}")
|
||||
|
||||
if "final_karaoke_cdg_zip" in final_track or "final_karaoke_txt_zip" in final_track:
|
||||
logger.info(f"")
|
||||
logger.info(f"Karaoke Files:")
|
||||
|
||||
if "final_karaoke_cdg_zip" in final_track:
|
||||
logger.info(f" CDG+MP3 ZIP: {final_track['final_karaoke_cdg_zip']}")
|
||||
|
||||
if "final_karaoke_txt_zip" in final_track:
|
||||
logger.info(f" TXT+MP3 ZIP: {final_track['final_karaoke_txt_zip']}")
|
||||
|
||||
if final_track["brand_code"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Organization:")
|
||||
logger.info(f" Brand Code: {final_track['brand_code']}")
|
||||
logger.info(f" Directory: {final_track['new_brand_code_dir_path']}")
|
||||
|
||||
if final_track["youtube_url"] or final_track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Sharing:")
|
||||
|
||||
if final_track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f" Folder Link: {final_track['brand_code_dir_sharing_link']}")
|
||||
try:
|
||||
time.sleep(1) # Brief pause between clipboard operations
|
||||
pyperclip.copy(final_track["brand_code_dir_sharing_link"])
|
||||
logger.info(f" (Folder link copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy folder link to clipboard: {str(e)}")
|
||||
|
||||
if final_track["youtube_url"]:
|
||||
logger.info(f" YouTube URL: {final_track['youtube_url']}")
|
||||
try:
|
||||
pyperclip.copy(final_track["youtube_url"])
|
||||
logger.info(f" (YouTube URL copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy YouTube URL to clipboard: {str(e)}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error during finalisation: {str(e)}")
|
||||
raise e
|
||||
|
||||
return
|
||||
|
||||
# Handle finalise-only mode
|
||||
if args.finalise_only:
|
||||
log_level = getattr(logging, args.log_level.upper())
|
||||
logger.setLevel(log_level)
|
||||
logger.info("Running in finalise-only mode...")
|
||||
|
||||
# Load CDG styles if CDG generation is enabled
|
||||
cdg_styles = None
|
||||
if args.enable_cdg:
|
||||
if not args.style_params_json:
|
||||
logger.error("CDG styles JSON file path (--style_params_json) is required when --enable_cdg is used")
|
||||
exit(1)
|
||||
try:
|
||||
with open(args.style_params_json, "r") as f:
|
||||
style_params = json.loads(f.read())
|
||||
cdg_styles = style_params["cdg"]
|
||||
except FileNotFoundError:
|
||||
logger.error(f"CDG styles configuration file not found: {args.style_params_json}")
|
||||
exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in CDG styles configuration file: {e}")
|
||||
exit(1)
|
||||
|
||||
kfinalise = KaraokeFinalise(
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
dry_run=args.dry_run,
|
||||
instrumental_format=args.instrumental_format,
|
||||
enable_cdg=args.enable_cdg,
|
||||
enable_txt=args.enable_txt,
|
||||
brand_prefix=args.brand_prefix,
|
||||
organised_dir=args.organised_dir,
|
||||
organised_dir_rclone_root=args.organised_dir_rclone_root,
|
||||
public_share_dir=args.public_share_dir,
|
||||
youtube_client_secrets_file=args.youtube_client_secrets_file,
|
||||
youtube_description_file=args.youtube_description_file,
|
||||
rclone_destination=args.rclone_destination,
|
||||
discord_webhook_url=args.discord_webhook_url,
|
||||
email_template_file=args.email_template_file,
|
||||
cdg_styles=cdg_styles,
|
||||
keep_brand_code=args.keep_brand_code,
|
||||
non_interactive=args.yes,
|
||||
)
|
||||
|
||||
try:
|
||||
track = kfinalise.process()
|
||||
logger.info(f"Karaoke finalisation processing complete! Output files:")
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {track['artist']} - {track['title']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Working Files:")
|
||||
logger.info(f" Video With Vocals: {track['video_with_vocals']}")
|
||||
logger.info(f" Video With Instrumental: {track['video_with_instrumental']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Final Videos:")
|
||||
logger.info(f" Lossless 4K MP4 (PCM): {track['final_video']}")
|
||||
logger.info(f" Lossless 4K MKV (FLAC): {track['final_video_mkv']}")
|
||||
logger.info(f" Lossy 4K MP4 (AAC): {track['final_video_lossy']}")
|
||||
logger.info(f" Lossy 720p MP4 (AAC): {track['final_video_720p']}")
|
||||
|
||||
if "final_karaoke_cdg_zip" in track or "final_karaoke_txt_zip" in track:
|
||||
logger.info(f"")
|
||||
logger.info(f"Karaoke Files:")
|
||||
|
||||
if "final_karaoke_cdg_zip" in track:
|
||||
logger.info(f" CDG+MP3 ZIP: {track['final_karaoke_cdg_zip']}")
|
||||
|
||||
if "final_karaoke_txt_zip" in track:
|
||||
logger.info(f" TXT+MP3 ZIP: {track['final_karaoke_txt_zip']}")
|
||||
|
||||
if track["brand_code"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Organization:")
|
||||
logger.info(f" Brand Code: {track['brand_code']}")
|
||||
logger.info(f" New Directory: {track['new_brand_code_dir_path']}")
|
||||
|
||||
if track["youtube_url"] or track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Sharing:")
|
||||
|
||||
if track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f" Folder Link: {track['brand_code_dir_sharing_link']}")
|
||||
try:
|
||||
time.sleep(1) # Brief pause between clipboard operations
|
||||
pyperclip.copy(track["brand_code_dir_sharing_link"])
|
||||
logger.info(f" (Folder link copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy folder link to clipboard: {str(e)}")
|
||||
|
||||
if track["youtube_url"]:
|
||||
logger.info(f" YouTube URL: {track['youtube_url']}")
|
||||
try:
|
||||
pyperclip.copy(track["youtube_url"])
|
||||
logger.info(f" (YouTube URL copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy YouTube URL to clipboard: {str(e)}")
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred during finalisation, see stack trace below: {str(e)}")
|
||||
raise e
|
||||
|
||||
return
|
||||
|
||||
# For prep or full workflow, parse input arguments
|
||||
input_media, artist, title, filename_pattern = None, None, None, None
|
||||
|
||||
if not args.args:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
|
||||
# Allow 3 forms of positional arguments:
|
||||
# 1. URL or Media File only (may be single track URL, playlist URL, or local file)
|
||||
# 2. Artist and Title only
|
||||
# 3. URL, Artist, and Title
|
||||
if args.args and (is_url(args.args[0]) or is_file(args.args[0])):
|
||||
input_media = args.args[0]
|
||||
if len(args.args) > 2:
|
||||
artist = args.args[1]
|
||||
title = args.args[2]
|
||||
elif len(args.args) > 1:
|
||||
artist = args.args[1]
|
||||
else:
|
||||
logger.warn("Input media provided without Artist and Title, both will be guessed from title")
|
||||
|
||||
elif os.path.isdir(args.args[0]):
|
||||
if not args.filename_pattern:
|
||||
logger.error("Filename pattern is required when processing a folder.")
|
||||
exit(1)
|
||||
if len(args.args) <= 1:
|
||||
logger.error("Second parameter provided must be Artist name; Artist is required when processing a folder.")
|
||||
exit(1)
|
||||
|
||||
input_media = args.args[0]
|
||||
artist = args.args[1]
|
||||
filename_pattern = args.filename_pattern
|
||||
|
||||
elif len(args.args) > 1:
|
||||
artist = args.args[0]
|
||||
title = args.args[1]
|
||||
logger.warn(f"No input media provided, the top YouTube search result for {artist} - {title} will be used.")
|
||||
|
||||
else:
|
||||
parser.print_help()
|
||||
exit(1)
|
||||
|
||||
log_level = getattr(logging, args.log_level.upper())
|
||||
logger.setLevel(log_level)
|
||||
|
||||
# Set up environment variables for lyrics-only mode
|
||||
if args.lyrics_only:
|
||||
args.skip_separation = True
|
||||
os.environ["KARAOKE_PREP_SKIP_AUDIO_SEPARATION"] = "1"
|
||||
os.environ["KARAOKE_PREP_SKIP_TITLE_END_SCREENS"] = "1"
|
||||
logger.info("Lyrics-only mode enabled: skipping audio separation and title/end screen generation")
|
||||
|
||||
# Step 1: Run KaraokePrep
|
||||
logger.info(f"KaraokePrep beginning with input_media: {input_media} artist: {artist} and title: {title}")
|
||||
kprep = KaraokePrep(
|
||||
artist=artist,
|
||||
title=title,
|
||||
input_media=input_media,
|
||||
filename_pattern=filename_pattern,
|
||||
dry_run=args.dry_run,
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
render_bounding_boxes=args.render_bounding_boxes,
|
||||
output_dir=args.output_dir,
|
||||
create_track_subfolders=args.no_track_subfolders,
|
||||
lossless_output_format=args.lossless_output_format,
|
||||
output_png=args.output_png,
|
||||
output_jpg=args.output_jpg,
|
||||
clean_instrumental_model=args.clean_instrumental_model,
|
||||
backing_vocals_models=args.backing_vocals_models,
|
||||
other_stems_models=args.other_stems_models,
|
||||
model_file_dir=args.model_file_dir,
|
||||
existing_instrumental=args.existing_instrumental,
|
||||
skip_separation=args.skip_separation,
|
||||
lyrics_artist=args.lyrics_artist,
|
||||
lyrics_title=args.lyrics_title,
|
||||
lyrics_file=args.lyrics_file,
|
||||
skip_lyrics=args.skip_lyrics,
|
||||
skip_transcription=args.skip_transcription,
|
||||
skip_transcription_review=args.skip_transcription_review,
|
||||
subtitle_offset_ms=args.subtitle_offset_ms,
|
||||
style_params_json=args.style_params_json,
|
||||
)
|
||||
|
||||
tracks = await kprep.process()
|
||||
|
||||
# If prep-only mode, display detailed output and exit
|
||||
if args.prep_only:
|
||||
logger.info(f"Karaoke Prep complete! Output files:")
|
||||
|
||||
for track in tracks:
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {track['artist']} - {track['title']}")
|
||||
logger.info(f" Input Media: {track['input_media']}")
|
||||
logger.info(f" Input WAV Audio: {track['input_audio_wav']}")
|
||||
logger.info(f" Input Still Image: {track['input_still_image']}")
|
||||
logger.info(f" Lyrics: {track['lyrics']}")
|
||||
logger.info(f" Processed Lyrics: {track['processed_lyrics']}")
|
||||
|
||||
logger.info(f" Separated Audio:")
|
||||
|
||||
# Clean Instrumental
|
||||
logger.info(f" Clean Instrumental Model:")
|
||||
for stem_type, file_path in track["separated_audio"]["clean_instrumental"].items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Other Stems
|
||||
logger.info(f" Other Stems Models:")
|
||||
for model, stems in track["separated_audio"]["other_stems"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
for stem_type, file_path in stems.items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Backing Vocals
|
||||
logger.info(f" Backing Vocals Models:")
|
||||
for model, stems in track["separated_audio"]["backing_vocals"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
for stem_type, file_path in stems.items():
|
||||
logger.info(f" {stem_type.capitalize()}: {file_path}")
|
||||
|
||||
# Combined Instrumentals
|
||||
logger.info(f" Combined Instrumentals:")
|
||||
for model, file_path in track["separated_audio"]["combined_instrumentals"].items():
|
||||
logger.info(f" Model: {model}")
|
||||
logger.info(f" Combined Instrumental: {file_path}")
|
||||
|
||||
logger.info("Preparation phase complete. Exiting due to --prep-only flag.")
|
||||
return
|
||||
|
||||
# Step 2: For each track, run KaraokeFinalise
|
||||
for track in tracks:
|
||||
logger.info(f"Starting finalisation phase for {track['artist']} - {track['title']}...")
|
||||
|
||||
# Use the track directory that was actually created by KaraokePrep
|
||||
track_dir = track["track_output_dir"]
|
||||
if not os.path.exists(track_dir):
|
||||
logger.error(f"Track directory not found: {track_dir}")
|
||||
continue
|
||||
|
||||
logger.info(f"Changing to directory: {track_dir}")
|
||||
os.chdir(track_dir)
|
||||
|
||||
# Load CDG styles if CDG generation is enabled
|
||||
cdg_styles = None
|
||||
if args.enable_cdg:
|
||||
if not args.style_params_json:
|
||||
logger.error("CDG styles JSON file path (--style_params_json) is required when --enable_cdg is used")
|
||||
exit(1)
|
||||
try:
|
||||
with open(args.style_params_json, "r") as f:
|
||||
style_params = json.loads(f.read())
|
||||
cdg_styles = style_params["cdg"]
|
||||
except FileNotFoundError:
|
||||
logger.error(f"CDG styles configuration file not found: {args.style_params_json}")
|
||||
exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Invalid JSON in CDG styles configuration file: {e}")
|
||||
exit(1)
|
||||
|
||||
# Initialize KaraokeFinalise
|
||||
kfinalise = KaraokeFinalise(
|
||||
log_formatter=log_formatter,
|
||||
log_level=log_level,
|
||||
dry_run=args.dry_run,
|
||||
instrumental_format=args.instrumental_format,
|
||||
enable_cdg=args.enable_cdg,
|
||||
enable_txt=args.enable_txt,
|
||||
brand_prefix=args.brand_prefix,
|
||||
organised_dir=args.organised_dir,
|
||||
organised_dir_rclone_root=args.organised_dir_rclone_root,
|
||||
public_share_dir=args.public_share_dir,
|
||||
youtube_client_secrets_file=args.youtube_client_secrets_file,
|
||||
youtube_description_file=args.youtube_description_file,
|
||||
rclone_destination=args.rclone_destination,
|
||||
discord_webhook_url=args.discord_webhook_url,
|
||||
email_template_file=args.email_template_file,
|
||||
cdg_styles=cdg_styles,
|
||||
keep_brand_code=args.keep_brand_code,
|
||||
non_interactive=args.yes,
|
||||
)
|
||||
|
||||
try:
|
||||
final_track = kfinalise.process()
|
||||
logger.info(f"Successfully completed processing for: {track['artist']} - {track['title']}")
|
||||
|
||||
# Display summary of outputs
|
||||
logger.info(f"Karaoke processing complete! Output files:")
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {final_track['artist']} - {final_track['title']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Working Files:")
|
||||
logger.info(f" Video With Vocals: {final_track['video_with_vocals']}")
|
||||
logger.info(f" Video With Instrumental: {final_track['video_with_instrumental']}")
|
||||
logger.info(f"")
|
||||
logger.info(f"Final Videos:")
|
||||
logger.info(f" Lossless 4K MP4 (PCM): {final_track['final_video']}")
|
||||
logger.info(f" Lossless 4K MKV (FLAC): {final_track['final_video_mkv']}")
|
||||
logger.info(f" Lossy 4K MP4 (AAC): {final_track['final_video_lossy']}")
|
||||
logger.info(f" Lossy 720p MP4 (AAC): {final_track['final_video_720p']}")
|
||||
|
||||
if "final_karaoke_cdg_zip" in final_track or "final_karaoke_txt_zip" in final_track:
|
||||
logger.info(f"")
|
||||
logger.info(f"Karaoke Files:")
|
||||
|
||||
if "final_karaoke_cdg_zip" in final_track:
|
||||
logger.info(f" CDG+MP3 ZIP: {final_track['final_karaoke_cdg_zip']}")
|
||||
|
||||
if "final_karaoke_txt_zip" in final_track:
|
||||
logger.info(f" TXT+MP3 ZIP: {final_track['final_karaoke_txt_zip']}")
|
||||
|
||||
if final_track["brand_code"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Organization:")
|
||||
logger.info(f" Brand Code: {final_track['brand_code']}")
|
||||
logger.info(f" New Directory: {final_track['new_brand_code_dir_path']}")
|
||||
|
||||
if final_track["youtube_url"] or final_track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f"")
|
||||
logger.info(f"Sharing:")
|
||||
|
||||
if final_track["brand_code_dir_sharing_link"]:
|
||||
logger.info(f" Folder Link: {final_track['brand_code_dir_sharing_link']}")
|
||||
try:
|
||||
time.sleep(1) # Brief pause between clipboard operations
|
||||
pyperclip.copy(final_track["brand_code_dir_sharing_link"])
|
||||
logger.info(f" (Folder link copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy folder link to clipboard: {str(e)}")
|
||||
|
||||
if final_track["youtube_url"]:
|
||||
logger.info(f" YouTube URL: {final_track['youtube_url']}")
|
||||
try:
|
||||
pyperclip.copy(final_track["youtube_url"])
|
||||
logger.info(f" (YouTube URL copied to clipboard)")
|
||||
except Exception as e:
|
||||
logger.warning(f" Failed to copy YouTube URL to clipboard: {str(e)}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error during finalisation: {str(e)}")
|
||||
raise e
|
||||
|
||||
|
||||
def main():
|
||||
asyncio.run(async_main())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,26 +0,0 @@
|
||||
import requests
|
||||
|
||||
|
||||
def download_file(url, filename):
|
||||
# Send a GET request to the URL
|
||||
response = requests.get(url, stream=True)
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
# Open a file with the specified filename in binary write mode
|
||||
with open(filename, "wb") as file:
|
||||
# Write the content of the response to the file
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
file.write(chunk)
|
||||
print("Download completed.")
|
||||
else:
|
||||
print(f"Failed to download. Status code: {response.status_code}")
|
||||
|
||||
|
||||
# URL of the file to be downloaded
|
||||
url = "https://github.com/nomadkaraoke/karaoke-gen/releases/download/v0.8.3/ffmpeg.exe"
|
||||
# Filename to save the downloaded file
|
||||
filename = "platform/ffmpeg.exe"
|
||||
|
||||
# Call the function to download the file
|
||||
download_file(url, filename)
|
||||
Generated
+204
-79
@@ -38,14 +38,14 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "anyio"
|
||||
version = "4.8.0"
|
||||
version = "4.9.0"
|
||||
description = "High level compatibility layer for multiple asynchronous event loop implementations"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main", "dev"]
|
||||
files = [
|
||||
{file = "anyio-4.8.0-py3-none-any.whl", hash = "sha256:b5011f270ab5eb0abf13385f851315585cc37ef330dd88e27ec3d34d651fd47a"},
|
||||
{file = "anyio-4.8.0.tar.gz", hash = "sha256:1d9fe889df5212298c0c0723fa20479d1b94883a2df44bd3897aa91083316f7a"},
|
||||
{file = "anyio-4.9.0-py3-none-any.whl", hash = "sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c"},
|
||||
{file = "anyio-4.9.0.tar.gz", hash = "sha256:673c0c244e15788651a4ff38710fea9675823028a6f08a5eda409e0c9840a028"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -55,8 +55,8 @@ sniffio = ">=1.1"
|
||||
typing_extensions = {version = ">=4.5", markers = "python_version < \"3.13\""}
|
||||
|
||||
[package.extras]
|
||||
doc = ["Sphinx (>=7.4,<8.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx_rtd_theme"]
|
||||
test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "trustme", "truststore (>=0.9.1) ; python_version >= \"3.10\"", "uvloop (>=0.21) ; platform_python_implementation == \"CPython\" and platform_system != \"Windows\" and python_version < \"3.14\""]
|
||||
doc = ["Sphinx (>=8.2,<9.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx_rtd_theme"]
|
||||
test = ["anyio[trio]", "blockbuster (>=1.5.23)", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "trustme", "truststore (>=0.9.1) ; python_version >= \"3.10\"", "uvloop (>=0.21) ; platform_python_implementation == \"CPython\" and platform_system != \"Windows\" and python_version < \"3.14\""]
|
||||
trio = ["trio (>=0.26.1)"]
|
||||
|
||||
[[package]]
|
||||
@@ -101,21 +101,21 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "attrs"
|
||||
version = "25.1.0"
|
||||
version = "25.3.0"
|
||||
description = "Classes Without Boilerplate"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "attrs-25.1.0-py3-none-any.whl", hash = "sha256:c75a69e28a550a7e93789579c22aa26b0f5b83b75dc4e08fe092980051e1090a"},
|
||||
{file = "attrs-25.1.0.tar.gz", hash = "sha256:1c97078a80c814273a76b2a298a932eb681c87415c11dee0a6921de7f1b02c3e"},
|
||||
{file = "attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3"},
|
||||
{file = "attrs-25.3.0.tar.gz", hash = "sha256:75d7cefc7fb576747b2c81b4442d4d4a1ce0900973527c011d1030fd3bf4af1b"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
benchmark = ["cloudpickle ; platform_python_implementation == \"CPython\"", "hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", "pytest-codspeed", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
|
||||
cov = ["cloudpickle ; platform_python_implementation == \"CPython\"", "coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
|
||||
dev = ["cloudpickle ; platform_python_implementation == \"CPython\"", "hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pre-commit-uv", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
|
||||
docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier (<24.7)"]
|
||||
docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier"]
|
||||
tests = ["cloudpickle ; platform_python_implementation == \"CPython\"", "hypothesis", "mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-xdist[psutil]"]
|
||||
tests-mypy = ["mypy (>=1.11.1) ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\"", "pytest-mypy-plugins ; platform_python_implementation == \"CPython\" and python_version >= \"3.10\""]
|
||||
|
||||
@@ -1018,6 +1018,18 @@ files = [
|
||||
{file = "distlib-0.3.9.tar.gz", hash = "sha256:a60f20dea646b8a33f3e7772f74dc0b2d0772d2837ee1342a00645c81edf9403"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "distro"
|
||||
version = "1.9.0"
|
||||
description = "Distro - an OS platform information API"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "distro-1.9.0-py3-none-any.whl", hash = "sha256:7bffd925d65168f85027d8da9af6bddab658135b840670a223589bc0c8ef02b2"},
|
||||
{file = "distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "docx2txt"
|
||||
version = "0.8"
|
||||
@@ -1197,14 +1209,14 @@ python-slugify = "*"
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.17.0"
|
||||
version = "3.18.0"
|
||||
description = "A platform independent file lock."
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main", "dev"]
|
||||
files = [
|
||||
{file = "filelock-3.17.0-py3-none-any.whl", hash = "sha256:533dc2f7ba78dc2f0f531fc6c4940addf7b70a481e269a5a3b93be94ffbe8338"},
|
||||
{file = "filelock-3.17.0.tar.gz", hash = "sha256:ee4e77401ef576ebb38cd7f13b9b28893194acc20a8e68e18730ba9c0e54660e"},
|
||||
{file = "filelock-3.18.0-py3-none-any.whl", hash = "sha256:c401f4f8377c4464e6db25fff06205fd89bdd83b65eb0488ed1b160f780e21de"},
|
||||
{file = "filelock-3.18.0.tar.gz", hash = "sha256:adbc88eabb99d2fec8c9c1b229b171f18afa655400173ddc653d5d01501fb9f2"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
@@ -1214,14 +1226,14 @@ typing = ["typing-extensions (>=4.12.2) ; python_version < \"3.11\""]
|
||||
|
||||
[[package]]
|
||||
name = "findpython"
|
||||
version = "0.6.2"
|
||||
version = "0.6.3"
|
||||
description = "A utility to find python versions on your system"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "findpython-0.6.2-py3-none-any.whl", hash = "sha256:bda62477f858ea623ef2269f5e734469a018104a5f6c0fd9317ba238464ddb76"},
|
||||
{file = "findpython-0.6.2.tar.gz", hash = "sha256:e0c75ba9f35a7f9bb4423eb31bd17358cccf15761b6837317719177aeff46723"},
|
||||
{file = "findpython-0.6.3-py3-none-any.whl", hash = "sha256:a85bb589b559cdf1b87227cc233736eb7cad894b9e68021ee498850611939ebc"},
|
||||
{file = "findpython-0.6.3.tar.gz", hash = "sha256:5863ea55556d8aadc693481a14ac4f3624952719efc1c5591abb0b4a9e965c94"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -1355,22 +1367,22 @@ tqdm = ["tqdm"]
|
||||
|
||||
[[package]]
|
||||
name = "google-api-core"
|
||||
version = "2.24.1"
|
||||
version = "2.24.2"
|
||||
description = "Google API client core library"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "google_api_core-2.24.1-py3-none-any.whl", hash = "sha256:bc78d608f5a5bf853b80bd70a795f703294de656c096c0968320830a4bc280f1"},
|
||||
{file = "google_api_core-2.24.1.tar.gz", hash = "sha256:f8b36f5456ab0dd99a1b693a40a31d1e7757beea380ad1b38faaf8941eae9d8a"},
|
||||
{file = "google_api_core-2.24.2-py3-none-any.whl", hash = "sha256:810a63ac95f3c441b7c0e43d344e372887f62ce9071ba972eacf32672e072de9"},
|
||||
{file = "google_api_core-2.24.2.tar.gz", hash = "sha256:81718493daf06d96d6bc76a91c23874dbf2fac0adbbf542831b805ee6e974696"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
google-auth = ">=2.14.1,<3.0.dev0"
|
||||
googleapis-common-protos = ">=1.56.2,<2.0.dev0"
|
||||
proto-plus = ">=1.22.3,<2.0.0dev"
|
||||
protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<6.0.0.dev0"
|
||||
requests = ">=2.18.0,<3.0.0.dev0"
|
||||
google-auth = ">=2.14.1,<3.0.0"
|
||||
googleapis-common-protos = ">=1.56.2,<2.0.0"
|
||||
proto-plus = ">=1.22.3,<2.0.0"
|
||||
protobuf = ">=3.19.5,<3.20.0 || >3.20.0,<3.20.1 || >3.20.1,<4.21.0 || >4.21.0,<4.21.1 || >4.21.1,<4.21.2 || >4.21.2,<4.21.3 || >4.21.3,<4.21.4 || >4.21.4,<4.21.5 || >4.21.5,<7.0.0"
|
||||
requests = ">=2.18.0,<3.0.0"
|
||||
|
||||
[package.extras]
|
||||
async-rest = ["google-auth[aiohttp] (>=2.35.0,<3.0.dev0)"]
|
||||
@@ -1380,14 +1392,14 @@ grpcio-gcp = ["grpcio-gcp (>=0.2.2,<1.0.dev0)"]
|
||||
|
||||
[[package]]
|
||||
name = "google-api-python-client"
|
||||
version = "2.163.0"
|
||||
version = "2.164.0"
|
||||
description = "Google API Client Library for Python"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "google_api_python_client-2.163.0-py2.py3-none-any.whl", hash = "sha256:080e8bc0669cb4c1fb8efb8da2f5b91a2625d8f0e7796cfad978f33f7016c6c4"},
|
||||
{file = "google_api_python_client-2.163.0.tar.gz", hash = "sha256:88dee87553a2d82176e2224648bf89272d536c8f04dcdda37ef0a71473886dd7"},
|
||||
{file = "google_api_python_client-2.164.0-py2.py3-none-any.whl", hash = "sha256:b2037c3d280793c8d5180b04317b16be4acd5f77af5dfa7213ace32d140a9ffe"},
|
||||
{file = "google_api_python_client-2.164.0.tar.gz", hash = "sha256:116f5a05dfb95ed7f7ea0d0f561fc5464146709c583226cc814690f9bb221492"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -1551,14 +1563,14 @@ zstd = ["zstandard (>=0.18.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "huggingface-hub"
|
||||
version = "0.29.2"
|
||||
version = "0.29.3"
|
||||
description = "Client library to download and publish models, datasets and other repos on the huggingface.co hub"
|
||||
optional = false
|
||||
python-versions = ">=3.8.0"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "huggingface_hub-0.29.2-py3-none-any.whl", hash = "sha256:c56f20fca09ef19da84dcde2b76379ecdaddf390b083f59f166715584953307d"},
|
||||
{file = "huggingface_hub-0.29.2.tar.gz", hash = "sha256:590b29c0dcbd0ee4b7b023714dc1ad8563fe4a68a91463438b74e980d28afaf3"},
|
||||
{file = "huggingface_hub-0.29.3-py3-none-any.whl", hash = "sha256:0b25710932ac649c08cdbefa6c6ccb8e88eef82927cacdb048efb726429453aa"},
|
||||
{file = "huggingface_hub-0.29.3.tar.gz", hash = "sha256:64519a25716e0ba382ba2d3fb3ca082e7c7eb4a2fc634d200e8380006e0760e5"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -1763,6 +1775,92 @@ MarkupSafe = ">=2.0"
|
||||
[package.extras]
|
||||
i18n = ["Babel (>=2.7)"]
|
||||
|
||||
[[package]]
|
||||
name = "jiter"
|
||||
version = "0.9.0"
|
||||
description = "Fast iterable JSON parser."
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "jiter-0.9.0-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:816ec9b60fdfd1fec87da1d7ed46c66c44ffec37ab2ef7de5b147b2fce3fd5ad"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9b1d3086f8a3ee0194ecf2008cf81286a5c3e540d977fa038ff23576c023c0ea"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1339f839b91ae30b37c409bf16ccd3dc453e8b8c3ed4bd1d6a567193651a4a51"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:ffba79584b3b670fefae66ceb3a28822365d25b7bf811e030609a3d5b876f538"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5cfc7d0a8e899089d11f065e289cb5b2daf3d82fbe028f49b20d7b809193958d"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e00a1a2bbfaaf237e13c3d1592356eab3e9015d7efd59359ac8b51eb56390a12"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d1d9870561eb26b11448854dce0ff27a9a27cb616b632468cafc938de25e9e51"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:9872aeff3f21e437651df378cb75aeb7043e5297261222b6441a620218b58708"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:1fd19112d1049bdd47f17bfbb44a2c0001061312dcf0e72765bfa8abd4aa30e5"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:6ef5da104664e526836070e4a23b5f68dec1cc673b60bf1edb1bfbe8a55d0678"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-win32.whl", hash = "sha256:cb12e6d65ebbefe5518de819f3eda53b73187b7089040b2d17f5b39001ff31c4"},
|
||||
{file = "jiter-0.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:c43ca669493626d8672be3b645dbb406ef25af3f4b6384cfd306da7eb2e70322"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:6c4d99c71508912a7e556d631768dcdef43648a93660670986916b297f1c54af"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8f60fb8ce7df529812bf6c625635a19d27f30806885139e367af93f6e734ef58"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:51c4e1a4f8ea84d98b7b98912aa4290ac3d1eabfde8e3c34541fae30e9d1f08b"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:5f4c677c424dc76684fea3e7285a7a2a7493424bea89ac441045e6a1fb1d7b3b"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2221176dfec87f3470b21e6abca056e6b04ce9bff72315cb0b243ca9e835a4b5"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3c7adb66f899ffa25e3c92bfcb593391ee1947dbdd6a9a970e0d7e713237d572"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c98d27330fdfb77913c1097a7aab07f38ff2259048949f499c9901700789ac15"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:eda3f8cc74df66892b1d06b5d41a71670c22d95a1ca2cbab73654745ce9d0419"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:dd5ab5ddc11418dce28343123644a100f487eaccf1de27a459ab36d6cca31043"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:42f8a68a69f047b310319ef8e2f52fdb2e7976fb3313ef27df495cf77bcad965"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-win32.whl", hash = "sha256:a25519efb78a42254d59326ee417d6f5161b06f5da827d94cf521fed961b1ff2"},
|
||||
{file = "jiter-0.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:923b54afdd697dfd00d368b7ccad008cccfeb1efb4e621f32860c75e9f25edbd"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:7b46249cfd6c48da28f89eb0be3f52d6fdb40ab88e2c66804f546674e539ec11"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:609cf3c78852f1189894383cf0b0b977665f54cb38788e3e6b941fa6d982c00e"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d726a3890a54561e55a9c5faea1f7655eda7f105bd165067575ace6e65f80bb2"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2e89dc075c1fef8fa9be219e249f14040270dbc507df4215c324a1839522ea75"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:04e8ffa3c353b1bc4134f96f167a2082494351e42888dfcf06e944f2729cbe1d"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:203f28a72a05ae0e129b3ed1f75f56bc419d5f91dfacd057519a8bd137b00c42"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fca1a02ad60ec30bb230f65bc01f611c8608b02d269f998bc29cca8619a919dc"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:237e5cee4d5d2659aaf91bbf8ec45052cc217d9446070699441a91b386ae27dc"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:528b6b71745e7326eed73c53d4aa57e2a522242320b6f7d65b9c5af83cf49b6e"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:9f48e86b57bc711eb5acdfd12b6cb580a59cc9a993f6e7dcb6d8b50522dcd50d"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-win32.whl", hash = "sha256:699edfde481e191d81f9cf6d2211debbfe4bd92f06410e7637dffb8dd5dfde06"},
|
||||
{file = "jiter-0.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:099500d07b43f61d8bd780466d429c45a7b25411b334c60ca875fa775f68ccb0"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:2764891d3f3e8b18dce2cff24949153ee30c9239da7c00f032511091ba688ff7"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:387b22fbfd7a62418d5212b4638026d01723761c75c1c8232a8b8c37c2f1003b"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:40d8da8629ccae3606c61d9184970423655fb4e33d03330bcdfe52d234d32f69"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a1be73d8982bdc278b7b9377426a4b44ceb5c7952073dd7488e4ae96b88e1103"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2228eaaaa111ec54b9e89f7481bffb3972e9059301a878d085b2b449fbbde635"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:11509bfecbc319459647d4ac3fd391d26fdf530dad00c13c4dadabf5b81f01a4"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f22238da568be8bbd8e0650e12feeb2cfea15eda4f9fc271d3b362a4fa0604d"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:17f5d55eb856597607562257c8e36c42bc87f16bef52ef7129b7da11afc779f3"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:6a99bed9fbb02f5bed416d137944419a69aa4c423e44189bc49718859ea83bc5"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:e057adb0cd1bd39606100be0eafe742de2de88c79df632955b9ab53a086b3c8d"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-win32.whl", hash = "sha256:f7e6850991f3940f62d387ccfa54d1a92bd4bb9f89690b53aea36b4364bcab53"},
|
||||
{file = "jiter-0.9.0-cp313-cp313-win_amd64.whl", hash = "sha256:c8ae3bf27cd1ac5e6e8b7a27487bf3ab5f82318211ec2e1346a5b058756361f7"},
|
||||
{file = "jiter-0.9.0-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:f0b2827fb88dda2cbecbbc3e596ef08d69bda06c6f57930aec8e79505dc17001"},
|
||||
{file = "jiter-0.9.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:062b756ceb1d40b0b28f326cba26cfd575a4918415b036464a52f08632731e5a"},
|
||||
{file = "jiter-0.9.0-cp313-cp313t-win_amd64.whl", hash = "sha256:6f7838bc467ab7e8ef9f387bd6de195c43bad82a569c1699cb822f6609dd4cdf"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:4a2d16360d0642cd68236f931b85fe50288834c383492e4279d9f1792e309571"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e84ed1c9c9ec10bbb8c37f450077cbe3c0d4e8c2b19f0a49a60ac7ace73c7452"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9f3c848209ccd1bfa344a1240763975ca917de753c7875c77ec3034f4151d06c"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7825f46e50646bee937e0f849d14ef3a417910966136f59cd1eb848b8b5bb3e4"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d82a811928b26d1a6311a886b2566f68ccf2b23cf3bfed042e18686f1f22c2d7"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0c058ecb51763a67f019ae423b1cbe3fa90f7ee6280c31a1baa6ccc0c0e2d06e"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9897115ad716c48f0120c1f0c4efae348ec47037319a6c63b2d7838bb53aaef4"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:351f4c90a24c4fb8c87c6a73af2944c440494ed2bea2094feecacb75c50398ae"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:d45807b0f236c485e1e525e2ce3a854807dfe28ccf0d013dd4a563395e28008a"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:1537a890724ba00fdba21787010ac6f24dad47f763410e9e1093277913592784"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-win32.whl", hash = "sha256:e3630ec20cbeaddd4b65513fa3857e1b7c4190d4481ef07fb63d0fad59033321"},
|
||||
{file = "jiter-0.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:2685f44bf80e95f8910553bf2d33b9c87bf25fceae6e9f0c1355f75d2922b0ee"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:9ef340fae98065071ccd5805fe81c99c8f80484e820e40043689cf97fb66b3e2"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:efb767d92c63b2cd9ec9f24feeb48f49574a713870ec87e9ba0c2c6e9329c3e2"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:113f30f87fb1f412510c6d7ed13e91422cfd329436364a690c34c8b8bd880c42"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8793b6df019b988526f5a633fdc7456ea75e4a79bd8396a3373c371fc59f5c9b"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7a9aaa5102dba4e079bb728076fadd5a2dca94c05c04ce68004cfd96f128ea34"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d838650f6ebaf4ccadfb04522463e74a4c378d7e667e0eb1865cfe3990bfac49"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c0194f813efdf4b8865ad5f5c5f50f8566df7d770a82c51ef593d09e0b347020"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:a7954a401d0a8a0b8bc669199db78af435aae1e3569187c2939c477c53cb6a0a"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:4feafe787eb8a8d98168ab15637ca2577f6ddf77ac6c8c66242c2d028aa5420e"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:27cd1f2e8bb377f31d3190b34e4328d280325ad7ef55c6ac9abde72f79e84d2e"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-win32.whl", hash = "sha256:161d461dcbe658cf0bd0aa375b30a968b087cdddc624fc585f3867c63c6eca95"},
|
||||
{file = "jiter-0.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:e8b36d8a16a61993be33e75126ad3d8aa29cf450b09576f3c427d27647fcb4aa"},
|
||||
{file = "jiter-0.9.0.tar.gz", hash = "sha256:aadba0964deb424daa24492abc3d229c60c4a31bfee205aedbf1acc7639d7893"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "joblib"
|
||||
version = "1.4.2"
|
||||
@@ -2023,34 +2121,34 @@ rapidfuzz = ">=3.9.0,<4.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "librosa"
|
||||
version = "0.10.2.post1"
|
||||
version = "0.11.0"
|
||||
description = "Python module for audio and music processing"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
python-versions = ">=3.8"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "librosa-0.10.2.post1-py3-none-any.whl", hash = "sha256:dc882750e8b577a63039f25661b7e39ec4cfbacc99c1cffba666cd664fb0a7a0"},
|
||||
{file = "librosa-0.10.2.post1.tar.gz", hash = "sha256:cd99f16717cbcd1e0983e37308d1db46a6f7dfc2e396e5a9e61e6821e44bd2e7"},
|
||||
{file = "librosa-0.11.0-py3-none-any.whl", hash = "sha256:0b6415c4fd68bff4c29288abe67c6d80b587e0e1e2cfb0aad23e4559504a7fa1"},
|
||||
{file = "librosa-0.11.0.tar.gz", hash = "sha256:f5ed951ca189b375bbe2e33b2abd7e040ceeee302b9bbaeeffdfddb8d0ace908"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
audioread = ">=2.1.9"
|
||||
decorator = ">=4.3.0"
|
||||
joblib = ">=0.14"
|
||||
lazy-loader = ">=0.1"
|
||||
joblib = ">=1.0"
|
||||
lazy_loader = ">=0.1"
|
||||
msgpack = ">=1.0"
|
||||
numba = ">=0.51.0"
|
||||
numpy = ">=1.20.3,<1.22.0 || >1.22.0,<1.22.1 || >1.22.1,<1.22.2 || >1.22.2"
|
||||
numpy = ">=1.22.3"
|
||||
pooch = ">=1.1"
|
||||
scikit-learn = ">=0.20.0"
|
||||
scipy = ">=1.2.0"
|
||||
scikit-learn = ">=1.1.0"
|
||||
scipy = ">=1.6.0"
|
||||
soundfile = ">=0.12.1"
|
||||
soxr = ">=0.3.2"
|
||||
typing-extensions = ">=4.1.1"
|
||||
typing_extensions = ">=4.1.1"
|
||||
|
||||
[package.extras]
|
||||
display = ["matplotlib (>=3.5.0)"]
|
||||
docs = ["ipython (>=7.0)", "matplotlib (>=3.5.0)", "mir-eval (>=0.5)", "numba (>=0.51)", "numpydoc", "presets", "sphinx (!=1.3.1)", "sphinx-copybutton (>=0.5.2)", "sphinx-gallery (>=0.7)", "sphinx-multiversion (>=0.2.3)", "sphinx-rtd-theme (>=1.2.0)", "sphinxcontrib-svg2pdfconverter"]
|
||||
docs = ["ipython (>=7.0)", "matplotlib (>=3.5.0)", "mir_eval (>=0.5)", "numba (>=0.51)", "numpydoc", "presets", "sphinx (!=1.3.1)", "sphinx-copybutton (>=0.5.2)", "sphinx-gallery (>=0.7)", "sphinx-multiversion (>=0.2.3)", "sphinx_rtd_theme (>=1.2.0)", "sphinxcontrib-googleanalytics (>=0.4)", "sphinxcontrib-svg2pdfconverter"]
|
||||
tests = ["matplotlib (>=3.5.0)", "packaging (>=20.0)", "pytest", "pytest-cov", "pytest-mpl", "resampy (>=0.2.2)", "samplerate", "types-decorator"]
|
||||
|
||||
[[package]]
|
||||
@@ -2253,14 +2351,14 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "lyrics-transcriber"
|
||||
version = "0.43.1"
|
||||
version = "0.48.0"
|
||||
description = "Automatically create synchronised lyrics files in ASS and MidiCo LRC formats with word-level timestamps, using Whisper and lyrics from Genius and Spotify"
|
||||
optional = false
|
||||
python-versions = "<3.13,>=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "lyrics_transcriber-0.43.1-py3-none-any.whl", hash = "sha256:1baf60b1487ec0fd069bdc071cdaa8612091f85898385794f4f2cd7870e0369c"},
|
||||
{file = "lyrics_transcriber-0.43.1.tar.gz", hash = "sha256:83c2fd0e73f268ccfe00ef81e8860a7a64116d1a6a5b8e48576a5a2e1ef26733"},
|
||||
{file = "lyrics_transcriber-0.48.0-py3-none-any.whl", hash = "sha256:236536aa45ebfe29a5924e92505ea1e813be44d1f73b683db040106c58de72e9"},
|
||||
{file = "lyrics_transcriber-0.48.0.tar.gz", hash = "sha256:ba01d82faad42432f6c82bf7bdc9a6505dc16f20e888b7ec54cb11fbf633d1a3"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -2268,10 +2366,11 @@ dropbox = ">=12"
|
||||
fastapi = ">=0.115"
|
||||
fonttools = ">=4.55"
|
||||
karaoke-lyrics-processor = ">=0.4"
|
||||
lyricsgenius = ">=3"
|
||||
lyricsgenius = ">=0.1.0"
|
||||
metaphone = ">=0.6"
|
||||
nltk = ">=3.9"
|
||||
ollama = ">=0.4.7,<0.5.0"
|
||||
openai = ">=1.63.2,<2.0.0"
|
||||
pydub = ">=0.25"
|
||||
python-dotenv = ">=1"
|
||||
python-levenshtein = ">=0.26"
|
||||
@@ -3156,6 +3255,32 @@ packaging = "*"
|
||||
protobuf = "*"
|
||||
sympy = "*"
|
||||
|
||||
[[package]]
|
||||
name = "openai"
|
||||
version = "1.66.3"
|
||||
description = "The official Python library for the openai API"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "openai-1.66.3-py3-none-any.whl", hash = "sha256:a427c920f727711877ab17c11b95f1230b27767ba7a01e5b66102945141ceca9"},
|
||||
{file = "openai-1.66.3.tar.gz", hash = "sha256:8dde3aebe2d081258d4159c4cb27bdc13b5bb3f7ea2201d9bd940b9a89faf0c9"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
anyio = ">=3.5.0,<5"
|
||||
distro = ">=1.7.0,<2"
|
||||
httpx = ">=0.23.0,<1"
|
||||
jiter = ">=0.4.0,<1"
|
||||
pydantic = ">=1.9.0,<3"
|
||||
sniffio = "*"
|
||||
tqdm = ">4"
|
||||
typing-extensions = ">=4.11,<5"
|
||||
|
||||
[package.extras]
|
||||
datalib = ["numpy (>=1)", "pandas (>=1.2.3)", "pandas-stubs (>=1.1.0.11)"]
|
||||
realtime = ["websockets (>=13,<15)"]
|
||||
|
||||
[[package]]
|
||||
name = "packaging"
|
||||
version = "24.2"
|
||||
@@ -3182,14 +3307,14 @@ files = [
|
||||
|
||||
[[package]]
|
||||
name = "pbs-installer"
|
||||
version = "2025.2.12"
|
||||
version = "2025.3.11"
|
||||
description = "Installer for Python Build Standalone"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "pbs_installer-2025.2.12-py3-none-any.whl", hash = "sha256:3d9034047945b2d5f169cd9bb324f1f28c37d0ec120d6110ddb10aa07016fb79"},
|
||||
{file = "pbs_installer-2025.2.12.tar.gz", hash = "sha256:c6815165babf312c90d27ccd16afe598de641d616860f88e1855f183b0253b39"},
|
||||
{file = "pbs_installer-2025.3.11-py3-none-any.whl", hash = "sha256:c5d17afdb41abbec2afda815d41a93276887f19e6bdc16e98b2dfed11d845968"},
|
||||
{file = "pbs_installer-2025.3.11.tar.gz", hash = "sha256:150986b56648e2d04e99fafe24c165fa94cfa8385b93d6bf9b82925c3d57d064"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -3466,18 +3591,18 @@ murmurhash = ">=0.28.0,<1.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "proto-plus"
|
||||
version = "1.26.0"
|
||||
version = "1.26.1"
|
||||
description = "Beautiful, Pythonic protocol buffers"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "proto_plus-1.26.0-py3-none-any.whl", hash = "sha256:bf2dfaa3da281fc3187d12d224c707cb57214fb2c22ba854eb0c105a3fb2d4d7"},
|
||||
{file = "proto_plus-1.26.0.tar.gz", hash = "sha256:6e93d5f5ca267b54300880fff156b6a3386b3fa3f43b1da62e680fc0c586ef22"},
|
||||
{file = "proto_plus-1.26.1-py3-none-any.whl", hash = "sha256:13285478c2dcf2abb829db158e1047e2f1e8d63a077d94263c2b88b043c75a66"},
|
||||
{file = "proto_plus-1.26.1.tar.gz", hash = "sha256:21a515a4c4c0088a773899e23c7bbade3d18f9c66c73edd4c7ee3816bc96a012"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
protobuf = ">=3.19.0,<6.0.0dev"
|
||||
protobuf = ">=3.19.0,<7.0.0"
|
||||
|
||||
[package.extras]
|
||||
testing = ["google-api-core (>=1.31.5)"]
|
||||
@@ -4539,14 +4664,14 @@ jeepney = ">=0.6"
|
||||
|
||||
[[package]]
|
||||
name = "setuptools"
|
||||
version = "75.8.2"
|
||||
version = "76.0.0"
|
||||
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "setuptools-75.8.2-py3-none-any.whl", hash = "sha256:558e47c15f1811c1fa7adbd0096669bf76c1d3f433f58324df69f3f5ecac4e8f"},
|
||||
{file = "setuptools-75.8.2.tar.gz", hash = "sha256:4880473a969e5f23f2a2be3646b2dfd84af9028716d398e46192f84bc36900d2"},
|
||||
{file = "setuptools-76.0.0-py3-none-any.whl", hash = "sha256:199466a166ff664970d0ee145839f5582cb9bca7a0a3a2e795b6a9cb2308e9c6"},
|
||||
{file = "setuptools-76.0.0.tar.gz", hash = "sha256:43b4ee60e10b0d0ee98ad11918e114c70701bc6051662a9a675a0496c1a158f4"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
@@ -5089,14 +5214,14 @@ torch = ["torch (>=1.6.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "threadpoolctl"
|
||||
version = "3.5.0"
|
||||
version = "3.6.0"
|
||||
description = "threadpoolctl"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "threadpoolctl-3.5.0-py3-none-any.whl", hash = "sha256:56c1e26c150397e58c4926da8eeee87533b1e32bef131bd4bf6a2f45f3185467"},
|
||||
{file = "threadpoolctl-3.5.0.tar.gz", hash = "sha256:082433502dd922bf738de0d8bcc4fdcbf0979ff44c42bd40f5af8a282f6fa107"},
|
||||
{file = "threadpoolctl-3.6.0-py3-none-any.whl", hash = "sha256:43a0b8fd5a2928500110039e43a5eed8480b918967083ea48dc3ab9f13c4a7fb"},
|
||||
{file = "threadpoolctl-3.6.0.tar.gz", hash = "sha256:8ab8b4aa3491d812b623328249fab5302a68d2d71745c8a4c719a2fcaba9f44e"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5116,27 +5241,27 @@ tests = ["coverage", "mypy", "pycodestyle", "pylint", "pytest"]
|
||||
|
||||
[[package]]
|
||||
name = "tokenizers"
|
||||
version = "0.21.0"
|
||||
version = "0.21.1"
|
||||
description = ""
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
python-versions = ">=3.9"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:3c4c93eae637e7d2aaae3d376f06085164e1660f89304c0ab2b1d08a406636b2"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:f53ea537c925422a2e0e92a24cce96f6bc5046bbef24a1652a5edc8ba975f62e"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6b177fb54c4702ef611de0c069d9169f0004233890e0c4c5bd5508ae05abf193"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:6b43779a269f4629bebb114e19c3fca0223296ae9fea8bb9a7a6c6fb0657ff8e"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9aeb255802be90acfd363626753fda0064a8df06031012fe7d52fd9a905eb00e"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d8b09dbeb7a8d73ee204a70f94fc06ea0f17dcf0844f16102b9f414f0b7463ba"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:400832c0904f77ce87c40f1a8a27493071282f785724ae62144324f171377273"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e84ca973b3a96894d1707e189c14a774b701596d579ffc7e69debfc036a61a04"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:eb7202d231b273c34ec67767378cd04c767e967fda12d4a9e36208a34e2f137e"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:089d56db6782a73a27fd8abf3ba21779f5b85d4a9f35e3b493c7bbcbbf0d539b"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:c87ca3dc48b9b1222d984b6b7490355a6fdb411a2d810f6f05977258400ddb74"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:4145505a973116f91bc3ac45988a92e618a6f83eb458f49ea0790df94ee243ff"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-win32.whl", hash = "sha256:eb1702c2f27d25d9dd5b389cc1f2f51813e99f8ca30d9e25348db6585a97e24a"},
|
||||
{file = "tokenizers-0.21.0-cp39-abi3-win_amd64.whl", hash = "sha256:87841da5a25a3a5f70c102de371db120f41873b854ba65e52bccd57df5a3780c"},
|
||||
{file = "tokenizers-0.21.0.tar.gz", hash = "sha256:ee0894bf311b75b0c03079f33859ae4b2334d675d4e93f5a4132e1eae2834fe4"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:e78e413e9e668ad790a29456e677d9d3aa50a9ad311a40905d6861ba7692cf41"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:cd51cd0a91ecc801633829fcd1fda9cf8682ed3477c6243b9a095539de4aecf3"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:28da6b72d4fb14ee200a1bd386ff74ade8992d7f725f2bde2c495a9a98cf4d9f"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:34d8cfde551c9916cb92014e040806122295a6800914bab5865deb85623931cf"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aaa852d23e125b73d283c98f007e06d4595732104b65402f46e8ef24b588d9f8"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a21a15d5c8e603331b8a59548bbe113564136dc0f5ad8306dd5033459a226da0"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2fdbd4c067c60a0ac7eca14b6bd18a5bebace54eb757c706b47ea93204f7a37c"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2dd9a0061e403546f7377df940e866c3e678d7d4e9643d0461ea442b4f89e61a"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:db9484aeb2e200c43b915a1a0150ea885e35f357a5a8fabf7373af333dcc8dbf"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:ed248ab5279e601a30a4d67bdb897ecbe955a50f1e7bb62bd99f07dd11c2f5b6"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:9ac78b12e541d4ce67b4dfd970e44c060a2147b9b2a21f509566d556a509c67d"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:e5a69c1a4496b81a5ee5d2c1f3f7fbdf95e90a0196101b0ee89ed9956b8a168f"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-win32.whl", hash = "sha256:1039a3a5734944e09de1d48761ade94e00d0fa760c0e0551151d4dd851ba63e3"},
|
||||
{file = "tokenizers-0.21.1-cp39-abi3-win_amd64.whl", hash = "sha256:0f0dcbcc9f6e13e675a66d7a5f2f225a736745ce484c1a4e07476a89ccdad382"},
|
||||
{file = "tokenizers-0.21.1.tar.gz", hash = "sha256:a1bb04dc5b448985f86ecd4b05407f5a8d97cb2c0532199b2a302a604a0165ab"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
@@ -5426,14 +5551,14 @@ tutorials = ["matplotlib", "pandas", "tabulate"]
|
||||
|
||||
[[package]]
|
||||
name = "trove-classifiers"
|
||||
version = "2025.3.3.18"
|
||||
version = "2025.3.13.13"
|
||||
description = "Canonical source for classifiers on PyPI (pypi.org)."
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
groups = ["dev"]
|
||||
files = [
|
||||
{file = "trove_classifiers-2025.3.3.18-py3-none-any.whl", hash = "sha256:215630da61cf8757c373f81b602fc1283ec5a691cf12c5f9f96f11d6ad5fc7f2"},
|
||||
{file = "trove_classifiers-2025.3.3.18.tar.gz", hash = "sha256:3ffcfa90a428adfde1a5d90e3aa1b87fe474c5dbdbf5ccbca74ed69ba83c5ca7"},
|
||||
{file = "trove_classifiers-2025.3.13.13-py3-none-any.whl", hash = "sha256:c1679d2876eef24584ad1619e3870177c216bab28bd5bc5b59ee78b491eb8a6b"},
|
||||
{file = "trove_classifiers-2025.3.13.13.tar.gz", hash = "sha256:2a5e24ddafb20da2225a825fe167c4fd4ecbf312cef4310d67f19dc40da7dc8d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5910,4 +6035,4 @@ cffi = ["cffi (>=1.11)"]
|
||||
[metadata]
|
||||
lock-version = "2.1"
|
||||
python-versions = ">=3.10,<3.13"
|
||||
content-hash = "601b411b7a247df8256530df2a3f18ee4638014e3c7d86c0b381aaf1e11a089c"
|
||||
content-hash = "db4df5e65ca0de735fe085a6e23ceceeaa5d3cb2147c8c3b1e2cbe07455ae024"
|
||||
+7
-7
@@ -22,7 +22,7 @@ from email.mime.text import MIMEText
|
||||
from lyrics_transcriber.output.cdg import CDGGenerator
|
||||
|
||||
|
||||
class KaraokeFinalise:
|
||||
class OldKaraokeFinalise:
|
||||
def __init__(
|
||||
self,
|
||||
logger=None,
|
||||
@@ -559,9 +559,9 @@ class KaraokeFinalise:
|
||||
self.logger.info(f"Searching for files in current directory containing {search_string}")
|
||||
|
||||
all_instrumental_files = [f for f in os.listdir(".") if search_string in f]
|
||||
flac_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.endswith(".flac"))
|
||||
mp3_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.endswith(".mp3"))
|
||||
wav_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.endswith(".wav"))
|
||||
flac_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.lower().endswith(".flac"))
|
||||
mp3_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.lower().endswith(".mp3"))
|
||||
wav_files = set(f.rsplit(".", 1)[0] for f in all_instrumental_files if f.lower().endswith(".wav"))
|
||||
|
||||
self.logger.debug(f"FLAC files found: {flac_files}")
|
||||
self.logger.debug(f"MP3 files found: {mp3_files}")
|
||||
@@ -572,9 +572,9 @@ class KaraokeFinalise:
|
||||
filtered_files = [
|
||||
f
|
||||
for f in all_instrumental_files
|
||||
if f.endswith(".flac")
|
||||
or (f.endswith(".wav") and f.rsplit(".", 1)[0] not in flac_files)
|
||||
or (f.endswith(".mp3") and f.rsplit(".", 1)[0] not in flac_files and f.rsplit(".", 1)[0] not in wav_files)
|
||||
if f.lower().endswith(".flac")
|
||||
or (f.lower().endswith(".wav") and f.rsplit(".", 1)[0] not in flac_files)
|
||||
or (f.lower().endswith(".mp3") and f.rsplit(".", 1)[0] not in flac_files and f.rsplit(".", 1)[0] not in wav_files)
|
||||
]
|
||||
|
||||
self.logger.debug(f"Filtered instrumental files: {filtered_files}")
|
||||
@@ -22,7 +22,7 @@ import json
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
class KaraokePrep:
|
||||
class OldKaraokePrep:
|
||||
def __init__(
|
||||
self,
|
||||
# Basic inputs
|
||||
@@ -999,7 +999,7 @@ class KaraokePrep:
|
||||
else:
|
||||
# Try to load from package resources
|
||||
try:
|
||||
with pkg_resources.path("karaoke_prep.resources", format["font"]) as font_path:
|
||||
with pkg_resources.path("karaoke_gen.resources", format["font"]) as font_path:
|
||||
font_path = str(font_path)
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Could not load font from resources: {e}, falling back to default font")
|
||||
@@ -1241,7 +1241,7 @@ class KaraokePrep:
|
||||
stems_dir = self._create_stems_directory(track_output_dir)
|
||||
result = {"clean_instrumental": {}, "other_stems": {}, "backing_vocals": {}, "combined_instrumentals": {}}
|
||||
|
||||
if os.environ.get("KARAOKE_PREP_SKIP_AUDIO_SEPARATION"):
|
||||
if os.environ.get("KARAOKE_GEN_SKIP_AUDIO_SEPARATION"):
|
||||
return result
|
||||
|
||||
result["clean_instrumental"] = self._separate_clean_instrumental(
|
||||
@@ -1646,7 +1646,7 @@ class KaraokePrep:
|
||||
processed_track["title_image_jpg"] = f"{output_image_filepath_noext}.jpg"
|
||||
processed_track["title_video"] = os.path.join(track_output_dir, f"{artist_title} (Title).mov")
|
||||
|
||||
if not self._file_exists(processed_track["title_video"]) and not os.environ.get("KARAOKE_PREP_SKIP_TITLE_END_SCREENS"):
|
||||
if not self._file_exists(processed_track["title_video"]) and not os.environ.get("KARAOKE_GEN_SKIP_TITLE_END_SCREENS"):
|
||||
self.logger.info(f"Creating title video...")
|
||||
self.create_title_video(
|
||||
self.artist, self.title, self.title_format, output_image_filepath_noext, processed_track["title_video"]
|
||||
@@ -1657,7 +1657,7 @@ class KaraokePrep:
|
||||
processed_track["end_image_jpg"] = f"{output_image_filepath_noext}.jpg"
|
||||
processed_track["end_video"] = os.path.join(track_output_dir, f"{artist_title} (End).mov")
|
||||
|
||||
if not self._file_exists(processed_track["end_video"]) and not os.environ.get("KARAOKE_PREP_SKIP_TITLE_END_SCREENS"):
|
||||
if not self._file_exists(processed_track["end_video"]) and not os.environ.get("KARAOKE_GEN_SKIP_TITLE_END_SCREENS"):
|
||||
self.logger.info(f"Creating end screen video...")
|
||||
self.create_end_video(self.artist, self.title, self.end_format, output_image_filepath_noext, processed_track["end_video"])
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
# Karaoke Prep Functionality Map
|
||||
|
||||
This document maps the functionality in the original `old_prep.py` file, showing the line ranges for different functional components.
|
||||
|
||||
## Class Definition and Initialization
|
||||
- **Class Definition**: Lines 25-1808
|
||||
- **Constructor `__init__`**: Lines 26-306
|
||||
- Parameter initialization: Lines 26-91
|
||||
- Logger setup: Lines 92-123
|
||||
- Basic parameters: Lines 125-133
|
||||
- Audio processing parameters: Lines 135-141
|
||||
- Input/Output parameters: Lines 143-148
|
||||
- Lyrics parameters: Lines 150-160
|
||||
- Style parameters and loading: Lines 162-237
|
||||
- Title/End format setup: Lines 239-280
|
||||
- Video settings: Lines 282-286
|
||||
- FFmpeg configuration: Lines 288-296
|
||||
- Debug logging: Lines 298-302
|
||||
- Initialization of output directory: Lines 304-306
|
||||
|
||||
## Helper Methods
|
||||
- **`parse_region`**: Lines 308-315 - Parses region string to tuple
|
||||
- **`sanitize_filename`**: Lines 530-536 - Sanitizes filenames for safe use
|
||||
- **`hex_to_rgb`**: Lines 1181-1184 - Converts hex color to RGB tuple
|
||||
- **`_file_exists`**: Lines 1499-1505 - Checks if file exists and logs result
|
||||
- **`_transform_text`**: Lines 1174-1181 - Transforms text based on specified type
|
||||
|
||||
## Media Information Extraction
|
||||
- **`extract_info_for_online_media`**: Lines 317-330 - Extracts info from online media
|
||||
- **`parse_single_track_metadata`**: Lines 332-382 - Parses metadata from extracted info
|
||||
|
||||
## Media Handling
|
||||
- **`copy_input_media`**: Lines 384-401 - Copies local media file
|
||||
- **`download_video`**: Lines 403-427 - Downloads video from URL
|
||||
- **`extract_still_image_from_video`**: Lines 429-436 - Extracts still image from video
|
||||
- **`convert_to_wav`**: Lines 438-462 - Converts media to WAV format
|
||||
|
||||
## Lyrics Processing
|
||||
- **`find_best_split_point`**: Lines 464-497 - Finds optimal split points for long lines
|
||||
- **`process_line`**: Lines 499-532 - Processes lyrics lines for optimal display
|
||||
- **`transcribe_lyrics`**: Lines 538-637 - Handles lyrics transcription via external module
|
||||
- **`backup_existing_outputs`**: Lines 538-599 - Backs up existing outputs to versioned folder
|
||||
|
||||
## Audio Separation
|
||||
- **`separate_audio`**: Lines 601-653 - Separates audio using audio-separator
|
||||
- **`process_audio_separation`**: Lines 1186-1311 - Main audio separation process
|
||||
- **`_create_stems_directory`**: Lines 1313-1318 - Creates stems directory
|
||||
- **`_separate_clean_instrumental`**: Lines 1320-1344 - Separates clean instrumental
|
||||
- **`_separate_other_stems`**: Lines 1346-1379 - Separates other stems
|
||||
- **`_separate_backing_vocals`**: Lines 1381-1405 - Separates backing vocals
|
||||
- **`_generate_combined_instrumentals`**: Lines 1407-1429 - Combines instrumentals with backing vocals
|
||||
- **`_normalize_audio_files`**: Lines 1431-1457 - Normalizes audio files
|
||||
- **`_normalize_audio`**: Lines 1459-1497 - Performs audio normalization
|
||||
|
||||
## Output Path Handling
|
||||
- **`setup_output_paths`**: Lines 655-677 - Sets up output paths for track
|
||||
|
||||
## Video and Image Generation
|
||||
- **`_create_gradient_mask`**: Lines 679-718 - Creates gradient mask for text coloring
|
||||
- **`calculate_text_size_to_fit`**: Lines 720-771 - Calculates text size to fit in region
|
||||
- **`_render_text_in_region`**: Lines 773-876 - Renders text in specified region
|
||||
- **`_draw_bounding_box`**: Lines 878-887 - Draws bounding box around region
|
||||
- **`create_video`**: Lines 889-934 - Creates video with title, artist, and text
|
||||
- **`_handle_existing_image`**: Lines 936-960 - Handles existing image for video
|
||||
- **`_create_background`**: Lines 962-972 - Creates or loads background image
|
||||
- **`_render_all_text`**: Lines 974-1000 - Renders all text elements on image
|
||||
- **`_save_output_files`**: Lines 1002-1017 - Saves output image files and creates video
|
||||
- **`_create_video_from_image`**: Lines 1019-1032 - Creates video from static image
|
||||
- **`create_title_video`**: Lines 1133-1149 - Creates title video
|
||||
- **`create_end_video`**: Lines 1151-1167 - Creates end video
|
||||
|
||||
## Main Processing Methods
|
||||
- **`prep_single_track`**: Lines 1507-1661 - Prepares a single track
|
||||
- **`shutdown`**: Lines 1663-1690 - Handles shutdown signals gracefully
|
||||
- **`process_playlist`**: Lines 1692-1708 - Processes a playlist
|
||||
- **`process_folder`**: Lines 1710-1748 - Processes a folder of audio files
|
||||
- **`process`**: Lines 1750-1782 - Main entry point for processing
|
||||
|
||||
## Concurrency and Error Handling
|
||||
- Signal handling in `prep_single_track`: Lines 1508-1510, 1655-1659
|
||||
- Task management: Lines 1580-1606
|
||||
- Exception handling: Throughout methods
|
||||
|
||||
## External Dependencies
|
||||
- Media handling: yt-dlp.YoutubeDL
|
||||
- Audio processing: audio_separator.separator
|
||||
- Image processing: PIL (Image, ImageDraw, ImageFont)
|
||||
- Lyrics transcription: lyrics_transcriber
|
||||
- Audio manipulation: pydub.AudioSegment
|
||||
- System utilities: os, sys, re, glob, logging, tempfile, shutil, asyncio, signal, time, fcntl, errno, psutil
|
||||
- Others: dotenv, json, datetime
|
||||
+4
-4
@@ -5,7 +5,7 @@ description = "Generate karaoke videos with synchronized lyrics. Handles the ent
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
packages = [{ include = "karaoke_prep" }]
|
||||
packages = [{ include = "karaoke_gen" }]
|
||||
homepage = "https://github.com/karaokenerds/karaoke-gen"
|
||||
repository = "https://github.com/karaokenerds/karaoke-gen"
|
||||
documentation = "https://github.com/karaokenerds/karaoke-gen/blob/main/README.md"
|
||||
@@ -25,7 +25,7 @@ google-auth = "*"
|
||||
google-auth-oauthlib = "*"
|
||||
google-auth-httplib2 = "*"
|
||||
thefuzz = ">=0.22"
|
||||
numpy = "^1"
|
||||
numpy = ">=1"
|
||||
audio-separator = { version = ">=0.21.0", extras = ["cpu"] }
|
||||
lyrics-converter = ">=0.2.1"
|
||||
lyrics-transcriber = ">=0.34"
|
||||
@@ -42,8 +42,8 @@ black = ">=23"
|
||||
poetry = "*"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
karaoke-gen = 'karaoke_prep.utils.gen_cli:main'
|
||||
karaoke-bulk = 'karaoke_prep.utils.bulk_cli:main'
|
||||
karaoke-gen = 'karaoke_gen.cli:main'
|
||||
karaoke-bulk = 'karaoke_gen.cli.bulk_cli:main'
|
||||
|
||||
[tool.black]
|
||||
line-length = 140
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Test package for the karaoke_gen package.
|
||||
"""
|
||||
Binary file not shown.
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
Tests for the core components.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from karaoke_gen.core import ProjectConfig, Track, KaraokeGenError
|
||||
|
||||
|
||||
class TestProjectConfig(unittest.TestCase):
|
||||
"""Test ProjectConfig class."""
|
||||
|
||||
def test_init_with_minimal_args(self):
|
||||
"""Test initialization with minimal arguments."""
|
||||
config = ProjectConfig()
|
||||
|
||||
# Check default values
|
||||
self.assertIsNone(config.artist)
|
||||
self.assertIsNone(config.title)
|
||||
self.assertIsNone(config.input_media)
|
||||
self.assertFalse(config.dry_run)
|
||||
self.assertEqual(config.output_dir, ".")
|
||||
|
||||
def test_init_with_all_args(self):
|
||||
"""Test initialization with all arguments."""
|
||||
logger = MagicMock()
|
||||
|
||||
config = ProjectConfig(
|
||||
artist="Test Artist",
|
||||
title="Test Title",
|
||||
input_media="test.mp3",
|
||||
dry_run=True,
|
||||
logger=logger,
|
||||
output_dir="/tmp",
|
||||
create_track_subfolders=True,
|
||||
)
|
||||
|
||||
# Check values
|
||||
self.assertEqual(config.artist, "Test Artist")
|
||||
self.assertEqual(config.title, "Test Title")
|
||||
self.assertEqual(config.input_media, "test.mp3")
|
||||
self.assertTrue(config.dry_run)
|
||||
self.assertEqual(config.logger, logger)
|
||||
self.assertEqual(config.output_dir, "/tmp")
|
||||
self.assertTrue(config.create_track_subfolders)
|
||||
|
||||
|
||||
class TestTrack(unittest.TestCase):
|
||||
"""Test Track class."""
|
||||
|
||||
def test_init_with_minimal_args(self):
|
||||
"""Test initialization with minimal arguments."""
|
||||
track = Track(artist="Test Artist", title="Test Title")
|
||||
|
||||
# Check values
|
||||
self.assertEqual(track.artist, "Test Artist")
|
||||
self.assertEqual(track.title, "Test Title")
|
||||
self.assertIsNone(track.input_media)
|
||||
|
||||
def test_init_with_all_args(self):
|
||||
"""Test initialization with all arguments."""
|
||||
track = Track(
|
||||
artist="Test Artist",
|
||||
title="Test Title",
|
||||
input_media="test.mp3",
|
||||
input_audio_wav="test.wav",
|
||||
input_still_image="test.jpg",
|
||||
lyrics="Test lyrics",
|
||||
)
|
||||
|
||||
# Check values
|
||||
self.assertEqual(track.artist, "Test Artist")
|
||||
self.assertEqual(track.title, "Test Title")
|
||||
self.assertEqual(track.input_media, "test.mp3")
|
||||
self.assertEqual(track.input_audio_wav, "test.wav")
|
||||
self.assertEqual(track.input_still_image, "test.jpg")
|
||||
self.assertEqual(track.lyrics, "Test lyrics")
|
||||
|
||||
|
||||
class TestKaraokeGenError(unittest.TestCase):
|
||||
"""Test KaraokeGenError class."""
|
||||
|
||||
def test_error_message(self):
|
||||
"""Test error message."""
|
||||
error = KaraokeGenError("Test error")
|
||||
self.assertEqual(str(error), "Test error")
|
||||
|
||||
def test_error_with_cause(self):
|
||||
"""Test error with cause."""
|
||||
cause = ValueError("Original error")
|
||||
error = KaraokeGenError("Test error", cause=cause)
|
||||
self.assertEqual(str(error), "Test error")
|
||||
self.assertEqual(error.__cause__, cause)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -3,7 +3,7 @@
|
||||
import os
|
||||
import json
|
||||
import logging
|
||||
from karaoke_prep.karaoke_prep import KaraokePrep
|
||||
from karaoke_gen.karaoke_gen import KaraokePrep
|
||||
|
||||
# Set up logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
"""
|
||||
Tests for the utility functions.
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from karaoke_gen.utils import (
|
||||
# File utilities
|
||||
sanitize_filename,
|
||||
ensure_directory_exists,
|
||||
file_exists,
|
||||
|
||||
# Path utilities
|
||||
normalize_path,
|
||||
join_paths,
|
||||
get_absolute_path,
|
||||
get_relative_path,
|
||||
get_filename,
|
||||
get_filename_without_extension,
|
||||
get_file_extension,
|
||||
|
||||
# String utilities
|
||||
slugify,
|
||||
truncate_string,
|
||||
extract_artist_and_title,
|
||||
format_duration,
|
||||
format_filesize,
|
||||
)
|
||||
|
||||
|
||||
class TestFileUtils(unittest.TestCase):
|
||||
"""Test file utility functions."""
|
||||
|
||||
def test_sanitize_filename(self):
|
||||
"""Test sanitize_filename function."""
|
||||
# Test with invalid characters
|
||||
self.assertEqual(sanitize_filename("file/with\\invalid:chars"), "file_with_invalid_chars")
|
||||
|
||||
# Test with leading/trailing spaces and dots
|
||||
self.assertEqual(sanitize_filename(" file.with.spaces. "), "file.with.spaces")
|
||||
|
||||
# Test with empty string
|
||||
self.assertEqual(sanitize_filename(""), "unnamed")
|
||||
|
||||
def test_ensure_directory_exists(self):
|
||||
"""Test ensure_directory_exists function."""
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
test_dir = os.path.join(temp_dir, "test_dir")
|
||||
|
||||
# Directory should not exist initially
|
||||
self.assertFalse(os.path.exists(test_dir))
|
||||
|
||||
# Create directory
|
||||
ensure_directory_exists(test_dir)
|
||||
|
||||
# Directory should exist now
|
||||
self.assertTrue(os.path.exists(test_dir))
|
||||
|
||||
# Should not raise exception when called on existing directory
|
||||
ensure_directory_exists(test_dir)
|
||||
|
||||
def test_file_exists(self):
|
||||
"""Test file_exists function."""
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
# Create a test file
|
||||
test_file = os.path.join(temp_dir, "test_file.txt")
|
||||
with open(test_file, "w") as f:
|
||||
f.write("test")
|
||||
|
||||
# Test with existing file
|
||||
self.assertTrue(file_exists(test_file))
|
||||
|
||||
# Test with non-existing file
|
||||
self.assertFalse(file_exists(os.path.join(temp_dir, "non_existing_file.txt")))
|
||||
|
||||
|
||||
class TestPathUtils(unittest.TestCase):
|
||||
"""Test path utility functions."""
|
||||
|
||||
def test_normalize_path(self):
|
||||
"""Test normalize_path function."""
|
||||
# Test with mixed separators
|
||||
self.assertEqual(normalize_path("path/to\\file"), os.path.normpath("path/to/file"))
|
||||
|
||||
def test_join_paths(self):
|
||||
"""Test join_paths function."""
|
||||
# Test joining paths
|
||||
self.assertEqual(join_paths("path", "to", "file"), os.path.join("path", "to", "file"))
|
||||
|
||||
def test_get_absolute_path(self):
|
||||
"""Test get_absolute_path function."""
|
||||
# Test with relative path
|
||||
self.assertEqual(get_absolute_path("."), os.path.abspath("."))
|
||||
|
||||
def test_get_relative_path(self):
|
||||
"""Test get_relative_path function."""
|
||||
# Test with absolute path
|
||||
abs_path = os.path.abspath(".")
|
||||
self.assertEqual(get_relative_path(abs_path, os.path.dirname(abs_path)), os.path.basename(abs_path))
|
||||
|
||||
def test_get_filename(self):
|
||||
"""Test get_filename function."""
|
||||
# Test with path
|
||||
self.assertEqual(get_filename("/path/to/file.txt"), "file.txt")
|
||||
|
||||
def test_get_filename_without_extension(self):
|
||||
"""Test get_filename_without_extension function."""
|
||||
# Test with path and extension
|
||||
self.assertEqual(get_filename_without_extension("/path/to/file.txt"), "file")
|
||||
|
||||
def test_get_file_extension(self):
|
||||
"""Test get_file_extension function."""
|
||||
# Test with path and extension
|
||||
self.assertEqual(get_file_extension("/path/to/file.txt"), ".txt")
|
||||
|
||||
|
||||
class TestStringUtils(unittest.TestCase):
|
||||
"""Test string utility functions."""
|
||||
|
||||
def test_slugify(self):
|
||||
"""Test slugify function."""
|
||||
# Test with spaces and special characters
|
||||
self.assertEqual(slugify("Hello World!"), "hello-world")
|
||||
|
||||
# Test with unicode characters
|
||||
self.assertEqual(slugify("Héllö Wörld"), "hello-world")
|
||||
|
||||
def test_truncate_string(self):
|
||||
"""Test truncate_string function."""
|
||||
# Test with string shorter than max length
|
||||
self.assertEqual(truncate_string("Hello", 10), "Hello")
|
||||
|
||||
# Test with string longer than max length
|
||||
self.assertEqual(truncate_string("Hello World", 8), "Hello...")
|
||||
|
||||
def test_extract_artist_and_title(self):
|
||||
"""Test extract_artist_and_title function."""
|
||||
# Test with standard format
|
||||
self.assertEqual(
|
||||
extract_artist_and_title("Artist - Title.mp3"),
|
||||
{"artist": "Artist", "title": "Title"}
|
||||
)
|
||||
|
||||
# Test with no separator
|
||||
self.assertEqual(
|
||||
extract_artist_and_title("Title.mp3"),
|
||||
{"artist": "", "title": "Title"}
|
||||
)
|
||||
|
||||
def test_format_duration(self):
|
||||
"""Test format_duration function."""
|
||||
# Test with seconds
|
||||
self.assertEqual(format_duration(65), "01:05")
|
||||
|
||||
# Test with minutes
|
||||
self.assertEqual(format_duration(125), "02:05")
|
||||
|
||||
def test_format_filesize(self):
|
||||
"""Test format_filesize function."""
|
||||
# Test with bytes
|
||||
self.assertEqual(format_filesize(500), "500 B")
|
||||
|
||||
# Test with kilobytes
|
||||
self.assertEqual(format_filesize(1500), "1.5 KB")
|
||||
|
||||
# Test with megabytes
|
||||
self.assertEqual(format_filesize(1500000), "1.4 MB")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user