mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-21 05:18:08 +09:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce6f9ee446 |
No files matched your search
BIN
Binary file not shown.
BIN
Binary file not shown.
+40
@@ -0,0 +1,40 @@
|
||||
|
||||
Well it's a big, big city and it's always the same
|
||||
Can never be too pretty, tell me your name
|
||||
Is it out of line if I were simply bold and say "Would you be mine?"
|
||||
Because I may be a beggar and you may be the queen
|
||||
I know I may be on a downer, I'm still ready to dream
|
||||
Though it's three o'clock, the time is just the time it takes for you to talk
|
||||
|
||||
|
||||
So if you're lonely, why'd you say you're not lonely?
|
||||
Oh you're a silly girl, I know I heard it so
|
||||
It's just like you to come and go
|
||||
And know me, no, you don't even know me
|
||||
You're so sweet to try, oh my, you caught my eye
|
||||
A girl like you is just irresistible
|
||||
|
||||
|
||||
Well it's a big, big city and the lights are all out
|
||||
But it's as much as I can do you know to figure you out
|
||||
And I must confess, my heart's in broken pieces and my head's a mess
|
||||
And it's four in the morning and I'm walking along
|
||||
Beside the ghost of every drinker here who's ever done wrong
|
||||
And it's you, woo-hoo, that's got me going crazy for the things you do
|
||||
|
||||
|
||||
So if you're crazy, I don't care, you amaze me
|
||||
But you're a stupid girl, oh me, oh my, you talk
|
||||
I die, you smile, you laugh, I cry
|
||||
And only, a girl like you could be lonely
|
||||
And it's a crying shame, if you would think the same
|
||||
A boy like me is just irresistible
|
||||
|
||||
|
||||
|
||||
So if you're lonely, why'd you say you're not lonely?
|
||||
Oh you're a silly girl, I know I heard it so
|
||||
It's just like you to come and go
|
||||
And know me, no, you don't even know me
|
||||
You're so sweet to try, oh my, you caught my eye
|
||||
A girl like you is just irresistible
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
|
After Width: | Height: | Size: 177 KiB |
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -81,22 +81,31 @@ class KaraokePrep:
|
||||
self.logger.warning(f"No YouTube results found for query: {query}")
|
||||
return None
|
||||
|
||||
def download_audio(self, youtube_id, filename):
|
||||
def download_video(self, youtube_id, output_filename_no_extension):
|
||||
self.logger.debug(f"Downloading YouTube video {youtube_id} to filename {output_filename_no_extension} + (as yet) unknown extension")
|
||||
ydl_opts = {
|
||||
"format": "ba",
|
||||
"postprocessors": [
|
||||
{
|
||||
"key": "FFmpegExtractAudio",
|
||||
"preferredcodec": "wav",
|
||||
"preferredquality": "192",
|
||||
}
|
||||
],
|
||||
"outtmpl": f"{filename}",
|
||||
"format": "bv*+ba/b", # if a combined video + audio format is better than the best video-only format use the combined format
|
||||
"outtmpl": f"{output_filename_no_extension}",
|
||||
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
|
||||
}
|
||||
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as youtube_dl_instance:
|
||||
youtube_dl_instance.download([f"https://www.youtube.com/watch?v={youtube_id}"])
|
||||
self.logger.warn(f"Download finished, assuming hard-coded webm extension (!) and returning this filename")
|
||||
# TODO: Replace hard-coded webm extension with the actual extension of the downloaded file using yt-dlp hooks / event callback
|
||||
return output_filename_no_extension + ".webm"
|
||||
|
||||
def extract_still_image_from_video(self, input_filename, output_filename_no_extension):
|
||||
output_filename = output_filename_no_extension + ".png"
|
||||
self.logger.debug(f"Extracting still image from position 30s YouTube video to {output_filename}")
|
||||
os.system(f'ffmpeg -i "{input_filename}" -ss 00:00:30 -vframes 1 "{output_filename}"')
|
||||
return output_filename
|
||||
|
||||
def convert_to_wav(self, input_filename, output_filename_no_extension):
|
||||
output_filename = output_filename_no_extension + ".wav"
|
||||
self.logger.debug(f"Converting {input_filename} to WAV file {output_filename}")
|
||||
os.system(f'ffmpeg -i "{input_filename}" "{output_filename}"')
|
||||
return output_filename
|
||||
|
||||
def write_lyrics_from_genius(self, artist, title, filename):
|
||||
genius = lyricsgenius.Genius(os.environ["GENIUS_API_TOKEN"])
|
||||
@@ -139,7 +148,9 @@ class KaraokePrep:
|
||||
|
||||
self.logger.debug(f"audio_file is valid file: {audio_file}")
|
||||
|
||||
self.logger.debug(f"instantiating Separator with model_name: {model_name} instrumental_path: {instrumental_path} and output_format: {self.output_format}")
|
||||
self.logger.debug(
|
||||
f"instantiating Separator with model_name: {model_name} instrumental_path: {instrumental_path} and output_format: {self.output_format}"
|
||||
)
|
||||
separator = Separator(
|
||||
audio_file,
|
||||
log_level=self.log_level,
|
||||
@@ -180,13 +191,25 @@ class KaraokePrep:
|
||||
"title": title,
|
||||
}
|
||||
|
||||
yt_filename_pattern = os.path.join(track_output_dir, f"{artist_title} (YouTube *.wav")
|
||||
youtube_audio_files = glob.glob(yt_filename_pattern)
|
||||
youtube_audio_file = None
|
||||
yt_webm_filename_pattern = os.path.join(track_output_dir, f"{artist_title} (YouTube *.webm")
|
||||
yt_webm_glob = glob.glob(yt_webm_filename_pattern)
|
||||
|
||||
if youtube_audio_files:
|
||||
youtube_audio_file = youtube_audio_files[0]
|
||||
self.logger.debug(f"Youtube audio already exists, skipping download: {youtube_audio_file}")
|
||||
yt_png_filename_pattern = os.path.join(track_output_dir, f"{artist_title} (YouTube *.png")
|
||||
yt_png_glob = glob.glob(yt_png_filename_pattern)
|
||||
|
||||
yt_wav_filename_pattern = os.path.join(track_output_dir, f"{artist_title} (YouTube *.wav")
|
||||
yt_wav_glob = glob.glob(yt_wav_filename_pattern)
|
||||
|
||||
processed_track["youtube_video"] = None
|
||||
processed_track["youtube_still_image"] = None
|
||||
processed_track["youtube_audio"] = None
|
||||
|
||||
if yt_webm_glob and yt_png_glob and yt_wav_glob:
|
||||
processed_track["youtube_video"] = yt_webm_glob[0]
|
||||
processed_track["youtube_still_image"] = yt_png_glob[0]
|
||||
processed_track["youtube_audio"] = yt_wav_glob[0]
|
||||
|
||||
self.logger.debug(f"YouTube output files already exist, skipping download: {processed_track['youtube_video']} + .wav + .png")
|
||||
else:
|
||||
if self.url is None:
|
||||
self.logger.warn(f"No URL specified - the top result from YouTube will be used.")
|
||||
@@ -197,16 +220,21 @@ class KaraokePrep:
|
||||
self.logger.info("Parsing YouTube video ID from URL...")
|
||||
youtube_id = self.url.split("watch?v=")[1]
|
||||
if youtube_id:
|
||||
youtube_audio_file = os.path.join(track_output_dir, f"{artist_title} (YouTube {youtube_id})")
|
||||
output_filename_no_extension = os.path.join(track_output_dir, f"{artist_title} (YouTube {youtube_id})")
|
||||
|
||||
self.logger.info("Downloading original audio from YouTube to filename {original_audio_filename}")
|
||||
self.download_audio(youtube_id, youtube_audio_file)
|
||||
youtube_audio_file = youtube_audio_file + ".wav"
|
||||
self.logger.info("Downloading original video from YouTube...")
|
||||
processed_track["youtube_video"] = self.download_video(youtube_id, output_filename_no_extension)
|
||||
|
||||
self.logger.info("Extracting still image from downloaded video...")
|
||||
processed_track["youtube_still_image"] = self.extract_still_image_from_video(
|
||||
processed_track["youtube_video"], output_filename_no_extension
|
||||
)
|
||||
|
||||
self.logger.info("Converting downloaded video to WAV for audio processing...")
|
||||
processed_track["youtube_audio"] = self.convert_to_wav(processed_track["youtube_video"], output_filename_no_extension)
|
||||
else:
|
||||
self.logger.warning(f"Skipping {title} by {artist} due to missing YouTube ID.")
|
||||
|
||||
processed_track["youtube_audio"] = youtube_audio_file
|
||||
|
||||
lyrics_file = os.path.join(track_output_dir, f"{artist_title} (Lyrics).txt")
|
||||
if os.path.exists(lyrics_file):
|
||||
self.logger.debug(f"Lyrics file already exists, skipping fetch: {lyrics_file}")
|
||||
|
||||
@@ -120,7 +120,9 @@ def main():
|
||||
|
||||
logger.info(f"")
|
||||
logger.info(f"Track: {track['artist']} - {track['title']}")
|
||||
logger.info(f" YouTube Video: {track['youtube_video']}")
|
||||
logger.info(f" YouTube Audio: {track['youtube_audio']}")
|
||||
logger.info(f" YouTube Still Image: {track['youtube_still_image']}")
|
||||
logger.info(f" Lyrics: {track['lyrics']}")
|
||||
logger.info(f" Instrumental: {track['instrumental_audio']}")
|
||||
logger.info(f" Vocals: {track['vocals_audio']}")
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-prep"
|
||||
version = "0.1.8"
|
||||
version = "0.2.0"
|
||||
description = "Prepare for karaoke video creation, by downloading audio and lyrics for a specified song."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user