extra-roformers 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, Mohammad Abdul-Tawab.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: extra-roformers
3
+ Version: 0.1.0
4
+ Summary: Extended audio-seprator with yt-dlp and Video support.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: audio-separation,vocal-extract,music-source-separation,yt-dlp,ffmpeg,deep-learning,music-remove
8
+ Author: mohammadmansour200
9
+ Author-email: mohammadamansour03@gmail.com
10
+ Requires-Python: >=3.10
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Dist: audio-separator[gpu] (>=0.30.0)
19
+ Requires-Dist: validators (>=0.35.0)
20
+ Requires-Dist: yt-dlp (>=2026.2.21)
21
+ Description-Content-Type: text/markdown
22
+
23
+ <div align="center">
24
+ <a href="https://pypi.org/project/extra-roformers" target="_blank"><img src="https://img.shields.io/pypi/v/extra-roformers?label=PyPI%20Version&color=limegreen" /></a>
25
+ <a href="https://pypi.org/project/extra-roformers" target="_blank"><img src="https://img.shields.io/pypi/pyversions/extra-roformers?color=limegreen" /></a>
26
+ <a href="https://github.com/mohammadmansour200/extra-roformers/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/pypi/l/extra-roformers?color=limegreen" /></a>
27
+ <a href="https://pepy.tech/project/extra-roformers" target="_blank"><img src="https://static.pepy.tech/badge/extra-roformers" /></a>
28
+ <a href="https://baseet.netlify.app/ai" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" /></a>
29
+ </div>
30
+
31
+ `extra-roformers`: Extended [audio-separator](https://github.com/nomadkaraoke/python-audio-separator/) with yt-dlp media downloading and Video
32
+ Music removal
33
+
34
+ ## Features
35
+
36
+ - 🎧 **Vocal isolation** using Mel-Band RoFormer model
37
+ - 📥 **Media download** from URLs (e.g., YouTube) using `yt-dlp`
38
+ - 📁 Works with both **audio** and **video** files
39
+ - ✅ Local + remote (URL) input support
40
+
41
+ ## Get started
42
+
43
+ *Make sure you have [ffmpeg](https://www.ffmpeg.org/download.html) installed.*
44
+
45
+ ```bash
46
+ sudo apt install ffmpeg
47
+ ```
48
+
49
+ Download package:
50
+ > Requires Python 3.10+
51
+
52
+ ```bash
53
+ pip install extra-roformers
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```bash
59
+ from extra_roformers.separate import extra_separator
60
+
61
+ extra_separator(
62
+ files=[
63
+ "https://www.youtube.com/watch?v=123",
64
+ "local_audio.mp3"
65
+ ],
66
+ download_format="audio", # or "video"
67
+ quality="medium", # "low", "medium", "high"
68
+ output_dir="outputs"
69
+ )
70
+
71
+ ```
72
+
@@ -0,0 +1,49 @@
1
+ <div align="center">
2
+ <a href="https://pypi.org/project/extra-roformers" target="_blank"><img src="https://img.shields.io/pypi/v/extra-roformers?label=PyPI%20Version&color=limegreen" /></a>
3
+ <a href="https://pypi.org/project/extra-roformers" target="_blank"><img src="https://img.shields.io/pypi/pyversions/extra-roformers?color=limegreen" /></a>
4
+ <a href="https://github.com/mohammadmansour200/extra-roformers/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/pypi/l/extra-roformers?color=limegreen" /></a>
5
+ <a href="https://pepy.tech/project/extra-roformers" target="_blank"><img src="https://static.pepy.tech/badge/extra-roformers" /></a>
6
+ <a href="https://baseet.netlify.app/ai" target="_blank"><img src="https://colab.research.google.com/assets/colab-badge.svg" /></a>
7
+ </div>
8
+
9
+ `extra-roformers`: Extended [audio-separator](https://github.com/nomadkaraoke/python-audio-separator/) with yt-dlp media downloading and Video
10
+ Music removal
11
+
12
+ ## Features
13
+
14
+ - 🎧 **Vocal isolation** using Mel-Band RoFormer model
15
+ - 📥 **Media download** from URLs (e.g., YouTube) using `yt-dlp`
16
+ - 📁 Works with both **audio** and **video** files
17
+ - ✅ Local + remote (URL) input support
18
+
19
+ ## Get started
20
+
21
+ *Make sure you have [ffmpeg](https://www.ffmpeg.org/download.html) installed.*
22
+
23
+ ```bash
24
+ sudo apt install ffmpeg
25
+ ```
26
+
27
+ Download package:
28
+ > Requires Python 3.10+
29
+
30
+ ```bash
31
+ pip install extra-roformers
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```bash
37
+ from extra_roformers.separate import extra_separator
38
+
39
+ extra_separator(
40
+ files=[
41
+ "https://www.youtube.com/watch?v=123",
42
+ "local_audio.mp3"
43
+ ],
44
+ download_format="audio", # or "video"
45
+ quality="medium", # "low", "medium", "high"
46
+ output_dir="outputs"
47
+ )
48
+
49
+ ```
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "extra-roformers"
3
+ version = "0.1.0"
4
+ description = "Extended audio-seprator with yt-dlp and Video support."
5
+ license = "MIT License"
6
+ packages = [{ include = "extra_roformers", from = "src" }]
7
+ include = ["LICENSE"]
8
+ readme = "README.md"
9
+ repository = "https://github.com/mohammadmansour200/extra_roformers"
10
+ homepage = "https://baseet.netlify.app/ai"
11
+ keywords = [
12
+ "audio-separation",
13
+ "vocal-extract",
14
+ "music-source-separation",
15
+ "yt-dlp",
16
+ "ffmpeg",
17
+ "deep-learning",
18
+ "music-remove"
19
+ ]
20
+ authors = [
21
+ { name = "mohammadmansour200", email = "mohammadamansour03@gmail.com" }
22
+ ]
23
+ requires-python = ">=3.10"
24
+ dependencies = [
25
+ "yt-dlp>=2026.2.21",
26
+ "validators>=0.35.0",
27
+ "audio-separator[gpu]>=0.30.0",
28
+ ]
29
+
30
+ [build-system]
31
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
32
+ build-backend = "poetry.core.masonry.api"
File without changes
@@ -0,0 +1,50 @@
1
+ import os
2
+ from typing import Any
3
+
4
+ import yt_dlp
5
+
6
+ int_quality = {
7
+ "high": "192",
8
+ "medium": "128",
9
+ "low": "96"
10
+ }
11
+
12
+
13
+ class Downloader:
14
+ def __init__(self, output_dir: str, media_type: str, quality: str):
15
+ self.output_dir = output_dir
16
+ self.media_type = media_type
17
+ self.quality = quality
18
+ self.is_output_video = self.media_type == "video"
19
+
20
+ def download(self, url: str) -> tuple[str, Any]:
21
+ self._initialize_youtube_dl()
22
+
23
+ url_data = self.youtube_dl.extract_info(url, download=True)
24
+
25
+ full_path = self.youtube_dl.prepare_filename(url_data)
26
+
27
+ return full_path
28
+
29
+ def _initialize_youtube_dl(self) -> None:
30
+ self.youtube_dl = yt_dlp.YoutubeDL(self._config())
31
+
32
+ def _config(self) -> dict[str, Any]:
33
+ config = {
34
+ 'ignoreerrors': True,
35
+ 'noplaylist': True,
36
+ 'outtmpl': os.path.join(self.output_dir, '%(id)s.%(ext)s'),
37
+ 'quiet': True,
38
+ 'verbose': False,
39
+ }
40
+
41
+ is_high_quality = self.quality == "high"
42
+
43
+ if not self.is_output_video:
44
+ config['format'] = f'bestaudio[abr>={int_quality[self.quality]}]/bestaudio'
45
+
46
+ if self.is_output_video and not is_high_quality:
47
+ config[
48
+ 'format'] = 'bestvideo[height<=720]+bestaudio' if self.quality == "medium" else 'bestvideo[height<=360]+bestaudio'
49
+
50
+ return config
@@ -0,0 +1,79 @@
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+
5
+
6
+ class FFMPEGUtils:
7
+ """
8
+ FFmpeg utils used in separation.
9
+
10
+ When created, FFMPEG binary path will be checked,
11
+ raising exception if not found. Such path could be inferred using
12
+ `FFMPEG_PATH` environment variable.
13
+ """
14
+
15
+ def __init__(self) -> None:
16
+ """
17
+ Default constructor, ensure FFMPEG binaries are available.
18
+
19
+ Raises:
20
+ ValueError:
21
+ If ffmpeg or ffprobe is not found.
22
+ """
23
+ for binary in ("ffmpeg", "ffprobe"):
24
+ if shutil.which(binary) is None:
25
+ raise Exception("ffmpeg_utils:{} binary not found".format(binary))
26
+
27
+ def replace_video_audio(self, input_video_path: str, input_audio_path: str, final_output_path: str):
28
+ try:
29
+ subprocess.run([
30
+ "ffmpeg",
31
+ "-y",
32
+ "-loglevel", "quiet",
33
+ "-an",
34
+ "-i", input_video_path,
35
+ "-i", input_audio_path,
36
+ "-map", "0:v",
37
+ "-map", "1:a",
38
+ "-c:v", "copy",
39
+ "-c:a", "copy",
40
+ final_output_path, ], check=True)
41
+ except Exception as e:
42
+ raise Exception(
43
+ "ffmpeg_utils:An error occurred with ffmpeg (see ffmpeg output below)\n\n{}".format(
44
+ e
45
+ )
46
+ )
47
+
48
+ def is_video(self, path: str) -> bool:
49
+ try:
50
+ result = subprocess.run(
51
+ ['ffprobe', '-v', 'error', '-select_streams', 'v:0',
52
+ '-show_entries', 'stream=codec_type', '-of', 'csv=p=0', path],
53
+ stdout=subprocess.PIPE,
54
+ stderr=subprocess.PIPE,
55
+ text=True, check=True
56
+ )
57
+ return 'video' in result.stdout
58
+ except Exception as e:
59
+ return False
60
+
61
+ def convert_to_audio_format(self, output_dir: str, output_name: str, audio_format: str):
62
+ processed_demucs_file_path = os.path.join(output_dir, f"{output_name}.wav")
63
+ final_output_file_path = os.path.join(output_dir,
64
+ f"{output_name}.{'mp3' if audio_format is None else audio_format}")
65
+ try:
66
+ subprocess.run([
67
+ "ffmpeg",
68
+ "-y",
69
+ "-loglevel", "quiet",
70
+ "-i", processed_demucs_file_path,
71
+ final_output_file_path
72
+ ]
73
+ , check=True)
74
+ except Exception as e:
75
+ raise Exception(
76
+ "ffmpeg_utils:An error occurred with ffmpeg (see ffmpeg output below)\n\n{}".format(
77
+ e
78
+ )
79
+ )
@@ -0,0 +1,167 @@
1
+ import os
2
+ import shutil
3
+
4
+ import validators
5
+ from audio_separator.separator import Separator
6
+
7
+ from extra_roformers.downloader import Downloader
8
+ from extra_roformers.ffmpeg_utils import FFMPEGUtils
9
+
10
+ video_audio_track_ext_map = {
11
+ ".mp4": "aac",
12
+ ".m4v": "aac",
13
+ ".webm": "opus",
14
+ ".flv": "aac",
15
+ ".mkv": "opus",
16
+ ".mov": "aac",
17
+ ".avi": "mp3",
18
+ ".ts": "aac",
19
+ ".ogg": "vorbis"
20
+ }
21
+
22
+ i18n = {
23
+ "en": {
24
+ "preparing": "Preparing files...",
25
+ "error_no_files": "Please provide files for processing.",
26
+ "saving_video": "Saving video in {path}",
27
+ "saving_audio": "Saving audio in {path}"
28
+ },
29
+ "ar": {
30
+ "preparing": "جاري تحضير الملفات من أجل معالجتها...",
31
+ "error_no_files": "لا يوجد ملفات للمعالجة.",
32
+ "saving_video": "جاري حفظ الفيديو في {path}",
33
+ "saving_audio": "جاري حفظ الصوت في {path}"
34
+ }
35
+ }
36
+
37
+ def get_output_format(input_filename):
38
+ ext = Path(input_filename).suffix.lower()
39
+
40
+ if ext in video_audio_track_ext_map:
41
+ target_format = video_audio_track_ext_map[ext]
42
+ elif ext in ['.wav', '.flac']:
43
+ target_format = ext.replace('.', '')
44
+ else:
45
+ target_format = "mp3"
46
+
47
+ return target_format
48
+
49
+ def extra_separator(
50
+ files: list[str],
51
+ download_format: str,
52
+ quality: str,
53
+ output_dir: str,
54
+ model: str = 'vocals_mel_band_roformer.ckpt',
55
+ lang: str = "ar"
56
+ ):
57
+ """
58
+ Separates vocals from a list of media files (audio/video), using audio-separator, and replaces
59
+ the audio track in video files with the extracted vocals if file was a video.
60
+
61
+ This function supports both local files and remote URLs (e.g., YouTube links). It handles:
62
+ - Downloading remote media using yt-dlp
63
+ - Performing source separation using Demucs (vocal isolation)
64
+ - For video: replacing the original audio with vocals using ffmpeg
65
+ - Cleaning up intermediate files and keeping only the final output
66
+ - Segmented processing in case of low-end devices
67
+
68
+ Parameters:
69
+ files (list[str]): List of file paths or URLs pointing to audio/video files.
70
+ download_format (str): Either "audio" or "video". Determines post-processing behavior.
71
+ quality (str): Quality level for yt-dlp downloading ("high", "low", "medium").
72
+ output_dir (str): Path to directory where final results will be saved.
73
+ model (str): model to be used
74
+ lang (str): Language for logs
75
+
76
+ Notes:
77
+ - Requires `ffmpeg`, and internet access for remote URLs.
78
+ - For audio files, only the isolated vocal track is kept in mp3 format.
79
+ - For video files, a new `.mp4` is generated with vocals replacing original audio.
80
+ - Temporary files are stored in a `tmp/` subfolder inside the output directory and deleted after completion.
81
+
82
+ Example:
83
+ extra_separator(
84
+ files=["https://www.youtube.com/watch?v=123", "local_song.mp3"],
85
+ media_type="audio",
86
+ quality="medium",
87
+ output_dir="output"
88
+ )
89
+ """
90
+ t = i18n[lang]
91
+
92
+ abs_output_dir = os.path.abspath(output_dir)
93
+ temp_output_dir = os.path.join(abs_output_dir, 'tmp')
94
+ separator_output_dir = os.path.join(abs_output_dir, model)
95
+
96
+ # Create directories if they don't exist
97
+ os.makedirs(temp_output_dir, exist_ok=True)
98
+ os.makedirs(separator_output_dir, exist_ok=True)
99
+
100
+ ffmpeg_utils = FFMPEGUtils()
101
+
102
+ file_to_be_processed = []
103
+
104
+ # --- Preparing files for processing ---
105
+ print(t["preparing"])
106
+
107
+ if not files:
108
+ raise Exception(t["error_no_files"])
109
+
110
+ downloader = Downloader(
111
+ output_dir=temp_output_dir,
112
+ media_type=download_format,
113
+ quality=quality
114
+ )
115
+ for index, url in enumerate(files):
116
+ is_url = validators.url(url)
117
+ if is_url:
118
+ downloaded_file_path = downloader.download(url=url)
119
+
120
+ file_to_be_processed.append(downloaded_file_path)
121
+ else:
122
+ file_to_be_processed.append(os.path.abspath(url))
123
+
124
+ # --- Demucs model inference ---
125
+ separator = Separator(
126
+ output_dir=separator_output_dir,
127
+ output_single_stem='Vocals',
128
+ )
129
+ separator.load_model(model)
130
+
131
+ # --- Postprocess ---
132
+ for original_file_path in files_to_be_processed:
133
+ file_path_obj = Path(original_file_path)
134
+ original_file_ext = file_path_obj.suffix.lower()
135
+ vocal_output_name = file_path_obj.stem
136
+
137
+ # --- Separate Audio ---
138
+ target_format = get_output_format(original_file_path)
139
+ separated_files = separator.separate(path, output_format=target_format.upper(), output_filename=f"{path_name_only}_vocals")
140
+
141
+ vocal_file_name = separated_files[0]
142
+ vocal_output_path = os.path.join(separator_output_dir, vocal_file_name)
143
+
144
+ # --- Post-Processing ---
145
+ is_video = ffmpeg_utils.is_video(original_file_path)
146
+
147
+ if is_video:
148
+ print(t["saving_video"].format(path=abs_output_dir))
149
+
150
+ final_video_output_path = os.path.join(abs_output_dir, f"{vocal_output_name}{original_file_ext}")
151
+
152
+ ffmpeg_utils.replace_video_audio(
153
+ input_video_path=original_file_path,
154
+ input_audio_path=vocal_output_path,
155
+ final_output_path=final_video_output_path
156
+ )
157
+ else:
158
+ print(t["saving_video"].format(path=abs_output_dir))
159
+
160
+ final_audio_output_path = os.path.join(abs_output_dir, vocal_file_name)
161
+ shutil.move(vocal_output_path, final_audio_output_path)
162
+
163
+ # --- Cleanup ---
164
+ if os.path.exists(temp_output_dir):
165
+ shutil.rmtree(temp_output_dir)
166
+ if os.path.exists(demucs_output_dir):
167
+ shutil.rmtree(demucs_output_dir)