From 6680cc2a6df6bfcdb2d2989d7f1f1ccd48e0c5e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Apr 2025 23:47:25 +0300 Subject: [PATCH] Add proxy support --- app/__init__.py | 4 ++-- app/config.py | 2 +- app/youtube_api.py | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 1eda48d..76f904a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -77,7 +77,7 @@ async def start(e: events.NewMessage.Event): Button.url('Link Yandex music', get_ymusic_link(enc_user_id)), ] await e.respond("""Hi! I can help you share music you listen on Spotify or Yandex music. -To use just type @now_listening_bot and select track. +To use just type @listensharebot and select track. Press button below to authorize your account first @@ -103,7 +103,7 @@ async def change_default(e: events.NewMessage.Event): async def set_default(e: events.CallbackQuery.Event): async with get_session_context() as session: await session.execute( - update(User).where(User.id == e.sender_id).values(default=str(e.data).split('_')[1]) + update(User).where(User.id == e.sender_id).values(default=str(e.data).split('_')[1][:-1]) ) await session.commit() await e.respond('Default service updated') diff --git a/app/config.py b/app/config.py index 58a046f..46edc8d 100644 --- a/app/config.py +++ b/app/config.py @@ -30,7 +30,7 @@ class Config(BaseSettings): yt: GoogleApiCreds ymusic: OauthCreds - proxy: str = '' + proxy: str | None jwt_secret: str diff --git a/app/youtube_api.py b/app/youtube_api.py index 41cdbf6..2c5592e 100644 --- a/app/youtube_api.py +++ b/app/youtube_api.py @@ -8,11 +8,15 @@ from yt_dlp import YoutubeDL from app.config import config -ytmusic = YTMusic('oauth.json', oauth_credentials=OAuthCredentials(client_id=config.yt.client_id, client_secret=config.yt.client_secret)) +ytmusic = YTMusic('oauth.json', + oauth_credentials=OAuthCredentials(client_id=config.yt.client_id, client_secret=config.yt.client_secret)) +if config.proxy: + ytmusic.proxies = {'http': config.proxy, 'https': config.proxy} def name_to_youtube(name: str): results = ytmusic.search(name, 'songs', limit=5) + print(results[0]) return results[0]['videoId']