Skip to content

Commit

Permalink
notebook: yt-dlp option
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Nov 9, 2024
1 parent 750f174 commit bf5a7ee
Showing 1 changed file with 78 additions and 30 deletions.
108 changes: 78 additions & 30 deletions notebook/yohane.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"\n",
"---\n",
"\n",
"Please click the badge below to open the latest version of the notebook:\n",
"Click the badge below to open the latest version of the notebook:\n",
"\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/Japan7/yohane/blob/main/notebook/yohane.ipynb\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
"</a>\n",
"\n",
"---\n",
"\n",
"**Before proceeding, change your runtime type to GPU (Toolbar > Runtime > Change runtime type > T4 GPU).**\n"
"**Before proceeding, change your runtime type to T4 GPU (Toolbar > Runtime > Change runtime type > T4 GPU).**\n"
]
},
{
Expand Down Expand Up @@ -61,17 +61,12 @@
"uv pip install --system git+$REPO_URL@$LATEST_TAG"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Restart the runtime if prompted."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"id": "l8b80QOHWjHQ"
},
"outputs": [],
"source": [
"!pip3 show yohane"
Expand All @@ -85,7 +80,7 @@
"source": [
"## Parameters\n",
"\n",
"The next cells will set the parameters for the yohane pipeline."
"The next cells will set the parameters for the yohane pipeline.\n"
]
},
{
Expand All @@ -96,16 +91,55 @@
},
"outputs": [],
"source": [
"# @title Song { display-mode: \"form\" }\n",
"# @markdown Run this cell and use the form below to **upload your song**.\n",
"# @title Song Upload\n",
"# @markdown Run this cell to **upload your song** using the form below.\n",
"#\n",
"# @markdown It can be either an audio or video file.\n",
"# @markdown Accepted formats: audio or video files.\n",
"#\n",
"# @markdown **If it fails, try another browser or upload your file manually in the Files section of the left side bar.**\n",
"# @markdown **Note**: If the upload fails, try using a different browser or upload the file manually in the Files section on the left sidebar.\n",
"\n",
"from google.colab import files\n",
"\n",
"files.upload_file(\"song\")"
"upload = files.upload()\n",
"for file in upload:\n",
" song_filename = file\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2Kg99ykCWjHR"
},
"outputs": [],
"source": [
"# @markdown **If you uploaded the file manually, enter the song filename here.**\n",
"\n",
"song_filename_override = \"\" # @param {type:\"string\"}\n",
"song_filename = song_filename_override or song_filename"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sp0sHZPCWjHS"
},
"outputs": [],
"source": [
"# @title Song Download (yt-dlp)\n",
"# @markdown **Enter** the remote URL below, **then execute** this cell to download the song.\n",
"\n",
"!uv pip install -q --system yt-dlp[default]\n",
"\n",
"from yt_dlp import YoutubeDL\n",
"\n",
"song_url = \"\" # @param {type:\"string\"}\n",
"\n",
"with YoutubeDL({\"format_sort\": [\"res:1080\", \"vcodec:h264\", \"acodec:aac\"]}) as ydl:\n",
" info = ydl.extract_info(song_url)\n",
" song_filename = ydl.prepare_filename(info)"
]
},
{
Expand All @@ -117,7 +151,7 @@
"outputs": [],
"source": [
"# @title Lyrics { display-mode: \"form\", run: \"auto\" }\n",
"# @markdown Run this cell and **paste your lyrics** in the box below.\n",
"# @markdown Run this cell, then **paste your lyrics** in the box below.\n",
"\n",
"from IPython.display import display\n",
"from ipywidgets import Layout, Textarea\n",
Expand All @@ -135,10 +169,10 @@
"outputs": [],
"source": [
"# @title Source Separator { display-mode: \"form\", run: \"auto\" }\n",
"# @markdown Run this cell and select the desired **Source Separator**:\n",
"# @markdown - `VocalRemoverSeparator` is based on the [`vocal-remover`](https://github.com/tsurumeso/vocal-remover) library. Take this one if you don't know what to choose.\n",
"# @markdown - `HybridDemucsSeparator` uses `torchaudio`'s [Hybrid Demucs model](https://pytorch.org/audio/2.1.0/tutorials/hybrid_demucs_tutorial.html) which is faster but less aggressive.\n",
"# @markdown - `None` if you don't care and want to skip the vocals extraction step.\n",
"# @markdown Run this cell and select a **Source Separator**:\n",
"# @markdown - **VocalRemoverSeparator**: Based on the [`vocal-remover`](https://github.com/tsurumeso/vocal-remover) library. Choose this if you're unsure.\n",
"# @markdown - **HybridDemucsSeparator**: Uses `torchaudio`'s [Hybrid Demucs model](https://pytorch.org/audio/2.1.0/tutorials/hybrid_demucs_tutorial.html), which is faster but less aggressive.\n",
"# @markdown - **None**: Skips the vocal extraction step if it's not needed.\n",
"\n",
"from yohane.audio import VocalRemoverSeparator, HybridDemucsSeparator\n",
"\n",
Expand Down Expand Up @@ -166,18 +200,17 @@
"outputs": [],
"source": [
"# @title Generate\n",
"# @markdown **Replace the song filename here if you uploaded it manually**\n",
"\n",
"import logging\n",
"from pathlib import Path\n",
"from yohane import Yohane\n",
"\n",
"logging.basicConfig(level=\"INFO\", force=True)\n",
"\n",
"song_filename = \"song\" # @param {type:\"string\"}\n",
"song_path = Path(song_filename)\n",
"\n",
"yohane = Yohane(separator)\n",
"yohane.load_song(Path(song_filename))\n",
"yohane.load_song(song_path)\n",
"yohane.load_lyrics(lyrics_area.value)\n",
"yohane.extract_vocals()\n",
"yohane.force_align()\n",
Expand All @@ -192,12 +225,26 @@
},
"outputs": [],
"source": [
"# @title Save and download\n",
"# @title Save and download karaoke file\n",
"\n",
"from google.colab import files\n",
"\n",
"subs.save(\"karaoke.ass\")\n",
"files.download(\"karaoke.ass\")"
"subs_path = song_path.with_suffix('.ass')\n",
"subs.save(subs_path)\n",
"files.download(subs_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Qy3iC4WFYuc9"
},
"outputs": [],
"source": [
"# @title Download song file\n",
"\n",
"files.download(song_path)"
]
},
{
Expand All @@ -206,7 +253,7 @@
"id": "YVB0lS8ENJvo"
},
"source": [
"The karaoke should have been downloaded. If not, open Files in the left side bar and look for `karaoke.ass`.\n",
"The karaoke file should have downloaded. If not, open Files in the left sidebar and look for `*.ass`.\n",
"\n",
"**Next recommended steps in Aegisub:**\n",
"\n",
Expand All @@ -231,12 +278,13 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11.6"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit bf5a7ee

Please sign in to comment.