From 5195a5f741b56cf648b0512cc5bb90d1edbbfe97 Mon Sep 17 00:00:00 2001 From: Bartosz <46005237+valdife@users.noreply.github.com> Date: Mon, 12 Aug 2024 22:37:48 +0200 Subject: [PATCH] Fix bot (#2) * Remove any cookies from browser * implement oauth2 integration * Update readme --- README.md | 12 +++++++----- youtubebot.py | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5b3613f..d12ac24 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,12 @@ A word of warning before we start though: you'll need somewhere to host the bot. 2. Download the code. You can do this by downloading the zip and unzipping it, or with a `git clone` command, or however you prefer to get GitHub content. 3. Make sure you have Python 3.8 or later installed. 4. Open up a console wherever you downloaded the code to (don't forget to unzip it if it's zipped), and run `pip install -r requirements.txt` -5. Create a copy of the ".env_example" file named ".env" -6. Head back to the "Bot" page. Click "Reset Token", then click "Copy". This will copy your bot's unique token so that the code can identify itself as the bot you've just created. -7. Edit ".env" and replace "your-token-goes-here" with the token you just copied. -8. Run `nohup ./youtubebot.py &` on Linux/Unix or `python youtube.py` on Windows (note that on Windows, if you close the console your bot will stop). For Linux/Unix: if you get an error along the lines of "permission denied" or "not executable", run `chmod +x youtubebot.py` to make it executable and try again. -9. The bot is now running. To stop it, run `pkill -f youtubebot.py` on Linux/Unix or press `ctrl+c` while clicked into your console on Windows. +5. Additionally, install YouTube OAuth2 for yt-dlp: `python3 -m pip install -U https://github.com/coletdjnz/yt-dlp-youtube-oauth2/archive/refs/heads/master.zip` +6. Create a copy of the ".env_example" file named ".env" +7. Head back to the "Bot" page. Click "Reset Token", then click "Copy". This will copy your bot's unique token so that the code can identify itself as the bot you've just created. +8. Edit ".env" and replace "your-token-goes-here" with the token you just copied. +9. On first run, use `python youtube.py` and follow instructions: https://github.com/coletdjnz/yt-dlp-youtube-oauth2?tab=readme-ov-file#logging-in +10. Run `nohup ./youtubebot.py &` on Linux/Unix or `python youtube.py` on Windows (note that on Windows, if you close the console your bot will stop). For Linux/Unix: if you get an error along the lines of "permission denied" or "not executable", run `chmod +x youtubebot.py` to make it executable and try again. +11. The bot is now running. To stop it, run `pkill -f youtubebot.py` on Linux/Unix or press `ctrl+c` while clicked into your console on Windows. Congrats! You should now be able to use the bot by joining a VC and using the commands above. If not, let me know and I'll try to help as best I can. diff --git a/youtubebot.py b/youtubebot.py index 1b5c540..2729ddc 100755 --- a/youtubebot.py +++ b/youtubebot.py @@ -103,6 +103,9 @@ async def play(ctx: commands.Context, *args): 'outtmpl': '%(id)s.%(ext)s', 'noplaylist': True, 'allow_playlist_files': False, + 'cookiesfrombrowser': None, + 'username': 'oauth2', + 'password': '', # 'progress_hooks': [lambda info, ctx=ctx: video_progress_hook(ctx, info)], # 'match_filter': lambda info, incomplete, will_need_search=will_need_search, ctx=ctx: start_hook(ctx, info, incomplete, will_need_search), 'paths': {'home': f'./dl/{server_id}'}}) as ydl: