added ffmpeg progressbar

This commit is contained in:
Hellow2
2023-06-15 09:58:48 +02:00
parent 5c31d6f7a8
commit 805017fea5
3 changed files with 49 additions and 64 deletions

View File

@@ -1,7 +1,7 @@
import logging
import random
from copy import copy
from typing import Optional, Union, Type, Dict, Set, List
from typing import Optional, Union, Type, Dict, Set, List, Tuple
import threading
from queue import Queue
@@ -345,15 +345,16 @@ class Page:
file=str(random.randint(0, 999999))
)
r = self.download_song_to_target(source=sources[0], target=temp_target, desc=song.title)
source = sources[0]
r = self.download_song_to_target(source=source, target=temp_target, desc=song.title)
if not r.is_fatal_error:
r.merge(self._post_process_targets(song, temp_target))
r.merge(self._post_process_targets(song, temp_target, source))
return r
def _post_process_targets(self, song: Song, temp_target: Target) -> DownloadResult:
correct_codec(temp_target)
def _post_process_targets(self, song: Song, temp_target: Target, source: Source) -> DownloadResult:
correct_codec(temp_target, interval_list=self.get_skip_intervals(song, source))
self.post_process_hook(song, temp_target)
@@ -371,6 +372,9 @@ class Page:
return r
def get_skip_intervals(self, song: Song, source: Source) -> List[Tuple[float, float]]:
return []
def post_process_hook(self, song: Song, temp_target: Target, **kwargs):
pass

View File

@@ -5,6 +5,8 @@ from enum import Enum
import sponsorblock
from sponsorblock.errors import HTTPException, NotFoundException
from music_kraken.objects import Song, Source
from ..objects import Source, DatabaseObject, Song, Target
from .abstract import Page
from ..objects import (
@@ -18,7 +20,6 @@ from ..objects import (
FormattedText,
ID3Timestamp
)
from ..audio.codec import remove_intervals
from ..connection import Connection
from ..utils.support_classes import DownloadResult
from ..utils.shared import YOUTUBE_LOGGER, INVIDIOUS_INSTANCE, BITRATE, ENABLE_SPONSOR_BLOCK
@@ -384,23 +385,15 @@ class YouTube(Page):
return DownloadResult(total=1)
return DownloadResult(error_message=f"Streaming to the file went wrong: {endpoint}, {str(target.file_path)}")
def post_process_hook(self, song: Song, temp_target: Target, **kwargs):
def get_skip_intervals(self, song: Song, source: Source) -> List[Tuple[float, float]]:
if not ENABLE_SPONSOR_BLOCK:
return
return []
# find the YouTube id
source_list = song.source_collection.get_sources_from_page(self.SOURCE_TYPE)
if len(source_list) <= 0:
self.LOGGER.warning(f"Couldn't find a youtube source in the post_processing_hook for {song.option_string}")
return
source = source_list[0]
parsed = YouTubeUrl(source.url)
if parsed.url_type != YouTubeUrlType.VIDEO:
self.LOGGER.warning(f"{source.url} is no video url.")
return
return []
# call the sponsorblock api, and remove the segments from the audio
segments = []
try:
segments = self.sponsorblock_client.get_skip_segments(parsed.id)
@@ -408,6 +401,5 @@ class YouTube(Page):
self.LOGGER.debug(f"No sponsor found for the video {parsed.id}.")
except HTTPException as e:
self.LOGGER.warning(f"{e}")
if len(segments) <= 0:
remove_intervals(temp_target, [(segment.start, segment.end) for segment in segments])
return [(segment.start, segment.end) for segment in segments]