draft: post process song
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
cc14253239
commit
ac6c513d56
@ -10,12 +10,12 @@ from ..objects import Target
|
||||
LOGGER = logging_settings["codex_logger"]
|
||||
|
||||
|
||||
def correct_codec(target: Target, bitrate_kb: int = main_settings["bitrate"], audio_format: str = main_settings["audio_format"], interval_list: List[Tuple[float, float]] = None):
|
||||
def correct_codec(target: Target, bitrate_kb: int = main_settings["bitrate"], audio_format: str = main_settings["audio_format"], skip_intervals: List[Tuple[float, float]] = None):
|
||||
if not target.exists:
|
||||
LOGGER.warning(f"Target doesn't exist: {target.file_path}")
|
||||
return
|
||||
|
||||
interval_list = interval_list or []
|
||||
skip_intervals = skip_intervals or []
|
||||
|
||||
bitrate_b = int(bitrate_kb / 1024)
|
||||
|
||||
@ -29,7 +29,7 @@ def correct_codec(target: Target, bitrate_kb: int = main_settings["bitrate"], au
|
||||
|
||||
start = 0
|
||||
next_start = 0
|
||||
for end, next_start in interval_list:
|
||||
for end, next_start in skip_intervals:
|
||||
aselect_list.append(f"between(t,{start},{end})")
|
||||
start = next_start
|
||||
aselect_list.append(f"gte(t,{next_start})")
|
||||
|
@ -279,11 +279,25 @@ class Pages:
|
||||
|
||||
# if everything went right, the file should exist now
|
||||
if not tmp.exists:
|
||||
r.error_message = f"The song {song.option_string} couldn't be downloaded."
|
||||
if used_source is None:
|
||||
r.error_message = f"No source found for {song.option_string}."
|
||||
else:
|
||||
r.error_message = f"Something went wrong downloading {song.option_string}."
|
||||
return r
|
||||
|
||||
# post process the audio
|
||||
found_on_disk = used_source is None
|
||||
if not found_on_disk or self.download_options.process_audio_if_found:
|
||||
correct_codec(target=tmp, skip_intervals=skip_intervals)
|
||||
r.sponsor_segments = len(skip_intervals)
|
||||
|
||||
if used_source is not None:
|
||||
used_source.page.post_process_hook(song=song, temp_target=tmp)
|
||||
|
||||
if not found_on_disc or self.download_options.process_metadata_if_found:
|
||||
write_metadata_to_target(metadata=song.metadata, target=tmp, song=song)
|
||||
|
||||
tmp.delete()
|
||||
return r
|
||||
|
||||
def fetch_url(self, url: str, stop_at_level: int = 2) -> Tuple[Type[Page], DataObject]:
|
||||
|
@ -262,15 +262,15 @@ class Page:
|
||||
r.merge(self._post_process_targets(
|
||||
song=song,
|
||||
temp_target=temp_target,
|
||||
interval_list=skip_intervals,
|
||||
skip_intervals=skip_intervals,
|
||||
found_on_disc=found_on_disc,
|
||||
))
|
||||
|
||||
return r
|
||||
|
||||
def _post_process_targets(self, song: Song, temp_target: Target, interval_list: List, found_on_disc: bool) -> DownloadResult:
|
||||
def _post_process_targets(self, song: Song, temp_target: Target, skip_intervals: List, found_on_disc: bool) -> DownloadResult:
|
||||
if not found_on_disc or self.download_options.process_audio_if_found:
|
||||
correct_codec(temp_target, interval_list=interval_list)
|
||||
correct_codec(temp_target, skip_intervals=skip_intervals)
|
||||
|
||||
self.post_process_hook(song, temp_target)
|
||||
|
||||
@ -286,7 +286,7 @@ class Page:
|
||||
r.add_target(target)
|
||||
|
||||
temp_target.delete()
|
||||
r.sponsor_segments += len(interval_list)
|
||||
r.sponsor_segments += len(skip_intervals)
|
||||
|
||||
return r
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user