diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-11 17:16:33 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-11 17:16:33 +0200 |
| commit | 0eb1a48fca5668c7c5c35ef81d247b4511d8e78a (patch) | |
| tree | 1ac1ed8f62ac0d641b6527141afd6f06eb3f8ade /cogs/music | |
| parent | fixing not working skip (diff) | |
| download | senator-sperma-0eb1a48fca5668c7c5c35ef81d247b4511d8e78a.tar.gz senator-sperma-0eb1a48fca5668c7c5c35ef81d247b4511d8e78a.zip | |
changed printing to proper logging
Diffstat (limited to 'cogs/music')
| -rw-r--r-- | cogs/music/play.py | 7 | ||||
| -rw-r--r-- | cogs/music/play_compressed.py | 9 |
2 files changed, 11 insertions, 5 deletions
diff --git a/cogs/music/play.py b/cogs/music/play.py index 5d82127..d902cdc 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | import asyncio | 1 | import asyncio |
| 2 | import logging | ||
| 2 | 3 | ||
| 3 | import discord | 4 | import discord |
| 4 | import yt_dlp | 5 | import yt_dlp |
| 5 | from discord.ext import commands | 6 | from discord.ext import commands |
| 6 | from youtubesearchpython import VideosSearch | 7 | from youtubesearchpython import VideosSearch |
| 7 | 8 | ||
| 9 | logger = logging.getLogger(__name__) | ||
| 10 | |||
| 8 | # Suppress noise about console usage from yt-dlp | 11 | # Suppress noise about console usage from yt-dlp |
| 9 | yt_dlp.utils.bug_reports_message = lambda: '' | 12 | yt_dlp.utils.bug_reports_message = lambda: '' |
| 10 | 13 | ||
| @@ -45,13 +48,13 @@ class Play(commands.Cog): | |||
| 45 | 48 | ||
| 46 | def after_playing(error): | 49 | def after_playing(error): |
| 47 | if error: | 50 | if error: |
| 48 | print(f'Player error: {error}') | 51 | logger.error(f'Player error: {error}') |
| 49 | coro = vc.disconnect() | 52 | coro = vc.disconnect() |
| 50 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) | 53 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) |
| 51 | try: | 54 | try: |
| 52 | fut.result() | 55 | fut.result() |
| 53 | except Exception as e: | 56 | except Exception as e: |
| 54 | print(f'Error disconnecting: {e}') | 57 | logger.error(f'Error disconnecting: {e}', exc_info=True) |
| 55 | 58 | ||
| 56 | source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) | 59 | source = discord.FFmpegPCMAudio(url2, **ffmpeg_options) |
| 57 | vc.play(source, after=after_playing) | 60 | vc.play(source, after=after_playing) |
diff --git a/cogs/music/play_compressed.py b/cogs/music/play_compressed.py index 0d4901c..038a15e 100644 --- a/cogs/music/play_compressed.py +++ b/cogs/music/play_compressed.py | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | import asyncio | 1 | import asyncio |
| 2 | import logging | ||
| 2 | import os | 3 | import os |
| 3 | import subprocess | 4 | import subprocess |
| 4 | 5 | ||
| @@ -6,6 +7,8 @@ import discord | |||
| 6 | from discord.ext import commands | 7 | from discord.ext import commands |
| 7 | from youtubesearchpython import VideosSearch | 8 | from youtubesearchpython import VideosSearch |
| 8 | 9 | ||
| 10 | logger = logging.getLogger(__name__) | ||
| 11 | |||
| 9 | 12 | ||
| 10 | class GrajcujZkompresowane(commands.Cog): | 13 | class GrajcujZkompresowane(commands.Cog): |
| 11 | def __init__(self, bot): | 14 | def __init__(self, bot): |
| @@ -20,7 +23,7 @@ class GrajcujZkompresowane(commands.Cog): | |||
| 20 | modified.write(f"{title}\n".encode('utf-8')) | 23 | modified.write(f"{title}\n".encode('utf-8')) |
| 21 | modified.write(data) | 24 | modified.write(data) |
| 22 | except Exception as e: | 25 | except Exception as e: |
| 23 | print(f"Failed to prepend title: {e}") | 26 | logger.error(f"Failed to prepend title: {e}", exc_info=True) |
| 24 | 27 | ||
| 25 | @staticmethod | 28 | @staticmethod |
| 26 | def compress_audio(input_path): | 29 | def compress_audio(input_path): |
| @@ -84,13 +87,13 @@ class GrajcujZkompresowane(commands.Cog): | |||
| 84 | title = found_title | 87 | title = found_title |
| 85 | def after_playing(error): | 88 | def after_playing(error): |
| 86 | if error: | 89 | if error: |
| 87 | print(f'Player error: {error}') | 90 | logger.error(f'Player error: {error}') |
| 88 | coro = vc.disconnect() | 91 | coro = vc.disconnect() |
| 89 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) | 92 | fut = asyncio.run_coroutine_threadsafe(coro, self.bot.loop) |
| 90 | try: | 93 | try: |
| 91 | fut.result() | 94 | fut.result() |
| 92 | except Exception as e: | 95 | except Exception as e: |
| 93 | print(f'Error disconnecting: {e}') | 96 | logger.error(f'Error disconnecting: {e}', exc_info=True) |
| 94 | 97 | ||
| 95 | if vc.is_playing() or vc.is_paused(): | 98 | if vc.is_playing() or vc.is_paused(): |
| 96 | vc.stop() | 99 | vc.stop() |
