Compare commits

...
10 Commits
6 changed files with 1080 additions and 952 deletions

No files matched your search

+24 -24
View File
@@ -18,34 +18,34 @@ jobs:
gh-token: ${{ secrets.GITHUB_TOKEN }}
parse-changelog: false
build-windows:
runs-on: windows-latest
# build-windows:
# runs-on: windows-latest
steps:
- uses: actions/checkout@v2
# steps:
# - uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
# - 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: Install dependencies with Poetry
# run: |
# pip install poetry
# poetry install
- name: Download ffmpeg binary
run: python platform/download_ffmpeg.py
# - name: Download ffmpeg binary
# run: python platform/download_ffmpeg.py
- name: Build EXE with PyInstaller
run: poetry run pyinstaller karaoke-prep.spec
# - name: Build EXE with PyInstaller
# run: poetry run pyinstaller karaoke-prep.spec
- name: Upload EXE as Artifact
uses: actions/upload-artifact@v2
with:
name: karaoke-prep-windows
path: |
build/
*.exe
*/*.exe
# - name: Upload EXE as Artifact
# uses: actions/upload-artifact@v2
# with:
# name: karaoke-prep-windows
# path: |
# build/
# *.exe
# */*.exe
@@ -14,6 +14,8 @@ from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.http import MediaFileUpload
import subprocess
import time
class KaraokeFinalise:
@@ -28,11 +30,13 @@ class KaraokeFinalise:
enable_txt=False,
brand_prefix=None,
organised_dir=None,
organised_dir_rclone_root=None,
public_share_dir=None,
youtube_client_secrets_file=None,
youtube_description_file=None,
rclone_destination=None,
discord_webhook_url=None,
non_interactive=False,
):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(log_level)
@@ -67,6 +71,8 @@ class KaraokeFinalise:
self.brand_prefix = brand_prefix
self.organised_dir = organised_dir
self.organised_dir_rclone_root = organised_dir_rclone_root
self.public_share_dir = public_share_dir
self.youtube_client_secrets_file = youtube_client_secrets_file
self.youtube_description_file = youtube_description_file
@@ -82,6 +88,7 @@ class KaraokeFinalise:
self.public_share_rclone_enabled = False
self.skip_notifications = False
self.non_interactive = non_interactive
self.suffixes = {
"title_mov": " (Title).mov",
@@ -98,13 +105,16 @@ class KaraokeFinalise:
"final_karaoke_mp4": " (Final Karaoke).mp4",
"final_karaoke_cdg_zip": " (Final Karaoke CDG).zip",
"final_karaoke_txt_zip": " (Final Karaoke TXT).zip",
"final_karaoke_720p_mp4": " (Final Karaoke 720p).mp4",
}
self.youtube_url_prefix = "https://www.youtube.com/watch?v="
self.youtube_url = None
self.brand_code = None
self.new_brand_code_dir = None
self.new_brand_code_dir_path = None
self.brand_code_dir_sharing_link = None
def check_input_files_exist(self, base_name, with_vocals_file, instrumental_audio_file):
self.logger.info(f"Checking required input files exist...")
@@ -149,6 +159,7 @@ class KaraokeFinalise:
"karaoke_mov": f"{base_name}{self.suffixes['karaoke_mov']}",
"with_vocals_mp4": f"{base_name}{self.suffixes['with_vocals_mp4']}",
"final_karaoke_mp4": f"{base_name}{self.suffixes['final_karaoke_mp4']}",
"final_karaoke_720p_mp4": f"{base_name}{self.suffixes['final_karaoke_720p_mp4']}",
}
if self.enable_cdg:
@@ -166,6 +177,10 @@ class KaraokeFinalise:
raise Exception(exit_message)
def prompt_user_bool(self, prompt_message, allow_empty=False):
if self.non_interactive:
self.logger.warning(f"Non-interactive mode, responding True for prompt: {prompt_message}")
return True
options_string = "[y]/n" if allow_empty else "y/[n]"
accept_responses = ["y", "yes"]
if allow_empty:
@@ -550,7 +565,15 @@ class KaraokeFinalise:
env_mov_input = f"-i {end_mov_file}"
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]"'
join_ffmpeg_command = f'{self.ffmpeg_base_command} -i {title_mov_file} -i {karaoke_mov_file} {env_mov_input} {ffmpeg_filter} -map "[outv]" -map "[outa]" -c:v libx264 -c:a aac_at -q:a 14 {output_final_mp4_file}'
aac_codec = "libfdk_aac"
# Check if aac_at codec is available
codec_check_command = f"{self.ffmpeg_base_command} -codecs"
result = os.popen(codec_check_command).read()
if "aac_at" in result:
aac_codec = "aac_at"
join_ffmpeg_command = f'{self.ffmpeg_base_command} -i {title_mov_file} -i {karaoke_mov_file} {env_mov_input} {ffmpeg_filter} -map "[outv]" -map "[outa]" -c:v libx264 -c:a {aac_codec} -q:a 14 {output_final_mp4_file}'
self.logger.debug(f"Running command: {join_ffmpeg_command}")
self.execute_command(join_ffmpeg_command, "Joining title and instrumental videos")
@@ -620,10 +643,20 @@ class KaraokeFinalise:
self.logger.info(f"TXT ZIP file created: {output_files['final_karaoke_txt_zip']}")
def encode_720p_version(self, input_file, output_file):
ffmpeg_command = (
f'{self.ffmpeg_base_command} -i "{input_file}" '
f'-c:v libx264 -vf "scale=1280:720" -b:v 200k -preset medium -tune animation '
f'-c:a copy "{output_file}"'
)
self.execute_command(ffmpeg_command, "Encoding 720p version of the final video")
def move_files_to_brand_code_folder(self, brand_code, artist, title, output_files):
self.logger.info(f"Moving files to new brand-prefixed directory...")
self.new_brand_code_dir_path = os.path.join(self.organised_dir, f"{brand_code} - {artist} - {title}")
self.new_brand_code_dir = f"{brand_code} - {artist} - {title}"
self.new_brand_code_dir_path = os.path.join(self.organised_dir, self.new_brand_code_dir)
self.prompt_user_confirmation_or_raise_exception(
f"Move files to new brand-prefixed directory {self.new_brand_code_dir_path} and delete current dir?",
@@ -641,15 +674,18 @@ class KaraokeFinalise:
os.rename(orig_dir, self.new_brand_code_dir_path)
def copy_final_files_to_public_share_dirs(self, brand_code, base_name, output_files):
self.logger.info(f"Copying final MP4 and ZIP to public share directory...")
self.logger.info(f"Copying final MP4, 720p MP4, and ZIP to public share directory...")
# Validate public_share_dir is a valid folder with MP4 and CDG subdirectories
# Validate public_share_dir is a valid folder with MP4, MP4-720p, and CDG subdirectories
if not os.path.isdir(self.public_share_dir):
raise Exception(f"Public share directory does not exist: {self.public_share_dir}")
if not os.path.isdir(os.path.join(self.public_share_dir, "MP4")):
raise Exception(f"Public share directory does not contain MP4 subdirectory: {self.public_share_dir}")
if not os.path.isdir(os.path.join(self.public_share_dir, "MP4-720p")):
raise Exception(f"Public share directory does not contain MP4-720p subdirectory: {self.public_share_dir}")
if not os.path.isdir(os.path.join(self.public_share_dir, "CDG")):
raise Exception(f"Public share directory does not contain CDG subdirectory: {self.public_share_dir}")
@@ -657,17 +693,23 @@ class KaraokeFinalise:
raise Exception(f"New track prefix was not set, refusing to copy to public share directory")
dest_mp4_dir = os.path.join(self.public_share_dir, "MP4")
dest_720p_dir = os.path.join(self.public_share_dir, "MP4-720p")
dest_cdg_dir = os.path.join(self.public_share_dir, "CDG")
os.makedirs(dest_mp4_dir, exist_ok=True)
os.makedirs(dest_720p_dir, exist_ok=True)
os.makedirs(dest_cdg_dir, exist_ok=True)
dest_mp4_file = os.path.join(dest_mp4_dir, f"{brand_code} - {base_name}.mp4")
dest_720p_mp4_file = os.path.join(dest_720p_dir, f"{brand_code} - {base_name}.mp4")
dest_zip_file = os.path.join(dest_cdg_dir, f"{brand_code} - {base_name}.zip")
if self.dry_run:
self.logger.info(f"DRY RUN: Would copy final MP4 and ZIP to {dest_mp4_file} + .cdg")
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}"
)
else:
shutil.copy2(output_files["final_karaoke_mp4"], dest_mp4_file)
shutil.copy2(output_files["final_karaoke_720p_mp4"], dest_720p_mp4_file)
shutil.copy2(output_files["final_karaoke_cdg_zip"], dest_zip_file)
self.logger.info(f"Copied final files to public share directory")
@@ -700,6 +742,31 @@ class KaraokeFinalise:
discord_message = f"New upload: {self.youtube_url}"
self.post_discord_message(discord_message, self.discord_webhook_url)
def generate_organised_folder_sharing_link(self):
self.logger.info(f"Getting Organised Folder sharing link for new brand code directory...")
rclone_dest = f"{self.organised_dir_rclone_root}/{self.new_brand_code_dir}"
rclone_link_cmd = f"rclone link {shlex.quote(rclone_dest)}"
if self.dry_run:
self.logger.info(f"DRY RUN: Would get sharing link with: {rclone_link_cmd}")
return "https://file-sharing-service.com/example"
# Add a 5-second delay to allow dropbox to index the folder before generating a link
self.logger.info("Waiting 5 seconds before generating link...")
time.sleep(5)
try:
self.logger.info(f"Running command: {rclone_link_cmd}")
result = subprocess.run(rclone_link_cmd, shell=True, check=True, capture_output=True, text=True)
self.brand_code_dir_sharing_link = result.stdout.strip()
self.logger.info(f"Got organised folder sharing link: {self.brand_code_dir_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}")
self.logger.error(f"Full exception: {e}")
def execute_optional_features(self, artist, title, base_name, input_files, output_files):
self.logger.info(f"Executing optional features...")
@@ -728,6 +795,8 @@ class KaraokeFinalise:
self.move_files_to_brand_code_folder(self.brand_code, artist, title, output_files)
self.generate_organised_folder_sharing_link()
def process(self):
if self.dry_run:
self.logger.warning("Dry run enabled. No actions will be performed.")
@@ -750,6 +819,7 @@ class KaraokeFinalise:
self.create_txt_zip_file(input_files, output_files)
self.remux_and_encode_output_video_files(with_vocals_file, input_files, output_files)
self.encode_720p_version(output_files["final_karaoke_mp4"], output_files["final_karaoke_720p_mp4"])
self.execute_optional_features(artist, title, base_name, input_files, output_files)
@@ -759,9 +829,11 @@ class KaraokeFinalise:
"video_with_vocals": output_files["with_vocals_mp4"],
"video_with_instrumental": output_files["karaoke_mov"],
"final_video": output_files["final_karaoke_mp4"],
"final_video_720p": output_files["final_karaoke_720p_mp4"],
"youtube_url": self.youtube_url,
"brand_code": self.brand_code,
"new_brand_code_dir_path": self.new_brand_code_dir_path,
"brand_code_dir_sharing_link": self.brand_code_dir_sharing_link,
}
if self.enable_cdg:
+12 -1
View File
@@ -71,6 +71,12 @@ def main():
help="Optional: Target directory where the processed folder will be moved after finalisation. Example: --organised_dir='/path/to/Tracks-Organized'",
)
parser.add_argument(
"--organised_dir_rclone_root",
default=None,
help="Optional: Rclone path which maps to your organised_dir, to generate a sharing link after adding files to it. Example: --organised_dir_rclone_root='andrewdropbox:Media/Karaoke/Tracks-Organized'",
)
parser.add_argument(
"--public_share_dir",
default=None,
@@ -118,6 +124,7 @@ def main():
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,
@@ -144,10 +151,14 @@ def main():
logger.info(f" Final TXT+MP3 ZIP: {track['final_karaoke_txt_zip']}")
logger.info(f" Final Video with Title: {track['final_video']}")
logger.info(f" YouTube URL: {track['youtube_url']}")
logger.info(f" Final Video 720p: {track['final_video_720p']}")
logger.info(f" Brand Code: {track['brand_code']}")
logger.info(f" New Brand Code Directory: {track['new_brand_code_dir_path']}")
logger.info(f" YouTube URL: {track['youtube_url']}")
logger.info(f" Folder Sharing Link: {track['brand_code_dir_sharing_link']}")
if __name__ == "__main__":
main()
+1
View File
@@ -60,6 +60,7 @@ def main():
nargs="+",
default=[
"UVR_MDXNET_KARA_2.onnx",
"mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt",
"2_HP-UVR.pth",
"model_bs_roformer_ep_317_sdr_12.9755.yaml",
"MDX23C-8KFFT-InstVoc_HQ_2.ckpt",
Generated
+964 -920
View File
File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-prep"
version = "0.22.2"
version = "0.24.0"
description = "Prepare for karaoke video creation, by downloading audio and lyrics for a specified song or playlist from youtube and separating audio stems. After syncing, finalise the video with a title screen!"
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
license = "MIT"
@@ -26,7 +26,7 @@ google-auth-httplib2 = "*"
pyperclip = ">=1.8"
thefuzz = ">=0.22"
numpy = "^1"
audio-separator = { version = ">=0.17.5", extras = ["cpu"] }
audio-separator = { version = ">=0.21.0", extras = ["cpu"] }
lyrics-converter = ">=0.2.1"
[tool.poetry.group.dev.dependencies]