Skip to content

Commit

Permalink
remove oauth2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsTheFae committed Jan 5, 2025
1 parent f465207 commit b7f2c99
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 497 deletions.
14 changes: 0 additions & 14 deletions config/example_options.ini
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,6 @@ YtdlpProxy =
# Leave blank to use default, dynamically generated UA strings.
YtdlpUserAgent =

# Experimental option to enable yt-dlp to use a YouTube account via OAuth2.
# When enabled, you must use the generated URL and code to authorize an account.
# The authorization token is then stored in the `data//oauth2.token` file.
# This option should not be used when cookies are enabled.
# Using a personal account may not be recommended.
# Set yes to enable or no to disable.
YtdlpUseOAuth2 = no

# Optional YouTube video URL used at start-up for triggering OAuth2 authorization.
# This starts the OAuth2 prompt early, rather than waiting for a song request.
# The URL set here should be an accessible YouTube video URL.
# Authorization must be completed before start-up will continue when this is set.
YtdlpOAuth2URL =

# Toggle the user block list feature, without emptying the block list.
EnableUserBlocklist = yes

Expand Down
10 changes: 0 additions & 10 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,6 @@ async def setup_hook(self) -> None:
)
self.config.spotify_enabled = False

# trigger yt tv oauth2 authorization.
if self.config.ytdlp_use_oauth2 and self.config.ytdlp_oauth2_url:
log.warning(
"Experimental Yt-dlp OAuth2 plugin is enabled. This might break at any point!"
)
# could probably do this with items from an auto-playlist but meh.
await self.downloader.extract_info(
self.config.ytdlp_oauth2_url, download=False, process=True
)

log.info("Initialized, now connecting to discord.")
# this creates an output similar to a progress indicator.
muffle_discord_console_log()
Expand Down
42 changes: 0 additions & 42 deletions musicbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
APL_FILE_HISTORY,
DATA_FILE_COOKIES,
DATA_FILE_SERVERS,
DATA_FILE_YTDLP_OAUTH2,
DEFAULT_AUDIO_CACHE_DIR,
DEFAULT_COMMAND_ALIAS_FILE,
DEFAULT_DATA_DIR,
Expand Down Expand Up @@ -937,40 +936,6 @@ def __init__(self, config_file: pathlib.Path) -> None:
"Leave blank to use default, dynamically generated UA strings."
),
)
self.ytdlp_use_oauth2: bool = self.register.init_option(
section="MusicBot",
option="YtdlpUseOAuth2",
dest="ytdlp_use_oauth2",
default=ConfigDefaults.ytdlp_use_oauth2,
getter="getboolean",
comment=_Dd(
"Experimental option to enable yt-dlp to use a YouTube account via OAuth2.\n"
"When enabled, you must use the generated URL and code to authorize an account.\n"
"The authorization token is then stored in the "
"`%(oauthfile)s` file.\n"
"This option should not be used when cookies are enabled.\n"
"Using a personal account may not be recommended.\n"
"Set yes to enable or no to disable."
),
comment_args={"oauthfile": f"{DEFAULT_DATA_DIR}/{DATA_FILE_YTDLP_OAUTH2}"},
)
self.ytdlp_oauth2_url: str = self.register.init_option(
section="MusicBot",
option="YtdlpOAuth2URL",
dest="ytdlp_oauth2_url",
getter="getstr",
default=ConfigDefaults.ytdlp_oauth2_url,
comment=_Dd(
"Optional YouTube video URL used at start-up for triggering OAuth2 authorization.\n"
"This starts the OAuth2 prompt early, rather than waiting for a song request.\n"
"The URL set here should be an accessible YouTube video URL.\n"
"Authorization must be completed before start-up will continue when this is set."
),
)
# Was: [Credentials] >> YtdlpOAuth2ClientID
self.ytdlp_oauth2_client_id: str = ConfigDefaults.ytdlp_oauth2_client_id
# Was: Credentials] >> YtdlpOAuth2ClientSecret
self.ytdlp_oauth2_client_secret: str = ConfigDefaults.ytdlp_oauth2_client_secret

