Skip to content

Commit

Permalink
merged preserve original audio with bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Jan 8, 2023
1 parent abedf1c commit 8db3708
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 29 deletions.
3 changes: 0 additions & 3 deletions spotdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def __init__(
restrict: bool = False,
print_errors: bool = False,
sponsor_block: bool = False,
preserve_original_audio: bool = False,
):
"""
Initialize the Spotdl class
Expand Down Expand Up @@ -93,7 +92,6 @@ def __init__(
- restrict: Whether to restrict the filename to ASCII characters.
- print_errors: Whether to print errors on exit.
- sponsor_block: Whether to remove sponsor segments using sponsor block postprocessor.
- preserve_original_audio: Whether to preserve the original audio file.
### Notes
- `search-query` uses the same format as `output`.
Expand Down Expand Up @@ -136,7 +134,6 @@ def __init__(
restrict=restrict,
print_errors=print_errors,
sponsor_block=sponsor_block,
preserve_original_audio=preserve_original_audio,
)

def search(self, query: List[str]) -> List[Song]:
Expand Down
1 change: 0 additions & 1 deletion spotdl/console/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def entry_point():
print_errors=settings["print_errors"],
sponsor_block=settings["sponsor_block"],
playlist_numbering=settings["playlist_numbering"],
preserve_original_audio=settings["preserve_original_audio"],
scan_for_songs=settings["scan_for_songs"],
)

Expand Down
1 change: 0 additions & 1 deletion spotdl/console/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def web(settings: Dict[str, Any]):
print_errors=settings["print_errors"],
sponsor_block=settings["sponsor_block"],
loop=app_state.loop,
preserve_original_audio=settings["preserve_original_audio"],
)

app_state.api = FastAPI(
Expand Down
16 changes: 6 additions & 10 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def __init__(
sponsor_block: bool = False,
loop: Optional[asyncio.AbstractEventLoop] = None,
playlist_numbering: bool = False,
preserve_original_audio: bool = False,
scan_for_songs: bool = False,
):
"""
Expand All @@ -118,7 +117,6 @@ def __init__(
- sponsor_block: Whether to remove sponsor segments using sponsor block postprocessor.
- loop: The event loop to use.
- playlist_numbering: Whether to convert tracks in a playlist into an album.
- preserve_original_audio: Whether to preserve the original audio file.
- scan_for_songs: Whether to scan the base output directory for known songs.
### Notes
Expand Down Expand Up @@ -199,7 +197,6 @@ def __init__(
self.audio_providers_classes = audio_providers_classes
self.progress_handler = ProgressHandler(NAME_TO_LEVEL[log_level], simple_tui)
self.playlist_numbering = playlist_numbering
self.preserve_original_audio = preserve_original_audio
self.scan_for_songs = scan_for_songs

# Gather already present songs
Expand Down Expand Up @@ -549,14 +546,13 @@ def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:

display_progress_tracker.notify_download_complete()

bitrate: Optional[str] = (
self.bitrate if self.bitrate else f"{int(download_info['abr'])}k"
)

# Ignore the bitrate if the preserve original audio
# option is set to true
if self.preserve_original_audio:
# Ignore the bitrate if the bitrate is set to auto for m4a/opus
# or if bitrate is set to disabled
bitrate = self.bitrate
if self.bitrate == "disable":
bitrate = None
elif self.bitrate == "auto":
bitrate = f"{int(download_info['abr'])}k"

success, result = convert(
input_file=temp_file,
Expand Down
17 changes: 5 additions & 12 deletions spotdl/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ def parse_ffmpeg_options(parser: _ArgumentGroup):
parser.add_argument(
"--bitrate",
choices=[
"auto",
"disable",
"8k",
"16k",
"24k",
Expand All @@ -295,6 +297,9 @@ def parse_ffmpeg_options(parser: _ArgumentGroup):
help=(
"The constant/variable bitrate to use for the output file. "
"Values from 0 to 9 are variable bitrates. "
"Auto will use the bitrate of the original file. "
"Disable will disable the bitrate option. "
"(In case of m4a and opus files, this option will skip the conversion)"
),
)

Expand All @@ -305,18 +310,6 @@ def parse_ffmpeg_options(parser: _ArgumentGroup):
help="Additional ffmpeg arguments passed as a string.",
)

# Preserve original audio stream
parser.add_argument(
"--preserve-original-audio",
action="store_const",
const=True,
help=(
"Preserve the original audio stream in case of m4a and opus files. "
"This option might overwrite the bitrate option. "
"Adding additional ffmpeg arguments might make this option useless."
),
)


def parse_output_options(parser: _ArgumentGroup):
"""
Expand Down
1 change: 0 additions & 1 deletion spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def get_config() -> Dict[str, Any]:
"keep_alive": False,
"allowed_origins": None,
"playlist_numbering": False,
"preserve_original_audio": False,
"scan_for_songs": False,
"web_use_output_dir": False,
}
1 change: 0 additions & 1 deletion spotdl/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ def update_settings(
print_errors=settings_cpy["print_errors"],
sponsor_block=settings_cpy["sponsor_block"],
loop=state.loop,
preserve_original_audio=settings_cpy["preserve_original_audio"],
)

return settings_cpy
Expand Down

0 comments on commit 8db3708

Please sign in to comment.