Skip to content

Commit 6aa14f9

Browse files
allerterallerter
and
allerter
authored
2.1.1 (#6)
* Convert TELEGRAM_CHANNEL to int if possible * Update TELEGRAM_CHANNEL possible values in README and app.json * Change Spotify invalid token error message to be clearer * Add missing await for sending invalid Spotify token error message * Improve Spotify error message for invalid token * Close DeezLoader client after it's been used * Improve the instructions for getting Spotify refresh token in README * improve CHECK_TELEGRAM log * Added missing await in update_playlist * Bump Heroku runtime Python to 3.8.10 * Bump requirements Co-authored-by: allerter <[email protected]>
1 parent e03f987 commit 6aa14f9

File tree

6 files changed

+25
-17
lines changed

6 files changed

+25
-17
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ Before continuing, install the packages in the
4747
pip install -r requirements.txt
4848

4949
Now run `spotify_refresh_token.py` in the `setup` folder get your
50-
refresh token. The script will ask for your Spotify app ID, app secret, and
51-
then the link of the webpage after you click *Agree* (the link will be
52-
someting like `https://example.com/callback?code=...`) You can run the script
53-
from the command line:
50+
refresh token. The script will ask for your Spotify app ID, app secret.
51+
After your browser opens up and you click *Agree*, you will be redirected
52+
to your redirected (the link will be
53+
something like `https://example.com/callback?code=...`). Copy the full URL and
54+
paste it in the console. Then the script will print out your refresh token.
55+
You can run the script from the command line:
5456

5557
python spotify_refresh_token.py
5658

@@ -109,7 +111,7 @@ driver installed. For example if you'll be using Postgres, you should have
109111
The string session you generated using `string_session.py`
110112

111113
- **TELEGRAM\_CHANNEL**
112-
The username of your Telegram channel
114+
The username of your Telegram channel. It can also be the channel ID or an invite link.
113115

114116
- **DEEZER\_ARL\_TOKEN**
115117
Your Deezer ARL token

app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"required": true
3838
},
3939
"TELEGRAM_CHANNEL": {
40-
"description": "The username of your Telegram channel",
40+
"description": "The username of your Telegram channel. It can also be the channel ID or an invite link.",
4141
"required": true
4242
},
4343
"DEEZER_ARL_TOKEN": {

requirements.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
tekore>=3.7.0,<4.0.0
1+
tekore>=3.7.1,<4.0.0
22
telethon>=1.21.1,<1.22.0
3-
httpx[http2]>=0.17.1,<0.18.0
3+
httpx[http2]>=0.18.1,<0.19.0
44
mutagen>=1.45.1,<1.46.0
5-
sqlalchemy>=1.4.7,<1.5.0
5+
sqlalchemy>=1.4.15,<1.5.0
66
pycryptodome>=3.10.1,<3.11.0
7-
cryptg==0.2.post2
7+
cryptg==0.2.post4
88
hachoir>=3.1.2,<3.2.0
9-
fastapi>=0.63.0,<0.64.0
9+
fastapi>=0.65.1,<0.66.0
1010
uvicorn>=0.13.4,<0.14.0

runtime.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-3.8.9
1+
python-3.8.10

spotify_telegram_sync/bot.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ async def update_playlist(
485485
"Your Deezer ARL token is expired/invalid. "
486486
"Replaced it with a new one."
487487
)
488-
telegram.send_message("me", msg)
488+
await telegram.send_message("me", msg)
489489
raise e
490490
except Exception as e:
491491
logger.error(
@@ -504,6 +504,7 @@ async def update_playlist(
504504
else:
505505
msg_id = None
506506
upload_to_db_tracks.append((track[0], msg_id))
507+
await deezer.close()
507508

508509
# add new tracks to database
509510
await database.add_tracks(upload_to_db_tracks)
@@ -587,11 +588,12 @@ async def prepare_clients(
587588
except tk.BadRequest as e:
588589
if "invalid_grant" in str(e):
589590
msg = (
590-
"Your Spotify refresh token is expired. "
591-
f"Replace it with a new one. Original error message: '{str(e)}'"
591+
"Your Spotify refresh token is either expired or invalid. "
592+
f"Original error message: '{str(e)}'"
592593
)
593-
telegram.send_message("me", msg)
594+
await telegram.send_message("me", msg)
594595
sys.exit(msg)
596+
raise e
595597
spotify = tk.Spotify(token, asynchronous=True)
596598
clients["spotify"] = spotify
597599
logger.debug("Spotify is ready.")
@@ -672,7 +674,7 @@ async def exception_handler(loop: asyncio.AbstractEventLoop, context: dict) -> N
672674
logger.info("Update playlist: ✔️ | Update bio: ❌")
673675
tasks.append(loop.create_task(update_playlist_loop()))
674676
if constants.CHECK_TELEGRAM:
675-
logger.info("Check Telegram: ✔️")
677+
logger.info("Check Telegram for added/deleted tracks: ✔️")
676678
tasks.append(loop.create_task(check_deleted()))
677679
client.on(events.NewMessage(chats=(telegram_channel)))(new_message_handler)
678680
else:

spotify_telegram_sync/constants.py

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
SPOTIFY_REFRESH_TOKEN = os.environ["SPOTIFY_REFRESH_TOKEN"]
77
SPOTIFY_PLAYLIST_ID = os.environ["SPOTIFY_PLAYLIST_ID"]
88
TELEGRAM_CHANNEL = os.environ["TELEGRAM_CHANNEL"]
9+
try:
10+
TELEGRAM_CHANNEL = int(TELEGRAM_CHANNEL)
11+
except ValueError:
12+
pass
913
DATABASE_URL = os.environ["DATABASE_URL"]
1014
TELETHON_API_ID = os.environ["TELETHON_API_ID"]
1115
TELETHON_API_HASH = os.environ["TELETHON_API_HASH"]

0 commit comments

Comments
 (0)