self.user_blocklist_enabled: bool = self.register.init_option(
section="MusicBot",
Expand Down Expand Up @@ -1552,14 +1517,7 @@ class ConfigDefaults:
auto_unpause_on_play: bool = False
ytdlp_proxy: str = ""
ytdlp_user_agent: str = ""
ytdlp_oauth2_url: str = ""

ytdlp_oauth2_client_id: str = (
"861556708454-d6dlm3lh05idd8npek18k6be8ba3oc68.apps.googleusercontent.com"
)
ytdlp_oauth2_client_secret: str = "SboVhoG9s0rNafixCSGGKXAT"

ytdlp_use_oauth2: bool = False
pre_download_next_song: bool = True

song_blocklist: Set[str] = set()
Expand Down
23 changes: 0 additions & 23 deletions musicbot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
DATA_FILE_SERVERS: str = "server_names.txt"
DATA_FILE_CACHEMAP: str = "playlist_cachemap.json"
DATA_FILE_COOKIES: str = "cookies.txt" # No support for this, go read yt-dlp docs.
DATA_FILE_YTDLP_OAUTH2: str = "oauth2.token"
DATA_GUILD_FILE_QUEUE: str = "queue.json"
DATA_GUILD_FILE_CUR_SONG: str = "current.txt"
DATA_GUILD_FILE_OPTIONS: str = "options.json"
Expand Down Expand Up @@ -130,28 +129,6 @@
# Time to wait before starting pre-download when a new song is playing.
DEFAULT_PRE_DOWNLOAD_DELAY: float = 4.0

# Time in seconds to wait before oauth2 authorization fails.
# This provides time to authorize as well as prevent process hang at shutdown.
DEFAULT_YTDLP_OAUTH2_TTL: float = 180.0

# Default / fallback scopes used for OAuth2 ytdlp plugin.
DEFAULT_YTDLP_OAUTH2_SCOPES: str = (
"http://gdata.youtube.com https://www.googleapis.com/auth/youtube"
)
# Info Extractors to exclude from OAuth2 patching, when OAuth2 is enabled.
YTDLP_OAUTH2_EXCLUDED_IES: List[str] = [
"YoutubeBaseInfoExtractor",
"YoutubeTabBaseInfoExtractor",
]
# Yt-dlp client creators that are not compatible with OAuth2 plugin.
YTDLP_OAUTH2_UNSUPPORTED_CLIENTS: List[str] = [
"web_creator",
"android_creator",
"ios_creator",
]
# Additional Yt-dlp clients to add to the OAuth2 client list.
YTDLP_OAUTH2_CLIENTS: List[str] = ["mweb"]

# Discord and other API constants
DISCORD_MSG_CHAR_LIMIT: int = 2000

Expand Down
33 changes: 0 additions & 33 deletions musicbot/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import functools
import hashlib
import importlib
import logging
import os
import pathlib
Expand All @@ -24,7 +23,6 @@
from .constants import DEFAULT_MAX_INFO_DL_THREADS, DEFAULT_MAX_INFO_REQUEST_TIMEOUT
from .exceptions import ExtractionError, MusicbotException
from .spotify import Spotify
from .ytdlp_oauth2_plugin import enable_ytdlp_oauth2_plugin

if TYPE_CHECKING:
from multidict import CIMultiDictProxy
Expand Down Expand Up @@ -147,37 +145,6 @@ def __init__(self, bot: "MusicBot") -> None:
log.info("Yt-dlp will use your configured proxy server.")
ytdl_format_options["proxy"] = bot.config.ytdlp_proxy

if bot.config.ytdlp_use_oauth2:
# set the login info so oauth2 is prompted.
ytdl_format_options["username"] = "mb_oauth2"
ytdl_format_options["password"] = ""
# ytdl_format_options["extractor_args"] = {
# "youtubetab": {"skip": ["authcheck"]}
# }

# check if the original plugin is installed, and use it instead of ours.
# It's worth doing this because our version might fail to work,
# even if the original causes infinite loop hangs while auth is pending...
try:
oauth_spec = importlib.util.find_spec(
"yt_dlp_plugins.extractor.youtubeoauth"
)
except ModuleNotFoundError:
oauth_spec = None

if oauth_spec is not None:
log.warning(
"Original OAuth2 plugin is installed and will be used instead.\n"
"This may cause MusicBot to not close completely, or hang pending authorization!\n"
"To close MusicBot, you must manually Kill the MusicBot process!\n"
"Yt-dlp is being set to show warnings and other log messages, to show the Auth code.\n"
"Uninstall the yt-dlp-youtube-oauth2 package to use integrated OAuth2 features instead."
)
ytdl_format_options["quiet"] = False
ytdl_format_options["no_warnings"] = False
else:
enable_ytdlp_oauth2_plugin(self.bot.config)

if self.download_folder:
# print("setting template to " + os.path.join(download_folder, otmpl))
otmpl = ytdl_format_options["outtmpl"]
Expand Down
Loading

0 comments on commit b7f2c99

Please sign in to comment.