Skip to content

Commit 7275dfd

Browse files
committed
refactor(stream): Use aiohttp instead of curl
**Summary** Well, YouTube is so strict sometimes, so it blocks buffer from actually being sent to the ffmpeg process in time, and we can't control that, however, a 15 seconds timeout was set, youtube usually takes more than 5 seconds to send buffers in time. **Why aiohttp?** I had to get rid of curl because handling it is harder, aiohttp is way easier and more reliable for requests like YouTube and MyInstants. - Solves #119 - Now local files don't need a curl process to be made, it can be done inside ffmpeg itself - Set the duration of the youtube video before playing it instead of calculating it during the stream.
1 parent c93ff61 commit 7275dfd

3 files changed

Lines changed: 150 additions & 129 deletions

File tree

src/torchlight/AudioClip.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def __init__(
3333
def __del__(self) -> None:
3434
self.logger.debug("~AudioClip()")
3535

36+
def SetDuration(self, duration: float) -> None:
37+
self.audio_player.SetDuration(duration)
38+
3639
def Play(
3740
self,
3841
seconds: int | None = None,

src/torchlight/Commands.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,9 @@ async def _func(self, message: list[str], player: Player) -> int:
966966

967967
self.torchlight.last_url = url
968968

969+
# Set the duration of the audio clip because youtube already provides it in the metadata
970+
# Helps fixing youtube not sending buffer in time.
971+
audio_clip.SetDuration(float(info["duration"]))
969972
return audio_clip.Play(real_time)
970973

971974

0 commit comments

Comments
 (0)