added convertion of the audio itself vie ffmpeg
This commit is contained in:
parent
4efef86793
commit
36ee456612
@ -12,3 +12,4 @@ SQLAlchemy
|
||||
setuptools~=60.2.0
|
||||
tqdm~=4.65.0
|
||||
peewee~=3.15.4
|
||||
ffmpeg-python~=0.2.0
|
@ -43,6 +43,7 @@ def download_audio():
|
||||
|
||||
pages.Musify.download_song(song)
|
||||
|
||||
|
||||
def real_download():
|
||||
search = pages.Search()
|
||||
search.search_url("https://musify.club/release/children-of-the-night-2018-1079829")
|
||||
@ -50,4 +51,4 @@ def real_download():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
music_kraken.cli(genre="test")
|
||||
music_kraken.cli(genre="dsbm")
|
||||
|
@ -2,37 +2,33 @@ from pathlib import Path
|
||||
|
||||
import ffmpeg
|
||||
|
||||
from ..utils.shared import BITRATE, CODEX_LOGGER as LOGGER
|
||||
from ..utils.shared import BITRATE, AUDIO_FORMAT, CODEX_LOGGER as LOGGER
|
||||
from ..objects import Target
|
||||
|
||||
def correct_codec(target: Target, bitrate: int = BITRATE):
|
||||
|
||||
def correct_codec(target: Target, bitrate_kb: int = BITRATE, audio_format: str = AUDIO_FORMAT):
|
||||
if not target.exists:
|
||||
LOGGER.warning(f"Target doesn't exist: {target.file_path}")
|
||||
return
|
||||
|
||||
output_file = Path(str(target.file_path) + ".out")
|
||||
bitrate_b = int(bitrate_kb / 1024)
|
||||
|
||||
# https://www.audioranger.com/audio-formats.php
|
||||
# https://kkroening.github.io/ffmpeg-python/index.html?highlight=audio#ffmpeg.output
|
||||
|
||||
ffmpeg_out = ffmpeg.output(
|
||||
ffmpeg.input(target.file_path),
|
||||
output_file,
|
||||
audio_bitrate=bitrate,
|
||||
format="mp3"
|
||||
).run()
|
||||
"""
|
||||
|
||||
in_file = ffmpeg.input('input.mp4')
|
||||
overlay_file = ffmpeg.input('overlay.png')
|
||||
(
|
||||
ffmpeg
|
||||
.concat(
|
||||
in_file.trim(start_frame=10, end_frame=20),
|
||||
in_file.trim(start_frame=30, end_frame=40),
|
||||
output_target = Target(
|
||||
path=target._path,
|
||||
file=str(target._file) + "." + audio_format
|
||||
)
|
||||
.overlay(overlay_file.hflip())
|
||||
.drawbox(50, 50, 120, 120, color='red', thickness=5)
|
||||
.output('out.mp4')
|
||||
.run()
|
||||
)
|
||||
"""
|
||||
|
||||
stream = ffmpeg.input(target.file_path)
|
||||
stream = stream.audio
|
||||
stream = ffmpeg.output(
|
||||
stream,
|
||||
str(output_target.file_path),
|
||||
audio_bitrate=bitrate_b,
|
||||
format=audio_format
|
||||
)
|
||||
out, err = ffmpeg.run(stream, quiet=True, overwrite_output=True)
|
||||
if err != "":
|
||||
LOGGER.debug(err)
|
||||
|
||||
output_target.copy_content(target)
|
||||
output_target.file_path.unlink()
|
||||
|
@ -21,7 +21,7 @@ from ..objects import (
|
||||
Label,
|
||||
AlbumType
|
||||
)
|
||||
from ..audio import write_metadata_to_target
|
||||
from ..audio import write_metadata_to_target, correct_codec
|
||||
from ..utils import shared
|
||||
|
||||
|
||||
@ -541,6 +541,7 @@ class Page:
|
||||
|
||||
@classmethod
|
||||
def _post_process_targets(cls, song: Song, temp_target: Target) -> DownloadResult:
|
||||
correct_codec(temp_target)
|
||||
write_metadata_to_target(song.metadata, temp_target)
|
||||
|
||||
r = DownloadResult()
|
||||
|
@ -19,6 +19,7 @@ class DefaultTarget:
|
||||
album: str = DEFAULT_VALUES["album"]
|
||||
album_type: str = DEFAULT_VALUES["album_type"]
|
||||
song: str = DEFAULT_VALUES["song"]
|
||||
audio_format: str = DEFAULT_VALUES["audio_format"]
|
||||
|
||||
def __setattr__(self, __name: str, __value: str) -> None:
|
||||
if __name in DEFAULT_VALUES:
|
||||
@ -36,9 +37,9 @@ class DefaultTarget:
|
||||
return Target(
|
||||
relative_to_music_dir=True,
|
||||
path=DOWNLOAD_PATH.format(genre=self.genre, label=self.label, artist=self.artist, album=self.album,
|
||||
song=self.song, album_type=self.album_type),
|
||||
song=self.song, album_type=self.album_type, audio_format=self.audio_format),
|
||||
file=DOWNLOAD_FILE.format(genre=self.genre, label=self.label, artist=self.artist, album=self.album,
|
||||
song=self.song, album_type=self.album_type)
|
||||
song=self.song, album_type=self.album_type, audio_format=self.audio_format)
|
||||
)
|
||||
|
||||
def song_object(self, song: Song):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, Set
|
||||
import logging
|
||||
import tempfile
|
||||
import os
|
||||
@ -94,6 +94,28 @@ proxies = {
|
||||
'https': 'socks5h://127.0.0.1:9150'
|
||||
} if TOR else {}
|
||||
|
||||
|
||||
# Only the formats with id3 metadata can be used
|
||||
# https://www.audioranger.com/audio-formats.php
|
||||
# https://web.archive.org/web/20230322234434/https://www.audioranger.com/audio-formats.php
|
||||
ALLOWED_FILE_FORMATS: Set[str] = {
|
||||
"mp3", "mp2", "mp1", # MPEG-1 ID3.2
|
||||
"wav", "wave", "rmi", # RIFF (including WAV) ID3.2
|
||||
"aiff", "aif", "aifc", # AIFF ID3.2
|
||||
"aac", "aacp", # Raw AAC ID3.2
|
||||
"tta", # True Audio ID3.2
|
||||
"ape", # Monkey's Audio ID3.1
|
||||
"mpc", "mpp", "mp+", # MusePack ID3.1
|
||||
"wv", # WavPack ID3.1
|
||||
"ofr", "ofs" # OptimFrog ID3.1
|
||||
}
|
||||
|
||||
# kB per second
|
||||
BITRATE = 125
|
||||
AUDIO_FORMAT = "mp3"
|
||||
if AUDIO_FORMAT not in ALLOWED_FILE_FORMATS:
|
||||
raise ValueError(f"The Audio Format is not in {ALLOWED_FILE_FORMATS} ({AUDIO_FORMAT}).")
|
||||
|
||||
"""
|
||||
available variables:
|
||||
- genre
|
||||
@ -104,17 +126,17 @@ available variables:
|
||||
- album_type
|
||||
"""
|
||||
DOWNLOAD_PATH = "{genre}/{artist}/{album_type}/{album}"
|
||||
DOWNLOAD_FILE = "{song}.mp3"
|
||||
DOWNLOAD_FILE = "{song}.{audio_format}"
|
||||
DEFAULT_VALUES = {
|
||||
"genre": "Various Genre",
|
||||
"label": "Various Labels",
|
||||
"artist": "Various Artists",
|
||||
"album": "Various Album",
|
||||
"song": "Various Song",
|
||||
"album_type": "Other"
|
||||
"album_type": "Other",
|
||||
"audio_format": AUDIO_FORMAT
|
||||
}
|
||||
# kB per second
|
||||
BITRATE = 100
|
||||
|
||||
|
||||
# size of the chunks that are streamed
|
||||
CHUNK_SIZE = 1024
|
||||
|
Loading…
Reference in New Issue
Block a user