diff --git a/main.py b/main.py index 4e3e88b..c615a93 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,6 @@ import yt_dlp as youtube_dl from config import DISCORD_BOT_TOKEN, DISCORD_CHANNEL_ID, YOUTUBE_CHANNEL_IDS import os import asyncio -import logging - -logging.basicConfig( - filename='yt_dlp.log', - format='%(asctime)s %(levelname)s:%(message)s', - level=logging.DEBUG -) intents = discord.Intents.default() intents.messages = True @@ -48,7 +41,7 @@ async def check_new_videos(): max_videos_to_download = 9 for channel_id in YOUTUBE_CHANNEL_IDS: - logging.info(f"Checking new videos for channel: {channel_id}") + print(f"Checking new videos for channel: {channel_id}") try: videos = get_all_videos(channel_id) videos.sort(key=lambda x: x[2]) @@ -59,33 +52,25 @@ async def check_new_videos(): channel_download_dir = os.path.join(download_dir, channel_id) os.makedirs(channel_download_dir, exist_ok=True) ydl_opts = { - 'format': 'best', # Simplified format + 'format': 'bestvideo+bestaudio/best', 'outtmpl': f'{channel_download_dir}/%(title)s [%(id)s].%(ext)s', - 'cookiefile': os.path.join(os.getcwd(), 'cookies.txt'), - 'quiet': True, - 'no_warnings': True, - 'ignoreerrors': True, + 'cookiefile': 'cookies.txt', } - try: - with youtube_dl.YoutubeDL(ydl_opts) as ydl: - ydl.download([video_url]) - add_downloaded_video(video_id) - channel = bot.get_channel(int(DISCORD_CHANNEL_ID)) - await channel.send(f"@everyone New video uploaded: {video_url}") - logging.info(f"Downloaded and notified for video {video_id} from channel: {channel_id}") - except youtube_dl.utils.DownloadError as e: - logging.error(f"DownloadError for video {video_id}: {e}") - except Exception as e: - logging.error(f"Unexpected error for video {video_id}: {e}") + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download([video_url]) + add_downloaded_video(video_id) + channel = bot.get_channel(int(DISCORD_CHANNEL_ID)) + await channel.send(f"@everyone New tard video dropped and has been archived: {video_url}") + print(f"Downloaded and notified for video {video_id} from channel: {channel_id}") else: - logging.warning(f"Video URL or ID missing for video ID {video_id} from channel: {channel_id}") + print(f"Video URL or ID missing for video ID {video_id} from channel: {channel_id}") except Exception as e: - logging.error(f"Error processing channel {channel_id}: {e}") + print(f"Error processing channel {channel_id}: {e}") await asyncio.sleep(5) @bot.event async def on_ready(): - logging.info(f'{bot.user.name} has connected to Discord!') + print(f'{bot.user.name} has connected to Discord!') check_new_videos.start() -bot.run(DISCORD_BOT_TOKEN) +bot.run(DISCORD_BOT_TOKEN) \ No newline at end of file