reformat
This commit is contained in:
parent
f65dd85c59
commit
41a4961d2b
@ -55,7 +55,11 @@ class Audio(discord.AudioSource):
|
|||||||
self.attempts = 0
|
self.attempts = 0
|
||||||
|
|
||||||
def _reduced_durations(self) -> dict[str, str]:
|
def _reduced_durations(self) -> dict[str, str]:
|
||||||
return {url: duration for url, duration in self._durations.items() if url == self.url}
|
return {
|
||||||
|
url: duration
|
||||||
|
for url, duration in self._durations.items()
|
||||||
|
if url == self.url
|
||||||
|
}
|
||||||
|
|
||||||
def set_source_if_necessary(self):
|
def set_source_if_necessary(self):
|
||||||
if not hasattr(self, "source"):
|
if not hasattr(self, "source"):
|
||||||
@ -73,7 +77,9 @@ class Audio(discord.AudioSource):
|
|||||||
|
|
||||||
def set_source(self):
|
def set_source(self):
|
||||||
self.schedule_duration_update()
|
self.schedule_duration_update()
|
||||||
self.source = FFmpegNormalAudio(self.url, options=self.options, before_options=self.before_options())
|
self.source = FFmpegNormalAudio(
|
||||||
|
self.url, options=self.options, before_options=self.before_options()
|
||||||
|
)
|
||||||
|
|
||||||
def set_already_read(self, already_read: int):
|
def set_already_read(self, already_read: int):
|
||||||
self.already_read = already_read
|
self.already_read = already_read
|
||||||
@ -110,14 +116,11 @@ class Audio(discord.AudioSource):
|
|||||||
args = []
|
args = []
|
||||||
args += [
|
args += [
|
||||||
"ffprobe",
|
"ffprobe",
|
||||||
"-i",
|
*("-i", url),
|
||||||
url,
|
|
||||||
"-show_entries",
|
"-show_entries",
|
||||||
"format=duration",
|
"format=duration",
|
||||||
"-v",
|
*("-v", "quiet"),
|
||||||
"quiet",
|
*("-of", "default=noprint_wrappers=1:nokey=1"),
|
||||||
"-of",
|
|
||||||
"default=noprint_wrappers=1:nokey=1",
|
|
||||||
"-sexagesimal",
|
"-sexagesimal",
|
||||||
]
|
]
|
||||||
ap = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE)
|
ap = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE)
|
||||||
@ -126,7 +129,9 @@ class Audio(discord.AudioSource):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
assert ap.stdout is not None
|
assert ap.stdout is not None
|
||||||
self._durations[url] = (await ap.stdout.read()).decode().strip().split(".")[0]
|
self._durations[url] = (
|
||||||
|
(await ap.stdout.read()).decode().strip().split(".")[0]
|
||||||
|
)
|
||||||
|
|
||||||
async def _update_duration(self):
|
async def _update_duration(self):
|
||||||
async with self._duration_lock:
|
async with self._duration_lock:
|
||||||
@ -148,9 +153,7 @@ class Audio(discord.AudioSource):
|
|||||||
def before_options(self) -> str:
|
def before_options(self) -> str:
|
||||||
before_options = ""
|
before_options = ""
|
||||||
if "http" in self.url and not self.unstable:
|
if "http" in self.url and not self.unstable:
|
||||||
before_options += (
|
before_options += " -reconnect 1 -reconnect_at_eof 0 -reconnect_streamed 1 -reconnect_delay_max 60 -copy_unknown"
|
||||||
" -reconnect 1 -reconnect_at_eof 0 -reconnect_streamed 1 -reconnect_delay_max 60 -copy_unknown"
|
|
||||||
)
|
|
||||||
if self.already_read:
|
if self.already_read:
|
||||||
before_options += f" -ss {self.source_seconds()}"
|
before_options += f" -ss {self.source_seconds()}"
|
||||||
return before_options.strip()
|
return before_options.strip()
|
||||||
@ -184,7 +187,9 @@ class Audio(discord.AudioSource):
|
|||||||
if self.attempts < 5 or random.random() > 0.1:
|
if self.attempts < 5 or random.random() > 0.1:
|
||||||
self.attempts += 1
|
self.attempts += 1
|
||||||
self.regenerating = True
|
self.regenerating = True
|
||||||
self.loop.create_task(self.regenerate("underran" if droppable else "not droppable"))
|
self.loop.create_task(
|
||||||
|
self.regenerate("underran" if droppable else "not droppable")
|
||||||
|
)
|
||||||
return FILL
|
return FILL
|
||||||
else:
|
else:
|
||||||
print(f"dropped {self.origin}")
|
print(f"dropped {self.origin}")
|
||||||
@ -224,7 +229,9 @@ class Audio(discord.AudioSource):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def respawn(cls, servicing: AServicing, guild: discord.Guild, respawn: dict) -> Audio:
|
async def respawn(
|
||||||
|
cls, servicing: AServicing, guild: discord.Guild, respawn: dict
|
||||||
|
) -> Audio:
|
||||||
member_id: int | None = respawn["rby"]
|
member_id: int | None = respawn["rby"]
|
||||||
if member_id is None:
|
if member_id is None:
|
||||||
member = None
|
member = None
|
||||||
|
Loading…
Reference in New Issue
Block a user